Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rootdir #1

Merged
merged 5 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions strax/storage/rucio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,35 @@
class rucio(strax.StorageBackend):
"""Get data from a rucio directory
"""
def __init__(self, root_dir, *args, **kwargs):
super().__init__(*args, **kwargs)
self.root_dir = root_dir

def get_metadata(self, dirname, **kwargs):
dirname = str(dirname)
def get_metadata(self, dirname:str, **kwargs):
prefix = dirname_to_prefix(dirname)
metadata_json = f'{prefix}-metadata.json'
fn = rucio_path(metadata_json, dirname)
fn = rucio_path(self.root_dir, metadata_json, dirname)

if not osp.exists(fn):
raise strax.DataCorrupted(f"Data in {dirname} has no metadata")

with open(fn, mode='r') as f:
return json.loads(f.read())

def _read_chunk(self, dirname, chunk_info, dtype, compressor):
fn = rucio_path(chunk_info['filename'], dirname)
fn = rucio_path(self.root_dir, chunk_info['filename'], dirname)
return strax.load_file(fn, dtype=dtype, compressor=compressor)

def _saver(self, dirname, metadata):
raise NotImplementedError(
"Cannot save directly into rucio, upload with admix instead")


def rucio_path(filename, dirname):
root_path ='/dali/lgrandi/rucio'
def rucio_path(root_dir, filename, dirname):
"""Convert target to path according to rucio convention"""
scope = "xnt_"+dirname.split('-')[0]
rucio_did = "{0}:{1}".format(scope,filename)
rucio_did = "{0}:{1}".format(scope, filename)
rucio_md5 = hashlib.md5(rucio_did.encode('utf-8')).hexdigest()
t1 = rucio_md5[0:2]
t2 = rucio_md5[2:4]
return osp.join(root_path,scope,t1,t2,filename)
return osp.join(root_dir, scope, t1, t2, filename)
1 change: 0 additions & 1 deletion strax/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ def profile_threaded(filename):
monitoring_gil = True
except (RuntimeError, ImportError):
monitoring_gil = False
pass

yappi.start()
yield
Expand Down