13 from pluginCondDBPyInterface
import *
14 from CondCore.Utilities
import iovInspector
as inspect
27 sys.setdlopenflags(DLFCN.RTLD_GLOBAL+DLFCN.RTLD_LAZY)
31 rdbms = RDBMS(
"/afs/cern.ch/cms/DB/conddb")
33 db = rdbms.getDB(options.dbName)
37 print "\nOverview of all tags in "+options.dbName+
" :\n"
55 iov = inspect.Iov(db,tag)
60 print "######## summries ########"
61 for x
in iov.summaries():
62 print x[0], x[1], x[2] ,x[3]
67 print "###(start_current,stop_current,avg_current,max_current,min_current,run_interval_micros) vs runnumber###"
71 print "######## trends ########"
72 for x
in iov.trendinrange(what,options.startRun-1,options.endRun+1):
73 if v>0
or x[0]==67647L
or x[0]==66893L
or x[0]==67264L:
74 print x[0],x[1] ,x[2], x[2][4], x[2][3]
76 if x[2][4] >= minI
and x[2][3] <= maxI:
77 runs_b_on.append(int(x[0]))
79 except Exception, er :
82 print "### runs with good B field ###"
95 dbs_quiery =
"find run where dataset="+options.dqDataset+
" and dq="+options.dqCriteria
97 os.system(
'python $DBSCMD_HOME/dbsCommandLine.py -c search --noheader --query="'+dbs_quiery+
'" | sort > /tmp/runs_full_of_pink_bunnies')
101 ff = open(
'/tmp/runs_full_of_pink_bunnies',
"r")
103 while line
and line!=
'':
104 runs_good_dq.append(int(line))
108 os.system(
'rm /tmp/runs_full_of_pink_bunnies')
110 print "### runs with good quality ###"
120 usage=
'%prog [options]\n\n'+\
121 'Creates a Python configuration file with filenames for runs in specified run range, with certain min B field and data quality requirements.'
123 parser=optparse.OptionParser(usage)
125 parser.add_option(
"-d",
"--alcaDataset",
126 help=
"[REQUIRED] Name of the input AlCa dataset to get filenames from.",
133 parser.add_option(
"-m",
"--isMC",
134 help=
"Whether sample is MC (true) or real data (false).",
139 parser.add_option(
"-s",
"--startRun",
140 help=
"First run number in range.",
145 parser.add_option(
"-e",
"--endRun",
146 help=
"Last run number in range.",
151 parser.add_option(
"-b",
"--minB",
152 help=
"Lower limit on minimal B field for a run.",
158 parser.add_option(
"--maxB",
159 help=
"Upper limit on B field for a run.",
164 parser.add_option(
"-t",
"--dbTag",
165 help=
"Runinfo DB tag to use.",
167 default=
"runinfo_31X_hlt",
170 parser.add_option(
"--printTags",
171 help=
"If present, the only thing script will do is printing list of tags in the DB",
176 parser.add_option(
"--dbName",
177 help=
"RunInfo DB name to use. The default one is "+\
178 "'oracle://cms_orcoff_prod/CMS_COND_31X_RUN_INFO'",
180 default=
"oracle://cms_orcoff_prod/CMS_COND_31X_RUN_INFO",
183 parser.add_option(
"--dqDataset",
184 help=
"Dataset name to query for good data quality runs. "+\
185 "If this option is not used, dqDataset=alcaDataset is automatically set. "+\
186 "If alcaDataset does not have DQ information use /Cosmics/Commissioning08-v1/RAW for CRAFT08 "+\
187 "and use /Cosmics/CRAFT09-v1/RAW for CRAFT08",
194 parser.add_option(
"-c",
"--dqCriteria",
195 help=
"Set of DQ criteria to use with -dq flag of dbs.\n"+\
196 "An example of a really strict condition:\n"
197 "'DT_Shift_Offline=GOOD&CSC_Shift_Offline=GOOD&SiStrip_Shift_Offline=GOOD&Pixel_Shift_Offline=GOOD'",
205 parser.add_option(
"-o",
"--outputFile",
206 help=
"Name for output file (please include the .py suffix)",
208 default=
"filelist.py",
211 parser.add_option(
"-v",
"--verbose",
212 help=
"Degree of debug info verbosity",
217 options,args=parser.parse_args()
225 if options.alcaDataset==
'' and not options.printTags:
226 print "--alcaDataset /your/dataset/name is required!"
229 if options.dqDataset==
'':
230 options.dqDataset = options.alcaDataset
232 if not (options.isMC==
'true' or options.isMC==
'false'):
233 print "--isMC option can have only 'true' or 'false' arguments"
238 minI = options.minB*18160/3.8
239 maxI = options.maxB*18160/3.8
242 copyargs = sys.argv[:]
243 for i
in range(len(copyargs)):
244 if copyargs[i] ==
"":
247 infotofile = [
"### %s\n" %
" ".
join(copyargs)]
249 allOptions =
'### ' + copyargs[0] +
' --alcaDataset ' + options.alcaDataset +
' --isMC ' + options.isMC + \
250 ' --startRun ' + str(options.startRun) +
' --endRun '+ str(options.endRun) + \
251 ' --minB ' + str(options.minB) +
' --maxB ' + str(options.maxB) + \
252 ' --dbTag ' + options.dbTag +
' --dqDataset ' + options.dqDataset +
' --dqCriteria "' + options.dqCriteria +
'"'\
253 ' --outputFile ' + options.outputFile
255 print "### all options, including default:"
265 if options.isMC==
'false':
268 infotofile.append(
"### runs with good B field ###\n")
269 infotofile.append(
"### %s\n" % str(runs_b_on))
277 if options.isMC==
'false':
280 infotofile.append(
"### runs with good quality ###\n")
281 infotofile.append(
"### %s\n" % str(runs_good_dq))
284 runs_good = [val
for val
in runs_b_on
if val
in runs_good_dq]
286 print "### runs with good B field and quality ###"
289 infotofile.append(
"### runs with good B field and quality ###\n")
290 infotofile.append(
"### %s\n" % str(runs_good))
295 dbs_quiery =
"find run, file.numevents, file where dataset="+options.alcaDataset+
" and run>="+str(options.startRun)+
" and run <="+str(options.endRun)
297 os.system(
'python $DBSCMD_HOME/dbsCommandLine.py -c search --noheader --query="'+dbs_quiery+
'" | sort > /tmp/runs_and_files_full_of_pink_bunnies')
303 ff = open(
'/tmp/runs_and_files_full_of_pink_bunnies',
'r')
305 (run, numevents, fname) = line.split(
' ')
306 if options.isMC==
'false' and (int(run)
not in runs_good):
308 fname = fname.rstrip(
'\n')
309 list_of_files.append(fname)
310 list_of_runs.append(run)
311 total_numevents += int(numevents)
313 os.system(
'rm /tmp/runs_and_files_full_of_pink_bunnies')
314 print "### total number of events in those runs = "+str(total_numevents)
316 infotofile.append(
"### total number of events in those runs = "+str(total_numevents))
322 size = len(list_of_files)
327 ff = open(options.outputFile,
'w')
328 ff.write(
"".
join(infotofile))
329 ff.write(
"\nfileNames = [\n")
331 for i
in range(0,size):
334 ff.write(
" '"+ list_of_files[i] +
"'"+comma+
" # "+ list_of_runs[i] +
"\n")
static std::string join(char **cmd)
def getGoodBRuns
functions definitions
def getGoodQRuns
obtaining list of good quality runs