Skip to content

Commit 5f382d7

Browse files
committed
Ability to treat run-holes in anchored MC
1 parent ac24642 commit 5f382d7

File tree

2 files changed

+69
-6
lines changed

2 files changed

+69
-6
lines changed

MC/bin/o2dpg_sim_workflow_anchored.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import re
1414
import json
1515
import math
16+
import pandas as pd
1617

1718
# Creates a time anchored MC workflow; positioned within a given run-number (as function of production size etc)
1819

@@ -295,12 +296,52 @@ def determine_timestamp(sor, eor, splitinfo, cycle, ntf, HBF_per_timeframe = 256
295296
production_offset = int(thisjobID * maxcycles) + cycle
296297
# add the time difference of this slot to start-of-run to get the final timestamp
297298
timestamp_of_production = sor + production_offset * ntf * HBF_per_timeframe * LHCOrbitMUS / 1000
298-
# this is a closure test. If we had prefect floating point precision everywhere, it wouldn't fail.
299+
# this is a closure test. If we had perfect floating point precision everywhere, it wouldn't fail.
299300
# But since we don't have that and there are some int casts as well, better check again.
300301
assert (timestamp_of_production >= sor)
301302
assert (timestamp_of_production <= eor)
302303
return int(timestamp_of_production), production_offset
303304

305+
306+
def exclude_timestamp(ts, orbit, run, filename):
307+
"""
308+
Checks if timestamp ts (or orbit) falls within a bad data period.
309+
Returns true if this timestamp should be excluded; false otherwise
310+
311+
ts is supposed to be in milliseconds
312+
orbit is some orbit after the orbitreset of the run
313+
"""
314+
if len(filename) == 0:
315+
return False
316+
317+
if not os.path.isfile(filename):
318+
return False
319+
320+
# read txt file into a pandas dataframe ---> if this fails catch exception and return
321+
df = pd.read_csv(filename, header=None, names=["Run", "From", "To", "Message"])
322+
323+
# extract data for this run number
324+
filtered = df[df['Run'] == run]
325+
326+
# now extract from and to lists
327+
exclude_list = list(zip(filtered["From"].to_list() , filtered["To"].to_list()))
328+
329+
if len(exclude_list) == 0:
330+
return False
331+
332+
data_is_in_orbits = exclude_list[0][0] < 1514761200000
333+
334+
if data_is_in_orbits:
335+
for orbitspan in exclude_list:
336+
if orbitspan[0] <= orbit and orbit <= orbitspan[1]:
337+
return True
338+
else:
339+
for timespan in exclude_list:
340+
if timespan[0] <= ts and ts <= timespan[1]:
341+
return True
342+
343+
return False
344+
304345
def main():
305346
parser = argparse.ArgumentParser(description='Creates an O2DPG simulation workflow, anchored to a given LHC run. The workflows are time anchored at regular positions within a run as a function of production size, split-id and cycle.')
306347

@@ -312,6 +353,7 @@ def main():
312353
parser.add_argument("-tf", type=int, help="number of timeframes per job", default=1)
313354
parser.add_argument("--ccdb-IRate", type=bool, help="whether to try fetching IRate from CCDB/CTP", default=True)
314355
parser.add_argument("--trig-eff", type=float, dest="trig_eff", help="Trigger eff needed for IR", default=-1.0)
356+
parser.add_argument("--run-time-span-file", type=str, dest="run_span_file", help="Run-time-span-file for exclusions of timestamps (bad data periods etc.)", default="")
315357
parser.add_argument('forward', nargs=argparse.REMAINDER) # forward args passed to actual workflow creation
316358
args = parser.parse_args()
317359
print (args)
@@ -329,6 +371,12 @@ def main():
329371

330372
# determine timestamp, and production offset for the final MC job to run
331373
timestamp, prod_offset = determine_timestamp(run_start, run_end, [args.split_id - 1, args.prod_split], args.cycle, args.tf, GLOparams["OrbitsPerTF"])
374+
# determine orbit corresponding to timestamp
375+
orbit = GLOparams["FirstOrbit"] + (timestamp - GLOparams["SOR"]) / LHCOrbitMUS
376+
377+
# check if timestamp is to be excluded
378+
# what to do in case of
379+
job_is_exluded = exclude_timestamp(timestamp, orbit, args.run_number, args.run_span_file)
332380

333381
# this is anchored to
334382
print ("Determined start-of-run to be: ", run_start)
@@ -402,8 +450,12 @@ def main():
402450
+ str(GLOparams["FirstOrbit"]) + " -field ccdb -bcPatternFile ccdb" + " --orbitsPerTF " + str(GLOparams["OrbitsPerTF"]) + " -col " + str(ColSystem) + " -eCM " + str(eCM) + ' --readoutDets ' + GLOparams['detList']
403451
print ("forward args ", forwardargs)
404452
cmd = "${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py " + forwardargs
405-
print ("Creating time-anchored workflow...")
406-
os.system(cmd)
453+
454+
if job_is_exluded:
455+
print ("TIMESTAMP IS EXCLUDED IN RUN")
456+
else:
457+
print ("Creating time-anchored workflow...")
458+
os.system(cmd)
407459

408460
if __name__ == "__main__":
409461
sys.exit(main())

MC/run/ANCHOR/anchorMC.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ MODULES="--skipModules ZDC"
210210
ALICEO2_CCDB_LOCALCACHE=${ALICEO2_CCDB_LOCALCACHE:-$(pwd)/ccdb}
211211

212212
# these arguments will be digested by o2dpg_sim_workflow_anchored.py
213-
baseargs="-tf ${NTIMEFRAMES} --split-id ${SPLITID} --prod-split ${PRODSPLIT} --cycle ${CYCLE} --run-number ${ALIEN_JDL_LPMRUNNUMBER}"
213+
baseargs="-tf ${NTIMEFRAMES} --split-id ${SPLITID} --prod-split ${PRODSPLIT} --cycle ${CYCLE} --run-number ${ALIEN_JDL_LPMRUNNUMBER} \
214+
${ALIEN_JDL_RUN_TIME_SPAN_FILE:+--run-time-span-file ${ALIEN_JDL_RUN_TIME_SPAN_FILE}}"
214215

215216
# these arguments will be passed as well but only evetually be digested by o2dpg_sim_workflow.py which is called from o2dpg_sim_workflow_anchored.py
216217
remainingargs="-seed ${SEED} -ns ${NSIGEVENTS} --include-local-qc --pregenCollContext"
@@ -223,17 +224,27 @@ remainingargs="${ALIEN_JDL_ANCHOR_SIM_OPTIONS} ${remainingargs} --anchor-config
223224
echo_info "baseargs passed to o2dpg_sim_workflow_anchored.py: ${baseargs}"
224225
echo_info "remainingargs forwarded to o2dpg_sim_workflow.py: ${remainingargs}"
225226

227+
anchoringLogFile=timestampsampling_${ALIEN_JDL_LPMRUNNUMBER}.log
226228
# query CCDB has changed, w/o "_"
227-
${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow_anchored.py ${baseargs} -- ${remainingargs} &> timestampsampling_${ALIEN_JDL_LPMRUNNUMBER}.log
229+
${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow_anchored.py ${baseargs} -- ${remainingargs} &> ${anchoringLogFile}
228230
WF_RC="${?}"
229231
if [ "${WF_RC}" != "0" ] ; then
230232
echo_error "Problem during anchor timestamp sampling and workflow creation. Exiting."
231233
exit ${WF_RC}
232234
fi
233235

234-
TIMESTAMP=`grep "Determined timestamp to be" timestampsampling_${ALIEN_JDL_LPMRUNNUMBER}.log | awk '//{print $6}'`
236+
TIMESTAMP=`grep "Determined timestamp to be" ${anchoringLogFile} | awk '//{print $6}'`
235237
echo_info "TIMESTAMP IS ${TIMESTAMP}"
236238

239+
# check if this job is exluded because it falls inside a bad data-taking period
240+
ISEXCLUDED=$(grep "TIMESTAMP IS EXCLUDED IN RUN" ${anchoringLogFile})
241+
if [ "${ISEXCLUDED}" ]; then
242+
# we can quit here; there is nothing to do
243+
# (apart from maybe creating a fake empty AO2D.root file or the like)
244+
echo "Timestamp is excluded from run. Nothing to do here"
245+
exit 0
246+
fi
247+
237248
# -- Create aligned geometry using ITS ideal alignment to avoid overlaps in geant
238249
CCDBOBJECTS_IDEAL_MC="ITS/Calib/Align"
239250
TIMESTAMP_IDEAL_MC=1

0 commit comments

Comments
 (0)