diff --git a/strax/storage/rucio.py b/strax/storage/rucio.py index 6df0a4f40..44f30b05e 100644 --- a/strax/storage/rucio.py +++ b/strax/storage/rucio.py @@ -12,17 +12,23 @@ 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): @@ -30,11 +36,11 @@ def _saver(self, dirname, metadata): "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) diff --git a/strax/utils.py b/strax/utils.py index f906c961d..7e525f684 100644 --- a/strax/utils.py +++ b/strax/utils.py @@ -205,7 +205,6 @@ def profile_threaded(filename): monitoring_gil = True except (RuntimeError, ImportError): monitoring_gil = False - pass yappi.start() yield