14 from __future__
import with_statement, print_function
16 from CoolRunQuery.utils.AtlRunQueryTimer
import timer
22 from CoolRunQuery.utils.AtlRunQueryUtils
import coolDbConn, runsOnServer
24 from CoolRunQuery.selector.AtlRunQuerySelectorRuntime
import RunTimeSelector
25 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import Selector, DataKey
27 from CoolRunQuery.AtlRunQueryRun
import Run
28 from CoolRunQuery.AtlRunQueryQueryConfig
import QC
37 def __init__(self, options, readoracle=False, loglevel=1, html="AUTO", origQuery="", datapath='data', parsedstring=""):
42 self.
config(options, readoracle, loglevel, html, origQuery, datapath, parsedstring)
44 with timer(
'run all'):
47 with timer(
'evaluate all'):
48 (dic, dicsum, xmlhtmlstr, roothtmlstr) = self.
evaluate(runlist)
50 with timer(
'output all'):
51 self.
output(runlist, dic, dicsum, xmlhtmlstr, roothtmlstr)
53 with timer(
'finalize'):
56 from CoolRunQuery.utils.AtlRunQueryTimer
import TimerStats
as TS
62 def config(self, options, readoracle, loglevel, html, origQuery, datapath, parsedstring):
66 QC.datapath = datapath
83 os.makedirs(QC.datapath, exist_ok =
True)
84 print(
"Using output directory: %s" % QC.datapath)
85 except (PermissionError, FileExistsError)
as err:
86 print(
"Could not create data output directory: %s" % QC.datapath)
87 print(
"Reason: %s" % err)
88 print(
"Will write to local directory")
117 raise RuntimeError (
"Unknown argument for option 'html': %s" % html)
118 Run.writehtml = self.
html
134 Selector.setCondDBMC()
145 nemo_dir =
'/afs/cern.ch/user/a/atlcond/scratch0/nemo/prod/web/'
147 f =
open( nemo_dir +
'calibruns.txt' )
151 Run.PromptCalibRuns.append(
int(line.strip()) )
156 fname = os.listdir( nemo_dir +
'tasks' )
158 for taskname
in fname:
159 m = re.match(
r'.*(task_(\d+)_\d+.txt)',taskname)
162 fname, runnr = m.groups()
163 Run.NemoTasks[
int(runnr)] = fname
164 except IOError
as err:
166 print (
"Because of this I can't mark runs that are currently in the calibration loop")
169 if 'cosmics' in options.show:
171 elif 'heavyions' in options.show:
172 self.
dqsumgrl =
"PHYS_HeavyIonP_All_Good"
176 self.
dqsumgrl =
'PHYS_StandardGRL_All_Good_25ns'
182 self.
dbbtag = (
"HEAD",
"HEAD")
187 from CoolRunQuery.AtlRunQuerySFO
import GetSFO_lastNruns
188 sfoconnection = coolDbConn.GetSFODBConnection()
189 sfocursor = sfoconnection.cursor()
191 if 'OPENED' in retlist[0][1]:
192 Run.runnropen = retlist[0][0]
197 for idx
in range(len(runlist)):
198 rrange = runlist[idx]
199 if 'last' not in rrange:
201 rrange = rrange.replace(
'last',
'')
205 runlist[idx] =
'%i+' % (retlist[-1][0])
211 from CoolRunQuery.utils.AtlRunQueryUtils
import get_runs_last_dt
214 runlist = [
'%i+' % rlist[-1]]
if (len(rlist)>0)
else [
'99999999+']
218 from CoolRunQuery.utils.AtlRunQueryUtils
import timeStringToSecondsUTC,secondsToTimeStringUTC,get_run_range2,GetTimeRanges
220 timeranges,timerangesHR =
GetTimeRanges(timelist, intRepFnc=timeStringToSecondsUTC, maxval=time())
221 timerangesAsString = [
list(map(secondsToTimeStringUTC, tr))
for tr
in timeranges ]
222 runranges = [ (
"%s-%s" %
get_run_range2(tr[0],tr[1]) )
for tr
in timerangesAsString]
223 runlist = [
','.
join(runranges)]
227 rtSel = RunTimeSelector(name =
'runtime', runlist = runlist)
230 runlist = rtSel.select()
242 from CoolRunQuery.AtlRunQuerySelectorWorker
import SelectorWorker
251 SelectorWorker.setApplySelection()
254 SelectorWorker.setShowOutput()
256 SelectorWorker.getRetrieveSelector(
'trigkey',
'TrigKeySelector')
259 for s
in SelectorWorker.getOrderedSelectorList():
261 if hasattr(s,
'initialize'):
262 with timer(
"initializing selector '%s'" % s.name):
267 for s
in SelectorWorker.selectors():
268 with timer(
"run selector '%s'" % s.name):
270 runlist = s.select(runlist)
272 with timer(
"run AfterQuery for selector '%s'" % s.name):
273 s.runAfterQuery(runlist)
280 print (
'SELOUT Selecting the %i most recent runs' % self.
maxNumOfRuns)
290 with timer(
'CreateResultDict'):
291 from CoolRunQuery.output.AtlRunQuerySave
import CreateResultDict
297 with timer(
'CreateXMLFile'):
298 print (
"Producing XML file")
299 from CoolRunQuery.output.AtlRunQueryXML
import CreateXMLFile
300 from CoolRunQuery.AtlRunQueryVersion
import SvnVersion
305 print (
"Creation of GRL disabled")
307 if self.
dictroot and len(runlist) > 0:
308 with timer(
'CreateRootFile'):
310 from CoolRunQuery.output.AtlRunQueryRoot
import CreateRootFile
314 print (
"Creation of root file disabled")
316 return (dic, dicsum, xmlhtmlstr, roothtmlstr)
319 def output(self, runlist, dic, dicsum, xmlhtmlstr, roothtmlstr):
323 with timer(
'GetOKS link info'):
324 from CoolRunQuery.AtlRunQuerySFO
import SetOKSLinks
328 from CoolRunQuery.html.AtlRunQueryHTML
import ResultPageMaker
330 pageinfo = {
'datapath' : QC.datapath,
342 'roothtmlstr' : roothtmlstr,
344 'xmlhtmlstr' : xmlhtmlstr,
348 with timer(
"run ResultPageMaker makePage"):
349 ResultPageMaker.makePage(pageinfo)
354 print (
'---------------------------------------------------------------------')
360 from CoolRunQuery.utils.AtlRunQueryUtils
import addKommaToNumber, filesize
362 for data_key, summary
in dicsum.items():
363 if data_key.Type==DataKey.STREAM:
364 key = data_key.ResultKey.replace(
'STR:',
'')
367 key = data_key.ResultKey
369 print (
'%20s : %s' % (key,val))
371 print (
"%20s : %g sec" % (
'Total execution time',duration))
372 print (
'---------------------------------------------------------------------')
375 coolDbConn.CloseAll()
377 if __name__ ==
'__main__':
378 from CoolRunQuery.AtlRunQueryOptions
import AtlRunQueryOptions
379 (options, args) = AtlRunQueryOptions().
parse()