2828# this is PyROOT; enables reading ROOT C++ objects
2929from ROOT import o2 , TFile , TString , TBufferJSON , TClass , std
3030
31+ # some global constants
32+ # this should be taken from the C++ code (via PyROOT and library access to these constants)
33+ LHCMaxBunches = 3564 ; # max N bunches
34+ LHCRFFreq = 400.789e6 ; # LHC RF frequency in Hz
35+ LHCBunchSpacingNS = 10 * 1.e9 / LHCRFFreq ; # bunch spacing in ns (10 RFbuckets)
36+ LHCOrbitNS = LHCMaxBunches * LHCBunchSpacingNS ; # orbit duration in ns
37+ LHCOrbitMUS = LHCOrbitNS * 1e-3 ; # orbit duration in \mus
38+ LHCBunchSpacingMUS = LHCBunchSpacingNS * 1e-3 # bunch spacing in mus
3139
3240# these need to go into a module / support layer
3341class CCDBAccessor :
@@ -90,7 +98,7 @@ def retrieve_sor_eor(ccdbreader, run_number):
9098 return {"SOR" : int (header ["SOR" ]), "EOR" : int (header ["EOR" ])}
9199
92100
93- def retrieve_CCDBObject_asJSON (ccdbreader , path , timestamp ):
101+ def retrieve_CCDBObject_asJSON (ccdbreader , path , timestamp , objtype_external = None ):
94102 """
95103 Retrieves a CCDB object as a JSON/dictionary.
96104 No need to know the type of the object a-priori.
@@ -100,6 +108,11 @@ def retrieve_CCDBObject_asJSON(ccdbreader, path, timestamp):
100108 print (f"WARNING: Could not get header for path ${ path } and timestamp { timestamp } " )
101109 return None
102110 objtype = header ["ObjectType" ]
111+ if objtype == None :
112+ objtype = objtype_external
113+ if objtype == None :
114+ return None
115+
103116 print (objtype )
104117 ts , obj = ccdbreader .fetch (path , objtype , timestamp )
105118 print (obj )
@@ -148,8 +161,18 @@ def retrieve_sor_eor_fromGRPECS(ccdbreader, run_number):
148161 # check that this object is really the one we wanted based on run-number
149162 assert (int (grp ["mRun" ]) == int (run_number ))
150163
151- print ("SOR GRP (internal) is " , grp ["mTimeStart" ], " EOR is " , grp ["mTimeEnd" ])
152- return {"SOR" : int (grp ["mTimeStart" ]), "EOR" : int (grp ["mTimeEnd" ])}
164+ SOR = int (grp ["mTimeStart" ]) # in milliseconds
165+ EOR = int (grp ["mTimeEnd" ])
166+ # fetch orbit reset to calculate orbitFirst
167+ ts , oreset = ccdbreader .fetch ("CTP/Calib/OrbitReset" , "vector<Long64_t>" , timestamp = SOR )
168+ print ("OrbitReset:" , int (oreset [0 ]))
169+ print ("RunStart:" , SOR )
170+
171+ orbitFirst = int ((1000 * SOR - oreset [0 ])// LHCOrbitMUS ) # calc done in microseconds
172+ print ("OrbitFirst" , orbitFirst )
173+
174+ # orbitReset.get(run_number)
175+ return {"SOR" : SOR , "EOR" : EOR , "FirstOrbit" : orbitFirst }
153176
154177def retrieve_GRP (ccdbreader , timestamp ):
155178 """
@@ -174,17 +197,10 @@ def determine_timestamp(sor, eor, splitinfo, cycle, ntf):
174197 thisjobID = splitinfo [0 ]
175198 print (f"Start-of-run : { sor } " )
176199 print (f"End-of-run : { eor } " )
177- time_length_inmus = 1000. * (eor - sor ) # time length in micro seconds
200+ time_length_inmus = 1000 * (eor - sor ) # time length in micro seconds
178201 timestamp_delta = time_length_inmus / totaljobs
179202 HBF_per_timeframe = 256 # 256 orbits per timeframe --> should be taken from GRP or common constant in all O2DPG
180203
181- # this should be taken from the C++ code (via PyROOT and library access to these constants)
182- LHCMaxBunches = 3564 ; # max N bunches
183- LHCRFFreq = 400.789e6 ; # LHC RF frequency in Hz
184- LHCBunchSpacingNS = 10 * 1.e9 / LHCRFFreq ; # bunch spacing in ns (10 RFbuckets)
185- LHCOrbitNS = LHCMaxBunches * LHCBunchSpacingNS ; # orbit duration in ns
186- LHCOrbitMUS = LHCOrbitNS * 1e-3 ; # orbit duration in \mus
187-
188204 ntimeframes = time_length_inmus / (HBF_per_timeframe * LHCOrbitMUS )
189205 norbits = time_length_inmus / LHCOrbitMUS
190206 print (f"This run has space for { ntimeframes } timeframes" )
@@ -237,7 +253,7 @@ def main():
237253
238254 # we finally pass forward to the unanchored MC workflow creation
239255 # TODO: this needs to be done in a pythonic way clearly
240- forwardargs = " " .join ([ a for a in args .forward if a != '--' ]) + " -tf " + str (args .tf ) + " --timestamp " + str (timestamp ) + " --production-offset " + str (prod_offset ) + " -run " + str (args .run_number ) + " -field ccdb -bcPatternFile ccdb"
256+ forwardargs = " " .join ([ a for a in args .forward if a != '--' ]) + " -tf " + str (args .tf ) + " --timestamp " + str (timestamp ) + " --production-offset " + str (prod_offset ) + " -run " + str (args .run_number ) + " --run-anchored --first-orbit " + str ( sor_eor [ "FirstOrbit" ]) + " - field ccdb -bcPatternFile ccdb"
241257 cmd = "${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py " + forwardargs
242258 print ("Creating time-anchored workflow..." )
243259 os .system (cmd )
0 commit comments