55 import sys, string, os.path, os, pickle, time, pprint
56 from xmlrpc
import client
as xmlrpclib
59 from subprocess
import getstatusoutput
66 if os.path.isfile(fname) :
67 sz = os.path.getsize(fname)
78 import stomp, json, ssl
79 from DataQualityUtils
import stompconfig
80 dest=
'/topic/atlas.dqm.progress'
81 conn=stomp.Connection([(
'atlas-mb.cern.ch', 61013)])
82 conn.connect(wait=
True, **stompconfig.config())
94 'MsgType': ((
'' if isprod
else 'Development') +
95 (
'WebDisplayRunComplete' if not incr
else 'WebDisplayIncremental')),
100 conn.send(body=json.dumps(body), destination=dest,headers=headers,ack=
'auto')
106 md5summer=hashlib.md5()
107 if os.path.isfile(filename):
109 infil=
open(filename,
'rb')
117 print(
"md5 sum of the \"%s\" is %s"%(filename,md5summer.hexdigest()))
124 print(
"\n##################################################################")
125 print(
"## ATLAS Tier-0 Offline DQM Processing ##")
126 print(
"##################################################################\n")
128 print(
"\n##################################################################")
129 print(
"## STEP 1: creating file with list of root files ...")
130 print(
"##################################################################\n")
133 print(
"Using pickled file ", picklefile,
" for input parameters")
134 f =
open(picklefile,
'r')
135 parmap = pickle.load(f)
138 print(
"\nFull Tier-0 run options:\n")
139 pprint.pprint(parmap)
141 inputfilelist = parmap.get(
'inputHistFiles', [])
142 nfiles = len(inputfilelist)
143 histMergeCompressionLevel=parmap.get(
'histMergeCompressionLevel', 1)
144 histMergeDebugLevel=parmap.get(
'histMergeDebugLevel', 0)
147 dt =
int(time.time() - tstart)
149 acronym =
'TRF_NOINPUT'
150 txt =
'empty input file list'
151 reportmap = {
'prodsys': {
'trfCode': retcode,
152 'trfAcronym': acronym,
156 'more': {
'num1': 0,
'num2': dt,
'txt1': txt }
164 if isinstance(inputfilelist[0], str) :
165 histtmpdsname = (inputfilelist[0]).
split(
'#')[0]
166 for val
in inputfilelist :
167 histtmpflist.append(val.split(
'#')[1])
169 elif isinstance(inputfilelist[0], dict) :
170 histtmpdsname = inputfilelist[0][
'dsn']
171 for fdict
in inputfilelist :
172 histtmpflist.append(fdict[
'lfn'])
173 nevt = fdict.get(
'events', 0)
176 print(
"WARNING Can't get number of events from input pickle file")
179 f =
open(
'hist_merge.list',
'w')
181 for hf
in histtmpflist :
182 txtstr +=
"%s\n" % hf
186 cmd =
"cat hist_merge.list"
187 (s,o) = getstatusoutput(cmd)
188 print(
"\nContents of file hist_merge.list:\n")
192 print(
"\n##################################################################")
193 print(
"## STEP 2: determining job parameters...")
194 print(
"##################################################################\n")
197 histdsname = (parmap[
'outputHistFile']).
split(
'#')[0]
198 histfile = (parmap[
'outputHistFile']).
split(
'#')[1]
199 amitag = histfile.split(
'.')[5]
203 incr = parmap.get(
'incrementalMode',
'False')
206 postproc = parmap.get(
'postProcessing',
'True')
209 allowCOOLUpload = parmap.get(
'allowCOOLUpload',
'True')
212 doWebDisplay = parmap.get(
'doWebDisplay',
'True')
215 productionMode = parmap.get(
'productionMode',
'True')
216 if productionMode !=
'True' and incr ==
'True':
217 print(
"Production mode is not True, turning off incremental mode")
221 filepaths = parmap.get(
'filepaths',
None)
222 if filepaths
and isinstance(filepaths, dict):
223 if 'basename' not in filepaths:
224 print(
"Improperly formed 'filepaths' (no 'basename')")
226 for evtclass
in (
'Collisions',
'Cosmics',
'HeavyIons'):
227 if evtclass
not in filepaths:
228 print(
"Improperly formed 'filepaths' (no '%s')" % evtclass)
230 clinfo = filepaths[evtclass]
231 for timeclass
in (
'run',
'minutes10',
'minutes30'):
232 if timeclass
not in clinfo:
233 print(
"Improperly formed 'filepaths[%s]' (no '%s')" % (evtclass, timeclass))
235 dqcenvvar =
'DQC_HCFG_%s_%s' % (evtclass.upper(), timeclass.upper())
236 fpath = os.path.join(filepaths[
'basename'], clinfo[timeclass])
237 print(
"Setting %s = %s" % (dqcenvvar, fpath))
238 os.environ[dqcenvvar] = fpath
244 dqproject = histdsname.split(
'.')[0]
246 dqproject =
'data_test'
247 dqproject = parmap.get(
'projectTag', dqproject)
250 if 'runNumber' in parmap :
251 runnr = parmap[
'runNumber']
254 runnr =
int(histdsname.split(
'.')[1])
259 if 'streamName' in parmap :
260 stream = parmap[
'streamName']
263 stream = histdsname.split(
'.')[2]
265 stream =
'test_dummy'
269 if 'procNumber' in parmap :
270 procnumber = parmap[
'procNumber']
273 while n_xmlrpc_tries <= MAX_XMLRPC_TRIES :
276 xmlrpcserver = xmlrpclib.ServerProxy(
'http://atlasdqm.cern.ch:8888')
277 procnumber = xmlrpcserver.get_next_proc_pass(runnr, stream,
'tier0')
280 print(
'Web service connection failed, attempt', n_xmlrpc_tries,
'of', MAX_XMLRPC_TRIES)
282 if n_xmlrpc_tries <= MAX_XMLRPC_TRIES:
283 time.sleep(20*2**n_xmlrpc_tries)
285 print(
"Job parameters:\n")
286 print(
" Run number: ", runnr)
287 print(
" Stream name: ", stream)
288 print(
" Processing pass: ", procnumber)
289 print(
" Incremental mode:", incr)
290 print(
" Post-processing: ", postproc)
291 print(
" COOL uploads: ", allowCOOLUpload)
292 print(
" Production mode: ", productionMode)
295 print(
"\n##################################################################")
296 print(
"## STEP 3: running histogram merging procedure ...")
297 print(
"##################################################################\n")
300 os.environ[
'DQPRODUCTION'] =
'1' if productionMode ==
'True' else '0'
301 os.environ[
'DQ_STREAM'] = stream
302 print(
"Setting env variable DQPRODUCTION to %s\n" % os.environ[
'DQPRODUCTION'])
303 os.environ[
'COOLUPLOADS'] =
'1' if allowCOOLUpload ==
'True' and productionMode ==
'True' else '0'
304 print(
"Setting env variable COOLUPLOADS to %s\n" % os.environ[
'COOLUPLOADS'])
306 if postproc ==
'True' :
308 cmd =
"python -u `which DQHistogramMerge.py` hist_merge.list %s 1 1 %d %d " % (histfile,histMergeCompressionLevel,histMergeDebugLevel)
310 cmd =
"python -u `which DQHistogramMerge.py` hist_merge.list %s 1 0 %d %d" % (histfile,histMergeCompressionLevel,histMergeDebugLevel)
312 cmd =
"python -u `which DQHistogramMerge.py` hist_merge.list %s 0 0 %d %d" % (histfile,histMergeCompressionLevel,histMergeDebugLevel)
314 print(
"Histogram merging command:\n")
316 print(
"\n##################################################################\n")
318 print(
"## ... logfile from DQHistogramMerge.py: ")
319 print(
"--------------------------------------------------------------------------------")
321 retcode1 = os.system(cmd)
322 print(
"--------------------------------------------------------------------------------")
324 dt1 =
int(t1 - tstart)
326 print(
"\n## DQHistogramMerge.py finished with retcode = %s" % retcode1)
327 print(
"## ... elapsed time: ", dt1,
" sec")
330 if postproc ==
'True' and incr ==
'False':
331 print(
"\n##################################################################")
332 print(
"## STEP 3b: copying postprocessing output to AFS ...")
333 print(
"##################################################################\n")
335 cmd =
"python -u `which DQFileMove.py` %s %s_%s_%s" % (dqproject, runnr, stream, procnumber)
337 print(
"File move command:\n")
339 print(
"\n##################################################################\n")
341 print(
"## ... logfile from DQFileMove.py: ")
342 print(
"--------------------------------------------------------------------------------")
344 retcode1b = os.system(cmd)
345 print(
"--------------------------------------------------------------------------------")
350 print(
"\n## DQFileMove.py finished with retcode = %s" % retcode1b)
351 print(
"## ... elapsed time: ", dt1b,
" sec")
353 if doWebDisplay ==
'True':
354 print(
"\n##################################################################")
355 print(
"## STEP 4: running web-display creation procedure ...")
356 print(
"##################################################################\n")
358 cmd =
"python -u `which DQWebDisplay.py` %s %s %s %s stream=%s" % (histfile, dqproject, procnumber, incr, stream)
360 print(
"Web display creation command:\n")
362 print(
"\n##################################################################\n")
364 print(
"## ... logfile from DQWebDisplay.py: ")
365 print(
"--------------------------------------------------------------------------------")
367 retcode2 = os.system(cmd)
368 print(
'DO NOT REPORT "Error in TH1: cannot merge histograms" ERRORS! THESE ARE IRRELEVANT!')
369 print(
"--------------------------------------------------------------------------------")
373 print(
"\n## DQWebDisplay.py finished with retcode = %s" % retcode2)
374 print(
"## ... elapsed time: ", dt2,
" sec")
376 print(
"\n##################################################################")
377 print(
"## WEB DISPLAY CREATION SKIPPED BY USER REQUEST")
378 print(
"##################################################################\n")
382 print(
"\n##################################################################")
383 print(
"## STEP 5: finishing the job ...")
384 print(
"##################################################################\n")
392 txt =
'trf finished OK'
397 if (retcode2 >> 8)
in (0, 5) :
399 histmap =
getFileMap(histfile, histdsname, nevts=nevts)
402 if doWebDisplay ==
'True':
403 print(
'Publishing to message service')
404 publish_success_to_mq(runnr, dqproject, stream, incr=(incr==
'True'), ami=amitag, procpass=procnumber, hcfg=filepaths, isprod=(productionMode==
'True'))
406 print(
'Web display off, not publishing to message service')
408 txt =
'DQWebDisplay.py execution problem'
409 print(
"ERROR: DQWebDisplay.py execution problem!")
411 acronym =
'TRF_DQMDISPLAY_EXE'
413 infilelist=
open(
'hist_merge.list',
'r')
414 for infname
in infilelist:
420 print(
"ERROR: DQHistogramMerge.py execution problem!")
422 acronym =
'TRF_DQMHISTMERGE_EXE'
424 txt =
'DQHistogramMerge.py execution problem'
426 infilelist=
open(
'hist_merge.list',
'r')
427 for infname
in infilelist:
432 DQResFile=
"DQResourceUtilization.txt"
433 if os.path.exists(DQResFile):
434 print(
"dumping resource utilization log")
435 with open(DQResFile)
as resfile:
436 for resline
in resfile:
437 print(resline, end=
' ')
440 reportmap = {
'prodsys': {
'trfCode': retcode,
441 'trfAcronym': acronym,
442 'jobOutputs': outfiles,
443 'jobInputs': infiles,
444 'nevents':
int(nevts),
445 'more': {
'num1':
int(nevts),
'num2':
int(dt),
'txt1': txt }
450 f =
open(
'jobReport.gpickle',
'w')
451 pickle.dump(reportmap, f)
454 print(
"\n## ... job finished with retcode : %s" % reportmap[
'prodsys'][
'trfCode'])
455 print(
"## ... error acronym: ", reportmap[
'prodsys'][
'trfAcronym'])
456 print(
"## ... elapsed time: ", reportmap[
'prodsys'][
'more'][
'num2'],
"sec")
458 print(
"##################################################################")
459 print(
"## End of job.")
460 print(
"##################################################################\n")
467 if __name__ ==
"__main__":
469 if (len(sys.argv) != 2)
and (
not sys.argv[1].startswith(
'--argdict=')) :
470 print(
"Input format wrong --- use ")
471 print(
" --argdict=<pickled-dictionary containing input info> ")
472 print(
" with key/value pairs: ")
473 print(
" 1) 'inputHistFiles': python list ")
474 print(
" ['datasetname#filename1', 'datasetname#filename2',...] (input dataset + file names) ")
475 print(
" or list of file dictionaries ")
476 print(
" [{'lfn':'fname1', 'checksum':'cks1', 'dsn':'dsn1', 'size':sz1, 'guid':'guid1', 'events':nevts1, ...}, ")
477 print(
" {'lfn':'fname2', 'checksum':'cks2', 'dsn':'dsn2', 'size':sz2, 'guid':'guid2', 'events':nevts2, ...}, ...] ")
478 print(
" 2) 'outputHistFile': string 'datasetname#filename' ")
479 print(
" (HIST output dataset name + file) ")
480 print(
" optional parameters: ")
481 print(
" 3) 'incrementalMode': string ('True'/'False') ")
482 print(
" ('True': do incremental update of DQM webpages on top of existing statistics; ")
483 print(
" 'False': create final DQM webpages, replace temporary ones) ")
484 print(
" 4) 'postProcessing': string ('True'/'False', default: 'True') ")
485 print(
" ('False': run histogram merging and DQ assessment only; ")
486 print(
" 'True': run additional post-processing step (fitting, etc.)) ")
487 print(
" 5) 'procNumber': int (number of processing pass, e.g. 1,2, ...) ")
488 print(
" 6) 'runNumber': int ")
489 print(
" 7) 'streamName': string (e.g., physics_IDCosmic, physics_Express, ...) ")
490 print(
" 8) 'projectTag': string (e.g., data10_7TeV, TrigDisplay)")
491 print(
" 9) 'allowCOOLUpload': string ('True'/'False', default: 'True')")
492 print(
" ('True': allow upload of defects to database; ")
493 print(
" 'False': do not upload defects to database)")
497 picklefile = sys.argv[1][len(
'--argdict='):]