ATLAS Offline Software
trigbs_createHLTBSTestFile.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
4 """
5 Prepare bytestream files for nightly and online tests
6 
7 Renumbers all event ids, runnumbers and lumiblocks to create test files.
8 The MUCTPi fragment normally sent through the RoIB is also recreated, though
9 that should only be necessary for 2009 data
10 
11 Note that a bunch of information is hardcoded and could change if
12 the data format of the CTP/MUCTPI/L1Calo ROIB fragments change.
13 """
14 
15 import os
16 import sys
17 
18 import eformat
19 import libpyevent_storage as EventStorage
20 
21 id=0
22 lumi=0
23 runno=0
24 runs=[]
25 def modify(event):
26  """Fills in the MUCTPi ROB)."""
27  global id
28  global runs
29  global runno
30  global lumi
31  id+=1
32 
33  map=[[eformat.helper.SubDetector.TDAQ_MUON_CTP_INTERFACE,0,1]]
34  DaqRobs=[None]*len(map)
35 
36  for rob in event:
37  cnt=0
38  for match in map:
39  if rob.source_id()==eformat.helper.SourceIdentifier(match[0],match[1]):
40  DaqRobs[cnt]=rob
41  cnt+=1
42 
43 
44  #work around corrupted events:
45  #new_event=eformat.write.FullEventFragment(event)
46  new_event=eformat.write.FullEventFragment()
47  new_event.copy_header(event)
48  if not event.run_no() in runs:
49  runs.append(event.run_no())
50  lumi+=1
51  new_event.run_no(runno) #fake it to avoid complaints and get latest conditions
52  new_event.lumi_block(lumi)
53  new_event.lvl1_id(id)
54  new_event.global_id(id)
55  for rob in event:
56  keep=True
57  for match in map:
58  if rob.source_id()==eformat.helper.SourceIdentifier(match[0],match[2]):
59  keep=False
60  break
61  if keep:
62  newrob=eformat.write.ROBFragment(rob)
63  newrob.rod_lvl1_id(id)
64  newrob.rod_run_no(runno)
65  newrob.checksum_type(0)
66  newrob.rod_lvl1_trigger_type(event.lvl1_trigger_type())
67  if rob.source_id()==eformat.helper.SourceIdentifier(eformat.helper.SubDetector.TDAQ_CTP,1):
68  newrob.rod_detev_type(1<<16|lumi)
69  new_event.append(newrob)
70  for idx in range(len(map)):
71  if DaqRobs[idx]:
72  rob=eformat.write.ROBFragment(DaqRobs[idx])
73  rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
74  rob.rod_lvl1_id(id)
75  rob.rod_run_no(runno)
76  rob.checksum_type(0)
77  rob.rod_lvl1_trigger_type(event.lvl1_trigger_type())
78  if map[idx][0]==eformat.helper.SubDetector.TDAQ_CTP:
79  version=rob.rod_minor_version()&0x1f
80  if version:
81  ctpSkip=(rob.rod_minor_version()>>8)&0x3f
82  else:
83  ctpSkip=(rob.rod_detev_type()>>16)&0x3f
84  data=[DaqRobs[idx].rod_data()[0],DaqRobs[idx].rod_data()[1]]
85  for ii in range(30):
86  data+=[DaqRobs[idx].rod_data()[2+ctpSkip*30+ii]]
87  rob.rod_data(data)
88  if map[idx][0]==eformat.helper.SubDetector.TDAQ_MUON_CTP_INTERFACE:
89  data=[]
90  muctpBC=(DaqRobs[idx].rod_data()[0]>>18)&7
91  for word in DaqRobs[idx].rod_data()[1:]:
92  if (word>>14)&7==muctpBC and (word>>26)&1:
93  data+=[(word&0x3fff)|(((word>>17)&0x1ff)<<14)]
94  if len(data)==0:
95  rob=eformat.write.ROBFragment()
96  rob.copy_header(DaqRobs[idx])
97  rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
98  else:
99  rob.rod_data(data)
100  new_event.append(rob)
101  else:
102  rob=eformat.write.ROBFragment()
103  rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
104  new_event.append(rob)
105  return new_event.readonly()
106 
107 if __name__ == "__main__":
108  if len(sys.argv)!=4:
109  print('usage: %s <infile> <outfile> <runno>' % sys.argv[0])
110  sys.exit(1)
111  global runno
112 
113  input_file = sys.argv[1]
114  output_file = sys.argv[2]
115  runno = int(sys.argv[3])
116 
117  input = eformat.istream([input_file])
118  dr=EventStorage.pickDataReader(input_file)
119  output = eformat.ostream(core_name="subset",
120  run_number=runno,
121  trigger_type=dr.triggerType(),
122  detector_mask=dr.detectorMask(),
123  beam_type=dr.beamType(),
124  beam_energy=dr.beamEnergy())
125  for event in input:
126  output.write(modify(event))
127  tmp_file_name = output.last_filename()
128  del output
129  os.rename(tmp_file_name,output_file)
trigbs_createHLTBSTestFile.modify
def modify(event)
Definition: trigbs_createHLTBSTestFile.py:25
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70