ATLAS Offline Software
uploadValsFromFile.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import uploadTools
4 
5 basepath="/afs/cern.ch/atlas/groups/Generators/CrossSectionInfo/ScriptsCentralPage/"
6 
7 def main():
8 
9  # parse options from command line
10  from optparse import OptionParser
11  parser = OptionParser(usage = "usage: %prog arguments", version="%prog")
12  parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Set verbose mode (default: %default)")
13  parser.add_option("-y", "--alwaysyes", action="store_true", dest="alwaysyes", help="Always answer yes to checks (default: %default)")
14  parser.add_option("-i", "--infile", action="store", dest="infile", help="Input file (default: %default)")
15  parser.add_option("-x", "--xsreffile", action="store", dest="xsreffile", help="Cross section reference file (default: %default)")
16  parser.add_option("-t", "--istest", action="store", dest="istest", help="Is test (no actual upload to AMI) (default: %default)")
17  parser.add_option("-d", "--delim", action="store", dest="delim", help="Delimiter for input file (default: %default)")
18  parser.add_option("-e", "--explanation",action="store", dest="explanation",help="Comment for explanation field (default: %default)")
19 
20  parser.set_defaults(verbose=False,alwaysyes=False,infile=None,xsreffile=basepath+"InputInformation/CrossSectionReference",istest="TRUE",delim=';',explanation=None)
21 
22  (opts, args) = parser.parse_args()
23 
24  if not opts.explanation:
25  print "ERROR: No explanation found - Should be JIRA ticket or similar"
26  return
27  elif 'CENTRPAGE' not in opts.explanation:
28  print "WARNING: Explanation found, but does not include CENTRPAGE - this should usually be a JIRA ticket"
29 
30  if opts.istest=="FALSE":
31  opts.istest=False
32 
33  UT=uploadTools.UT(istest=opts.istest,verbose=opts.verbose,alwaysyes=opts.alwaysyes,xsRefFile=opts.xsreffile if hasattr(opts,"xsreffile") else None,delim=opts.delim if hasattr(opts,"delim") else None)
34 
35  cols=UT.colors
36 
37  if not opts.istest:
38  print cols.FAIL+"INFO: THIS IS NOT A TEST - UPLOADING FOR REALS!"+cols.ENDC
39  else:
40  print cols.OKGREEN+"INFO: THIS IS A TEST - Nothing will be uploaded!"+cols.ENDC
41 
42 
43 
44 
45  currentfile=UT.getCurrentVals(UT.getDSListFromFile(opts.infile),UT.getFieldsInFile(opts.infile))
46  UT.currentVals=UT.getDetailsFromFile(currentfile)
47  #print UT.currentVals
48 
49  UT.newVals=uploadVals=UT.getDetailsFromFile(opts.infile)
50  #print uploadVals
51 
52  for ds in uploadVals:
53  if ds in UT.currentVals:
54  print cols.OKGREEN+"INFO: Working on datset %s"%(ds)+cols.ENDC
55  for param in uploadVals[ds]:
56  if param in UT.currentVals[ds]:
57  if len(uploadVals[ds][param].strip()) or uploadVals[ds][param].strip()=="#UNKNOWN#":
58  newval=uploadVals[ds][param]
59  currentval=UT.currentVals[ds][param]
60  if param in ["genFiltEff","crossSection","kFactor"] and "unknown" not in newval.lower() and "unknown" not in currentval.lower():
61  newval=float(uploadVals[ds][param])
62  currentval=float(UT.currentVals[ds][param])
63  if newval!=currentval:
64  print cols.WARNING+"INFO: Upload %s = %s (current val = %s)"%(param,uploadVals[ds][param],UT.currentVals[ds][param])+cols.ENDC
65  UT.updateValue(ds,param,uploadVals[ds][param],opts.explanation,uploadVals[ds]["crossSectionRef"])
66  else:
67  print "INFO: Inputted %s value is identical to current DB value (%s) - ignoring"%(param,UT.currentVals[ds][param])
68  else:
69  print "INFO: %s value empty or unknown - ignoring"%(param)
70  else:
71  print "WARNING: Parameter %s not found in current AMI vals dictionary for %s"%(param,ds)
72  else:
73  print "WARNING: Parameter dataset %s not found in current AMI val dictionary"%(ds)
74 
75  #UT.updateXS("test","mc15","1234","Just a test")
76 
77 if __name__ == '__main__':
78  main()
79 
uploadValsFromFile.main
def main()
Definition: uploadValsFromFile.py:7
readCCLHist.float
float
Definition: readCCLHist.py:83
uploadTools.UT
Definition: uploadTools.py:10