@@ -67,6 +67,9 @@ def fetch(self, path, obj_type, timestamp=None, meta_info=None):
6767
6868 return timestamp , obj
6969
70+ def get_run_duration (self , run_number ):
71+ return o2 .ccdb .BasicCCDBManager .instance ().getRunDuration (run_number )
72+
7073 def fetch_header (self , path , timestamp = None ):
7174 meta_info = std .map ["std::string" , "std::string" ]()
7275 if timestamp is None :
@@ -75,22 +78,6 @@ def fetch_header(self, path, timestamp=None):
7578 return header
7679
7780
78-
79- def retrieve_sor_eor (ccdbreader , run_number ):
80- """
81- retrieves start of run (sor) and end of run (eor) given a run number
82- from the RCT/Info/RunInformation table
83- """
84-
85- path_run_info = "RCT/Info/RunInformation"
86- header = ccdbreader .fetch_header (path_run_info , run_number )
87- if not header :
88- print (f"WARNING: Cannot find run information for run number { run_number } " )
89- return None
90- # return this a dictionary
91- return {"SOR" : int (header ["SOR" ]), "EOR" : int (header ["EOR" ])}
92-
93-
9481def retrieve_CCDBObject_asJSON (ccdbreader , path , timestamp , objtype_external = None ):
9582 """
9683 Retrieves a CCDB object as a JSON/dictionary.
@@ -111,7 +98,7 @@ def retrieve_CCDBObject_asJSON(ccdbreader, path, timestamp, objtype_external = N
11198 jsonTString = TBufferJSON .ConvertToJSON (obj , TClass .GetClass (objtype ))
11299 return json .loads (jsonTString .Data ())
113100
114- def retrieve_params_fromGRPECS (ccdbreader , run_number , rct = None ):
101+ def retrieve_params_fromGRPECS (ccdbreader , run_number , run_start = None , run_end = None ):
115102 """
116103 Retrieves start of run (sor), end of run (eor) and other global parameters from the GRPECS object,
117104 given a run number. We first need to find the right object
@@ -150,22 +137,18 @@ def retrieve_params_fromGRPECS(ccdbreader, run_number, rct = None):
150137 # object, with which we can query the end time as well
151138 grp = retrieve_CCDBObject_asJSON (ccdbreader , "/GLO/Config/GRPECS" + "/runNumber=" + str (run_number ) + "/" , int (SOV ))
152139
153-
154140 # check that this object is really the one we wanted based on run-number
155141 assert (int (grp ["mRun" ]) == int (run_number ))
156142
157143 SOR = int (grp ["mTimeStart" ]) # in milliseconds
158144 EOR = int (grp ["mTimeEnd" ])
159145 # cross check with RCT if available
160- if rct != None :
161- # verify that the variaous sor_eor information are the same
162- if SOR != rct ["SOR" ]:
163- print ("WARNING: Inconsistent SOR information on CCDB (divergence between GRPECS and RCT) ... will take RCT one" )
164- SOR = rct ["SOR" ]
165-
166- if EOR != rct ["EOR" ]:
167- print ("WARNING: Inconsistent EOR information on CCDB (divergence between GRPECS and RCT) ... will take RCT one" )
168- EOR = rct ["EOR" ]
146+ if run_start is not None :
147+ print (f"INFO: GRPECS SOR ({ SOR } ) will be superseded by externally provided run start ({ run_start } )" )
148+ SOR = run_start
149+ if run_end is not None :
150+ print (f"INFO: GRPECS EOR ({ EOR } ) will be superseded by externally provided run end ({ run_end } )" )
151+ EOR = run_end
169152
170153 # fetch orbit reset to calculate orbitFirst
171154 ts , oreset = ccdbreader .fetch ("CTP/Calib/OrbitReset" , "vector<Long64_t>" , timestamp = SOR )
@@ -319,7 +302,6 @@ def main():
319302 parser .add_argument ("-tf" , type = int , help = "number of timeframes per job" , default = 1 )
320303 parser .add_argument ("--ccdb-IRate" , type = bool , help = "whether to try fetching IRate from CCDB/CTP" , default = True )
321304 parser .add_argument ("--trig-eff" , type = float , dest = "trig_eff" , help = "Trigger eff needed for IR" , default = - 1.0 )
322- parser .add_argument ("--use-rct-info" , dest = "use_rct_info" , action = "store_true" , help = argparse .SUPPRESS ) # Use SOR and EOR information from RCT instead of SOX and EOX from CTPScalers
323305 parser .add_argument ('forward' , nargs = argparse .REMAINDER ) # forward args passed to actual workflow creation
324306 args = parser .parse_args ()
325307
@@ -329,34 +311,21 @@ def main():
329311 # make a CCDB accessor object
330312 ccdbreader = CCDBAccessor (args .ccdb_url )
331313 # fetch the EOR/SOR
332- rct_sor_eor = retrieve_sor_eor (ccdbreader , args .run_number ) # <-- from RCT/Info
333- GLOparams = retrieve_params_fromGRPECS (ccdbreader , args .run_number , rct = rct_sor_eor )
314+ run_duration = ccdbreader .get_run_duration (args .run_number )
315+ run_start = run_duration .first
316+ run_end = run_duration .second
317+
318+ GLOparams = retrieve_params_fromGRPECS (ccdbreader , args .run_number , run_start = run_start , run_end = run_end )
334319 if not GLOparams :
335- print ("No time info found " )
320+ print ("ERROR: Could not retrieve information from GRPECS " )
336321 sys .exit (1 )
337322
338- ctp_scalers = retrieve_CTPScalers (ccdbreader , args .run_number )
339- if ctp_scalers is None :
340- print (f"ERROR: Cannot retrive scalers for run number { args .run_number } " )
341- exit (1 )
342-
343- first_orbit = ctp_scalers .getOrbitLimit ().first
344- # SOR and EOR values in milliseconds
345- sor = ctp_scalers .getTimeLimit ().first
346- eor = ctp_scalers .getTimeLimit ().second
347-
348- if args .use_rct_info :
349- first_orbit = GLOparams ["FirstOrbit" ]
350- # SOR and EOR values in milliseconds
351- sor = GLOparams ["SOR" ]
352- eor = GLOparams ["EOR" ]
353-
354323 # determine timestamp, and production offset for the final MC job to run
355- timestamp , prod_offset = determine_timestamp (sor , eor , [args .split_id - 1 , args .prod_split ], args .cycle , args .tf , GLOparams ["OrbitsPerTF" ])
324+ timestamp , prod_offset = determine_timestamp (run_start , run_end , [args .split_id - 1 , args .prod_split ], args .cycle , args .tf , GLOparams ["OrbitsPerTF" ])
356325
357326 # this is anchored to
358- print ("Determined start-of-run to be: " , sor )
359- print ("Determined end-of-run to be: " , eor )
327+ print ("Determined start-of-run to be: " , run_start )
328+ print ("Determined end-of-run to be: " , run_end )
360329 print ("Determined timestamp to be : " , timestamp )
361330 print ("Determined offset to be : " , prod_offset )
362331
@@ -399,7 +368,10 @@ def main():
399368 effTrigger = 28.0 # this is ZDC
400369 else :
401370 effTrigger = 0.759
402-
371+ ctp_scalers = retrieve_CTPScalers (ccdbreader , args .run_number )
372+ if ctp_scalers is None :
373+ print (f"ERROR: Cannot retrive scalers for run number { args .run_number } " )
374+ exit (1 )
403375 # time needs to be converted to seconds ==> timestamp / 1000
404376 rate = retrieve_MinBias_CTPScaler_Rate (ctp_scalers , timestamp / 1000. , effTrigger , grplhcif .getBunchFilling ().getNBunches (), ColSystem )
405377
@@ -415,8 +387,8 @@ def main():
415387 # we finally pass forward to the unanchored MC workflow creation
416388 # TODO: this needs to be done in a pythonic way clearly
417389 # NOTE: forwardargs can - in principle - contain some of the arguments that are appended here. However, the last passed argument wins, so they would be overwritten.
418- forwardargs += " -tf " + str (args .tf ) + " --sor " + str (sor ) + " --timestamp " + str (timestamp ) + " --production-offset " + str (prod_offset ) + " -run " + str (args .run_number ) + " --run-anchored --first-orbit " \
419- + str (first_orbit ) + " -field ccdb -bcPatternFile ccdb" + " --orbitsPerTF " + str (GLOparams ["OrbitsPerTF" ]) + " -col " + str (ColSystem ) + " -eCM " + str (eCM ) + ' --readoutDets ' + GLOparams ['detList' ]
390+ forwardargs += " -tf " + str (args .tf ) + " --sor " + str (run_start ) + " --timestamp " + str (timestamp ) + " --production-offset " + str (prod_offset ) + " -run " + str (args .run_number ) + " --run-anchored --first-orbit " \
391+ + str (GLOparams [ "FirstOrbit" ] ) + " -field ccdb -bcPatternFile ccdb" + " --orbitsPerTF " + str (GLOparams ["OrbitsPerTF" ]) + " -col " + str (ColSystem ) + " -eCM " + str (eCM ) + ' --readoutDets ' + GLOparams ['detList' ]
420392 print ("forward args " , forwardargs )
421393 cmd = "${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py " + forwardargs
422394 print ("Creating time-anchored workflow..." )
0 commit comments