Skip to content

Commit e2d3cd1

Browse files
committed
fetch timestamp based on run number
This is fixing the timestamp to the run number, in case no external timestamp was passed.
1 parent 62fb02c commit e2d3cd1

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

MC/bin/o2dpg_sim_workflow.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import json
2727
import itertools
2828
import time
29+
import requests, re
2930

3031
sys.path.append(join(dirname(__file__), '.', 'o2dpg_workflow_utils'))
3132

@@ -186,13 +187,34 @@ def addWhenActive(detID, needslist, appendstring):
186187
if isActive(detID):
187188
needslist.append(appendstring)
188189

190+
191+
def retrieve_sor(run_number):
192+
"""
193+
retrieves start of run (sor)
194+
from the RCT/RunInformation table with a simple http request
195+
in case of problems, 0 will be returned
196+
"""
197+
url="http://alice-ccdb.cern.ch/browse/RCT/RunInformation/"+str(run_number)
198+
ansobject=requests.get(url)
199+
tokens=ansobject.text.split("\n")
200+
201+
SOR=0
202+
# extract SOR by pattern matching
203+
for t in tokens:
204+
match_object=re.match("\s*(SOR\s*=\s*)([0-9]*)\s*", t)
205+
if match_object != None:
206+
SOR=match_object[2]
207+
break
208+
209+
return SOR
210+
211+
189212
# ----------- START WORKFLOW CONSTRUCTION -----------------------------
190213

191-
# set the time
214+
# set the time to start of run (if no timestamp specified)
192215
if args.timestamp==-1:
193-
# 1000 to convert seconds into milliseconds.
194-
args.timestamp = int(time.time() * 1000)
195-
print("Setting timestamp to ", args.timestamp)
216+
args.timestamp = retrieve_sor(args.run)
217+
assert (args.timestamp != 0)
196218

197219
NTIMEFRAMES=int(args.tf)
198220
NWORKERS=args.j
@@ -310,8 +332,10 @@ def getDPL_global_options(bigshm=False):
310332

311333
BKGtask=createTask(name='bkgsim', lab=["GEANT"], needs=[BKG_CONFIG_task['name']], cpu=NWORKERS )
312334
BKGtask['cmd']='${O2_ROOT}/bin/o2-sim -e ' + SIMENGINE + ' -j ' + str(NWORKERS) + ' -n ' + str(NBKGEVENTS) \
313-
+ ' -g ' + str(GENBKG) + ' ' + str(MODULES) + ' -o bkg ' + str(INIBKG) \
314-
+ ' --field ' + str(BFIELD) + ' ' + str(CONFKEYBKG) + ' --timestamp ' + str(args.timestamp)
335+
+ ' -g ' + str(GENBKG) + ' ' + str(MODULES) + ' -o bkg ' + str(INIBKG) \
336+
+ ' --field ' + str(BFIELD) + ' ' + str(CONFKEYBKG) \
337+
+ ('',' --timestamp ' + str(args.timestamp))[args.timestamp!=-1] + ' --run ' + str(args.run)
338+
315339
if not "all" in activeDetectors:
316340
BKGtask['cmd'] += ' --readoutDetectors ' + " ".join(activeDetectors)
317341

@@ -491,7 +515,8 @@ def getDPL_global_options(bigshm=False):
491515
SGNtask['cmd']='${O2_ROOT}/bin/o2-sim -e ' + str(SIMENGINE) + ' ' + str(MODULES) + ' -n ' + str(NSIGEVENTS) + ' --seed ' + str(TFSEED) \
492516
+ ' --field ' + str(BFIELD) + ' -j ' + str(NWORKERS) + ' -g ' + str(GENERATOR) \
493517
+ ' ' + str(TRIGGER) + ' ' + str(CONFKEY) + ' ' + str(INIFILE) \
494-
+ ' -o ' + signalprefix + ' ' + embeddinto + ' --timestamp ' + str(args.timestamp)
518+
+ ' -o ' + signalprefix + ' ' + embeddinto \
519+
+ (' --timestamp ' + str(args.timestamp))[args.timestamp!=-1] + ' --run ' + args.run
495520
if not "all" in activeDetectors:
496521
SGNtask['cmd'] += ' --readoutDetectors ' + " ".join(activeDetectors)
497522
workflow['stages'].append(SGNtask)
@@ -547,10 +572,12 @@ def getDPL_global_options(bigshm=False):
547572
startOrbit = (tf-1 + int(args.production_offset)*NTIMEFRAMES)*orbitsPerTF
548573
globalTFConfigValues = { "HBFUtils.orbitFirstSampled" : args.first_orbit + startOrbit,
549574
"HBFUtils.nHBFPerTF" : orbitsPerTF,
550-
"HBFUtils.startTime" : args.timestamp,
551575
"HBFUtils.orbitFirst" : args.first_orbit,
552576
"HBFUtils.runNumber" : args.run }
553-
577+
# we set the timesamp here only if specified explicitely (otherwise it will come from
578+
# the simulation GRP and digitization)
579+
if (args.timestamp != -1):
580+
globalTFConfigValues["HBFUtils.startTime"] = args.timestamp
554581

555582
def putConfigValues(localCF = {}):
556583
"""

0 commit comments

Comments
 (0)