Classes | Functions
extractor_prod Namespace Reference

Classes

class  expMetaData
 
class  MetaData
 
class  MetaDataKey
 

Functions

def main ()
 

Function Documentation

def extractor_prod.main ( void  )

Definition at line 348 of file extractor_prod.py.

348 def main():
349 
350  argparser = argparse.ArgumentParser('Parse arguments')
351  argparser.add_argument('--infile',help='path to input file',required=True,type=str)
352  argparser.add_argument('--declare',help='validate and declare the metadata for the file specified in --infile to SAM',action='store_true')
353  argparser.add_argument('--appname',help='application name for SAM metadata',type=str)
354  argparser.add_argument('--appversion',help='application version for SAM metadata',type=str)
355  argparser.add_argument('--appfamily',help='application family for SAM metadata',type=str)
356  argparser.add_argument('--campaign',help='Value for DUNE.campaign for SAM metadata',type=str)
357  argparser.add_argument('--data_stream',help='Value for data_stream for SAM metadata',type=str)
358  argparser.add_argument('--requestid',help='Value for DUNE.requestid for SAM metadata',type=str)
359  argparser.add_argument('--set_processed',help='Set for parent file as processed in SAM metadata',action="store_true")
360  argparser.add_argument('--strip_parents',help='Do not include the file\'s parents in SAM metadata for declaration',action="store_true")
361  argparser.add_argument('--no_crc',help='Leave the crc out of the generated json',action="store_true")
362  argparser.add_argument('--skip_dumper',help='Skip running sam_metadata_dumper on the input file',action="store_true")
363  argparser.add_argument('--input_json',help='Input json file containing metadata to be added to output (can contain ANY valid SAM metadata parameters)',type=str)
364 
365  global args
366  args = argparser.parse_args()
367 
368  ih = ifdh.ifdh()
369 
370  try:
371 # expSpecificMetadata = expMetaData(os.environ['SAM_EXPERIMENT'], str(sys.argv[1]))
372  expSpecificMetadata = expMetaData(os.environ['SAM_EXPERIMENT'], args.infile)
373  mddict = expSpecificMetadata.getmetadata()
374  # If --input_json is supplied, open that dict now and add it to the output json
375  if args.input_json != None:
376  if os.path.exists(args.input_json):
377  try:
378  injson=open(args.input_json)
379  arbjson = json.load(injson)
380  for key in list(arbjson.keys()):
381  mddict[key] = arbjson[key]
382  except:
383  print('Error loading input json file.')
384  raise
385  else:
386  print('Error, specified input file does not exist.')
387  sys.exit(1)
388 
389  if 'application' in mddict and 'name' not in list(mddict['application'].keys()) and args.appname != None:
390  mddict['application']['name'] = args.appname
391  if 'application' in mddict and 'version' not in list(mddict['application'].keys()) and args.appversion != None:
392  mddict['application']['version'] = args.appversion
393  if 'application' in mddict and 'family' not in list(mddict['application'].keys()) and args.appfamily != None:
394  mddict['application']['family'] = args.appfamily
395  if args.appfamily != None and args.appname != None and args.appversion != None:
396  mddict['application'] = {}
397  mddict['application']['family'] = args.appfamily
398  mddict['application']['name'] = args.appname
399  mddict['application']['version'] = args.appversion
400  if 'DUNE.campaign' not in list(mddict.keys()) and args.campaign != None:
401  mddict['DUNE.campaign'] = args.campaign
402  if args.data_stream != None:
403  mddict['data_stream'] = args.data_stream
404  if args.requestid != None:
405  mddict['DUNE.requestid'] = args.requestid
406 
407  except TypeError:
408  print('You have not implemented a defineMetaData function by providing an experiment.')
409  print('No metadata keys will be saved')
410  raise
411 # mdtext = json.dumps(expSpecificMetadata.getmetadata(), indent=2, sort_keys=True)
412  mdtext = json.dumps(mddict, indent=2, sort_keys=True)
413 
414  if args.declare:
415  ih.declareFile(mdtext)
416 
417  if args.set_processed:
418  swc = samweb_client.SAMWebClient('dune')
419  moddict = {"DUNE.production_status" : "processed" }
420  for parent in moddict['parents']:
421  fname = moddict['parents'][parent]['file_name']
422  try:
423  swc.modifyFileMetadata(fname, moddict)
424  except:
425  print('Error modidying metadata for %s' % fname)
426  raise
427 
428  print(mdtext)
429  sys.exit(0)
430 
431 
432 
int open(const char *, int)
Opens a file descriptor.