ATLAS Offline Software
replaceMUCTPI.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 Module for creating the MUCTPi fragment normally send through the RoIB
6 using the information readout from the ROS.
7 It can be used either standalone or as a "-Z" plugin to athenaMT/PT.
8 
9 Note that a bunch of information is hardcoded and could change if
10 the data format of the CTP/MUCTPI/L1Calo ROIB fragments change.
11 """
12 
13 import os
14 import sys
15 
16 import eformat
17 import libpyevent_storage as EventStorage
18 
19 def modify(event):
20  """Fills in the MUCTPi ROB)."""
21 
22  map=[[eformat.helper.SubDetector.TDAQ_MUON_CTP_INTERFACE,0,1]]
23 
24  DaqRobs=[None]*len(map)
25 
26  for rob in event:
27  cnt=0
28  for match in map:
29  if rob.source_id()==eformat.helper.SourceIdentifier(match[0],match[1]):
30  DaqRobs[cnt]=rob
31  cnt+=1
32 
33 
34  #work around corrupted events:
35  #new_event=eformat.write.FullEventFragment(event)
36  new_event=eformat.write.FullEventFragment()
37  new_event.copy_header(event)
38  for rob in event:
39  keep=True
40  for match in map:
41  if rob.source_id()==eformat.helper.SourceIdentifier(match[0],match[2]):
42  keep=False
43  break
44  if keep:
45  new_event.append_unchecked(rob)
46  for idx in range(len(map)):
47  if DaqRobs[idx]:
48  rob=eformat.write.ROBFragment(DaqRobs[idx])
49  rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
50  if map[idx][0]==eformat.helper.SubDetector.TDAQ_CTP:
51  version=rob.rod_minor_version()&0x1f
52  if version:
53  ctpSkip=(rob.rod_minor_version()>>8)&0x3f
54  else:
55  ctpSkip=(rob.rod_detev_type()>>16)&0x3f
56  data=[DaqRobs[idx].rod_data()[0],DaqRobs[idx].rod_data()[1]]
57  for ii in range(30):
58  data+=[DaqRobs[idx].rod_data()[2+ctpSkip*30+ii]]
59  rob.rod_data(data)
60  if map[idx][0]==eformat.helper.SubDetector.TDAQ_MUON_CTP_INTERFACE:
61  data=[]
62  if len(DaqRobs[idx].rod_data()):
63  muctpBC=(DaqRobs[idx].rod_data()[0]>>18)&7
64  for word in DaqRobs[idx].rod_data()[1:]:
65  if (word>>14)&7==muctpBC and (word>>26)&1:
66  data+=[(word&0x3fff)|(((word>>17)&0x1ff)<<14)]
67  if len(data)==0:
68  rob=eformat.write.ROBFragment()
69  rob.copy_header(DaqRobs[idx])
70  rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
71  else:
72  rob.rod_data(data)
73  new_event.append(rob)
74  else:
75  rob=eformat.write.ROBFragment()
76  rob.source_id(eformat.helper.SourceIdentifier(map[idx][0],map[idx][2]))
77  new_event.append(rob)
78  return new_event.readonly()
79 
80 
81 def ReplaceMUCTPI(input_file,output_file):
82  input = eformat.istream([input_file])
83  dr=EventStorage.pickDataReader(input_file)
84  output = eformat.ostream(core_name="subset",
85  run_number=dr.runNumber(),
86  trigger_type=dr.triggerType(),
87  detector_mask=dr.detectorMask(),
88  beam_type=dr.beamType(),
89  beam_energy=dr.beamEnergy())
90  for event in input:
91  output.write(modify(event))
92  tmp_file_name = output.last_filename()
93  del output
94  os.rename(tmp_file_name,output_file)
95 
96 
97 
98 if __name__ == "__main__":
99  if len(sys.argv)!=3:
100  print('usage: %s <infile> <outfile>' % sys.argv[0])
101  sys.exit(1)
102  input_file = sys.argv[1]
103  output_file = sys.argv[2]
104 
105  ReplaceMUCTPI(input_file,output_file)
python.replaceMUCTPI.ReplaceMUCTPI
def ReplaceMUCTPI(input_file, output_file)
Definition: replaceMUCTPI.py:81
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.replaceMUCTPI.modify
def modify(event)
Definition: replaceMUCTPI.py:19
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28