15 from CoolRunQuery.utils.AtlRunQueryTimer
import timer
21 from CoolRunQuery.utils.AtlRunQueryUtils
import coolDbConn, runsOnServer
23 from CoolRunQuery.selector.AtlRunQuerySelectorRuntime
import RunTimeSelector
24 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import Selector, DataKey
26 from CoolRunQuery.AtlRunQueryRun
import Run
27 from CoolRunQuery.AtlRunQueryQueryConfig
import QC
36 def __init__(self, options, readoracle=False, loglevel=1, html="AUTO", origQuery="", datapath='data', parsedstring=""):
41 self.
config(options, readoracle, loglevel, html, origQuery, datapath, parsedstring)
43 with timer(
'run all'):
46 with timer(
'evaluate all'):
47 (dic, dicsum, xmlhtmlstr, roothtmlstr) = self.
evaluate(runlist)
49 with timer(
'output all'):
50 self.
output(runlist, dic, dicsum, xmlhtmlstr, roothtmlstr)
52 with timer(
'finalize'):
55 from CoolRunQuery.utils.AtlRunQueryTimer
import TimerStats
as TS
61 def config(self, options, readoracle, loglevel, html, origQuery, datapath, parsedstring):
65 QC.datapath = datapath
82 os.makedirs(QC.datapath, exist_ok =
True)
83 print(
"Using output directory: %s" % QC.datapath)
84 except (PermissionError, FileExistsError)
as err:
85 print(
"Could not create data output directory: %s" % QC.datapath)
86 print(
"Reason: %s" % err)
87 print(
"Will write to local directory")
116 raise RuntimeError (
"Unknown argument for option 'html': %s" % html)
117 Run.writehtml = self.
html
133 Selector.setCondDBMC()
144 nemo_dir =
'/afs/cern.ch/user/a/atlcond/scratch0/nemo/prod/web/'
146 f =
open( nemo_dir +
'calibruns.txt' )
150 Run.PromptCalibRuns.append(
int(line.strip()) )
155 fname = os.listdir( nemo_dir +
'tasks' )
157 for taskname
in fname:
158 m = re.match(
r'.*(task_(\d+)_\d+.txt)',taskname)
161 fname, runnr = m.groups()
162 Run.NemoTasks[
int(runnr)] = fname
163 except IOError
as err:
165 print (
"Because of this I can't mark runs that are currently in the calibration loop")
168 if 'cosmics' in options.show:
170 elif 'heavyions' in options.show:
171 self.
dqsumgrl =
"PHYS_HeavyIonP_All_Good"
175 self.
dqsumgrl =
'PHYS_StandardGRL_All_Good_25ns'
181 self.
dbbtag = (
"HEAD",
"HEAD")
186 from CoolRunQuery.AtlRunQuerySFO
import GetSFO_lastNruns
187 sfoconnection = coolDbConn.GetSFODBConnection()
188 sfocursor = sfoconnection.cursor()
190 if 'OPENED' in retlist[0][1]:
191 Run.runnropen = retlist[0][0]
196 for idx
in range(len(runlist)):
197 rrange = runlist[idx]
198 if 'last' not in rrange:
200 rrange = rrange.replace(
'last',
'')
204 runlist[idx] =
'%i+' % (retlist[-1][0])
210 from CoolRunQuery.utils.AtlRunQueryUtils
import get_runs_last_dt
213 runlist = [
'%i+' % rlist[-1]]
if (len(rlist)>0)
else [
'99999999+']
217 from CoolRunQuery.utils.AtlRunQueryUtils
import timeStringToSecondsUTC,secondsToTimeStringUTC,get_run_range2,GetTimeRanges
219 timeranges,timerangesHR =
GetTimeRanges(timelist, intRepFnc=timeStringToSecondsUTC, maxval=time())
220 timerangesAsString = [
list(map(secondsToTimeStringUTC, tr))
for tr
in timeranges ]
221 runranges = [ (
"%s-%s" %
get_run_range2(tr[0],tr[1]) )
for tr
in timerangesAsString]
222 runlist = [
','.
join(runranges)]
226 rtSel = RunTimeSelector(name =
'runtime', runlist = runlist)
229 runlist = rtSel.select()
241 from CoolRunQuery.AtlRunQuerySelectorWorker
import SelectorWorker
250 SelectorWorker.setApplySelection()
253 SelectorWorker.setShowOutput()
255 SelectorWorker.getRetrieveSelector(
'trigkey',
'TrigKeySelector')
258 for s
in SelectorWorker.getOrderedSelectorList():
260 if hasattr(s,
'initialize'):
261 with timer(
"initializing selector '%s'" % s.name):
266 for s
in SelectorWorker.selectors():
267 with timer(
"run selector '%s'" % s.name):
269 runlist = s.select(runlist)
271 with timer(
"run AfterQuery for selector '%s'" % s.name):
272 s.runAfterQuery(runlist)
279 print (
'SELOUT Selecting the %i most recent runs' % self.
maxNumOfRuns)
289 with timer(
'CreateResultDict'):
290 from CoolRunQuery.output.AtlRunQuerySave
import CreateResultDict
296 with timer(
'CreateXMLFile'):
297 print (
"Producing XML file")
298 from CoolRunQuery.output.AtlRunQueryXML
import CreateXMLFile
299 from CoolRunQuery.AtlRunQueryVersion
import SvnVersion
304 print (
"Creation of GRL disabled")
306 if self.
dictroot and len(runlist) > 0:
307 with timer(
'CreateRootFile'):
309 from CoolRunQuery.output.AtlRunQueryRoot
import CreateRootFile
313 print (
"Creation of root file disabled")
315 return (dic, dicsum, xmlhtmlstr, roothtmlstr)
318 def output(self, runlist, dic, dicsum, xmlhtmlstr, roothtmlstr):
322 with timer(
'GetOKS link info'):
323 from CoolRunQuery.AtlRunQuerySFO
import SetOKSLinks
327 from CoolRunQuery.html.AtlRunQueryHTML
import ResultPageMaker
329 pageinfo = {
'datapath' : QC.datapath,
341 'roothtmlstr' : roothtmlstr,
343 'xmlhtmlstr' : xmlhtmlstr,
347 with timer(
"run ResultPageMaker makePage"):
348 ResultPageMaker.makePage(pageinfo)
353 print (
'---------------------------------------------------------------------')
359 from CoolRunQuery.utils.AtlRunQueryUtils
import addKommaToNumber, filesize
361 for data_key, summary
in dicsum.items():
362 if data_key.Type==DataKey.STREAM:
363 key = data_key.ResultKey.replace(
'STR:',
'')
366 key = data_key.ResultKey
368 print (
'%20s : %s' % (key,val))
370 print (
"%20s : %g sec" % (
'Total execution time',duration))
371 print (
'---------------------------------------------------------------------')
374 coolDbConn.CloseAll()
376 if __name__ ==
'__main__':
377 from CoolRunQuery.AtlRunQueryOptions
import AtlRunQueryOptions
378 (options, args) = AtlRunQueryOptions().
parse()