Skip to content

Commit

Permalink
Suggestions received during the tutorial session
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
delaere committed Aug 1, 2013
1 parent b3a8206 commit 5b78ecb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions add_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion add_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down
4 changes: 3 additions & 1 deletion search_SAMADhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5b78ecb

Please sign in to comment.