From 5b78ecb6b65606fec5a21371d7df803460fa81e2 Mon Sep 17 00:00:00 2001 From: Christophe Delaere Date: Thu, 1 Aug 2013 16:22:58 +0200 Subject: [PATCH] Suggestions received during the tutorial session * For samples and results, the path is resolved/expanded before we store it in the database. It makes more sense than relative paths. * For results, the path may also be a file, not only a directory * When entering a sample with no explicit #processed events, the code tries to guess it from the parent sample and/or dataset. --- add_result.py | 6 +++--- add_sample.py | 18 +++++++++++++++++- search_SAMADhi.py | 4 +++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/add_result.py b/add_result.py index 5ad0b45..b9749e6 100755 --- a/add_result.py +++ b/add_result.py @@ -37,9 +37,9 @@ def get_opt(self): # check that the path exists if len(args) < 1: self.parser.error("path is mandatory") - opts.path = args[0] - if not os.path.exists(opts.path) or not os.path.isdir(opts.path): - self.parser.error("%s is not an existing directory"%opts.path) + opts.path = os.path.abspath(os.path.expandvars(os.path.expanduser(args[0]))) + if not os.path.exists(opts.path) or not ( os.path.isdir(opts.path) or os.path.isfile(opts.path)) : + self.parser.error("%s is not an existing file or directory"%opts.path) # set author if opts.author is None: opts.author = getpwuid(os.stat(opts.path).st_uid).pw_name diff --git a/add_sample.py b/add_sample.py index 9fecc86..7edb3ee 100755 --- a/add_sample.py +++ b/add_sample.py @@ -61,7 +61,7 @@ def get_opt(self): if len(args) < 2: self.parser.error("type and path are mandatory") opts.sampletype = args[0] - opts.path = args[1] + opts.path = os.path.abspath(os.path.expandvars(os.path.expanduser(args[1]))) # check path if not os.path.exists(opts.path) or not os.path.isdir(opts.path): self.parser.error("%s is not an existing directory"%opts.path) @@ -107,6 +107,22 @@ def main(): prompt_dataset(sample,dbstore) if sample.source_sample_id is None: prompt_sample(sample,dbstore) + # check that source sample and dataset exist + if sample.source_dataset_id is not None: + checkExisting = dbstore.find(Dataset,Dataset.dataset_id==sample.source_dataset_id) + if checkExisting.is_empty(): + raise IndexError("No dataset with such index: %d"%sample.source_dataset_id) + if sample.source_sample_id is not None: + checkExisting = dbstore.find(Sample,Sample.sample_id==sample.source_sample_id) + if checkExisting.is_empty(): + raise IndexError("No sample with such index: %d"%sample.source_sample_id) + # if opts.nevents is not set, take #events from source sample (if set) or from source dataset (if set) in that order + if sample.nevents_processed is None and sample.source_sample_id is not None: + sample.nevents_processed = dbstore.find(Sample,Sample.sample_id==sample.source_sample_id).one().nevents_processed + if sample.nevents_processed is None and sample.source_dataset_id is not None: + sample.nevents_processed = dbstore.find(Dataset,Dataset.dataset_id==sample.source_dataset_id).one().nevents + if sample.nevents_processed is None: + print "Warning: Number of processed events not given, and no way to guess it." # check that there is no existing entry checkExisting = dbstore.find(Sample,Sample.name==sample.name) if checkExisting.is_empty(): diff --git a/search_SAMADhi.py b/search_SAMADhi.py index 2ab1557..a154f46 100755 --- a/search_SAMADhi.py +++ b/search_SAMADhi.py @@ -37,7 +37,9 @@ def get_opt(self): if args[0] not in ["dataset","sample","result","madweight"]: self.parser.error("type must be one of dataset, sample, result") cnt = 0 - if opts.path is not None: cnt +=1 + if opts.path is not None: + cnt +=1 + opts.path = os.path.abspath(os.path.expandvars(os.path.expanduser(opts.path))) if opts.name is not None: cnt +=1 if opts.objid is not None: cnt +=1 if cnt>1: