ATLAS Offline Software
Classes | Functions | Variables
python.trigbs_modifyEvent Namespace Reference

Classes

class  Config
 
class  Store
 

Functions

def modify (event)
 
def main ()
 

Variables

 log
 

Function Documentation

◆ main()

def python.trigbs_modifyEvent.main ( )

Definition at line 66 of file trigbs_modifyEvent.py.

66 def main():
67  import argparse
68 
69  parser = argparse.ArgumentParser(description=__doc__)
70 
71  parser.add_argument('file', metavar='FILE', nargs=1, help='input file')
72  parser.add_argument('-o', '--output', type=str, help='output base file name')
73  parser.add_argument('-n', '--events', type=int, default=-1, help='number of events to process')
74  parser.add_argument('-r', '--runNumber', type=int, help='set run number')
75  parser.add_argument('-l', '--eventsPerLB', type=int, help='increment lumiblock number in steps [%(default)s]')
76  parser.add_argument('--firstLB', type=int, default=1, help='first lumiblock number [%(default)s]')
77  parser.add_argument('--incLB', type=int, default=1, help='increment steps for lumiblock number [%(default)s]')
78  parser.add_argument('-t', '--timestamp', type=int, help='set timestamp in seconds [%(default)s]')
79  parser.add_argument('--removeRobs', metavar='PATTERN', type=str, help='regex for removing specific ROB IDs')
80 
81  args = parser.parse_args()
82 
83  Config.firstLB = Store.currentLB = args.firstLB
84  Config.incLB = args.incLB
85  Config.eventsPerLB = args.eventsPerLB
86  Config.runNumber = args.runNumber
87  Config.bc_sec = args.timestamp
88 
89  log.info('Opening file %s', args.file[0])
90  dr = eformat.EventStorage.pickDataReader(args.file[0])
91  ostr = eformat.ostream(core_name = args.output or dr.fileNameCore(),
92  run_number = Config.runNumber or dr.runNumber(),
93  trigger_type = dr.triggerType(),
94  detector_mask = dr.detectorMask(),
95  beam_type = dr.beamType(),
96  beam_energy = dr.beamEnergy())
97 
98  bsfile = eformat.istream([args.file[0]])
99  i = 0
100  for event in bsfile:
101  i +=1
102  if args.events>0 and i>args.events:
103  break
104  ro_event = modify(event)
105  if args.removeRobs:
106  rw_event = eformat.write.FullEventFragment(ro_event, re.compile(args.removeRobs))
107  else:
108  rw_event = eformat.write.FullEventFragment(ro_event)
109  ostr.write(rw_event)
110 
111  return
112 

◆ modify()

def python.trigbs_modifyEvent.modify (   event)

Definition at line 28 of file trigbs_modifyEvent.py.

28 def modify(event):
29  from TrigByteStreamTools import CTPfragment
30 
31  if Store.eventCounter==0:
32  Store.currentLB = Config.firstLB
33 
34  newevt = event if isinstance(event,eformat.write.FullEventFragment) else eformat.write.FullEventFragment(event)
35  Store.eventCounter += 1
36 
37  if Config.eventsPerLB is not None:
38  Store.currentLB = Config.firstLB + Config.incLB*((Store.eventCounter-1) // Config.eventsPerLB)
39 
40  # Find CTP ROB
41  ctp_robs = [rob for rob in newevt.children()
42  if rob.source_id().subdetector_id() == helper.SubDetector.TDAQ_CTP]
43 
44  # Modify LB in CTP fragmnet
45  for ctp_rob in ctp_robs:
46  CTPfragment.setLumiBlock(ctp_rob, Store.currentLB)
47 
48  # Set LB in event header
49  newevt.lumi_block(Store.currentLB)
50 
51  # Set run number
52  if Config.runNumber is not None:
53  newevt.run_no(Config.runNumber)
54 
55  # Modify event time stamp
56  if Config.bc_sec is not None:
57  newevt.bc_time_seconds(Config.bc_sec)
58  newevt.bc_time_nanoseconds(0)
59 
60  log.info("Event %4d, L1ID %10d assigned LB = %d, run = %d, bc_time_sec = %d",
61  Store.eventCounter, newevt.lvl1_id(), newevt.lumi_block(), newevt.run_no(), newevt.bc_time_seconds())
62 
63  return newevt if isinstance(event,eformat.write.FullEventFragment) else newevt.readonly()
64 
65 

Variable Documentation

◆ log

python.trigbs_modifyEvent.log

Definition at line 26 of file trigbs_modifyEvent.py.

python.trigbs_modifyEvent.main
def main()
Definition: trigbs_modifyEvent.py:66
python.trigbs_modifyEvent.modify
def modify(event)
Definition: trigbs_modifyEvent.py:28