ATLAS Offline Software
slimHLTBSFile.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 slimHLTBSFile.py
6 
7 Module for removing raw and time/quality information from LAr data,
8 raw digits from Tile data, preprocessor information from L1Calo data and
9 pre-existing L2 and EF results. None of this information is currently used by
10 the HLT and removing it reduces file size by up to a factor 4.
11 
12 Note that this requires datafiles to have energy readings
13 """
14 
15 import os
16 import sys
17 
18 import eformat
19 import libpyevent_storage as EventStorage
20 
21 def hi16(word):
22  return (word&0xffff0000)>>16
23 
24 def lo16(word):
25  return word&0xffff
26 
27 def reducedLARFEB(data):
28  sizeenergy=lo16(data[3])
29  offenergy=hi16(data[3])
30  nsamples=lo16(data[7])
31  radd=(nsamples+1)//2
32  total=18-8+83+radd+3
33  if total>data[0] or sizeenergy==0:
34  return [data[ii] for ii in range(data[0])]
35  newdata=[data[ii] for ii in range(total-3)+range(data[0]-3,data[0])] #one should actually recalculate checksum
36  newdata[0]=total
37  newdata[3]=(18<<16)+83+radd
38  newdata[4]=0 #no quality
39  newdata[5]=0 #no samples
40  for ii in range(offenergy,offenergy+9):
41  newdata[ii]=0 #zero masks
42  return newdata
43 
44 def reducedTILE(data):
45  idx=0
46  newdata=[]
47  while idx<len(data):
48  size=data[idx+1]
49  type=data[idx+2]>>16&0xff
50  if type>1:
51  newdata+=[data[ii] for ii in range(idx,idx+size)]
52  idx+=size
53  return newdata
54 
55 def modify(event):
56  new_event=eformat.write.FullEventFragment()
57  new_event.copy_header(event)
58  for rob in event:
59  newrob=eformat.write.ROBFragment(rob)
60  if rob.source_id().human_detector()=='TDAQ_CALO_PREPROC':
61  continue
62  if rob.source_id().human_detector()=='TDAQ_LVL2':
63  continue
64  if rob.source_id().human_detector()=='TDAQ_EVENT_FILTER':
65  continue
66  if rob.source_id().human_group()=="TILECAL":
67  data = rob.rod_data()
68  newdata=reducedTILE(data)
69  newrob.rod_data(newdata)
70 
71  if rob.source_id().human_group()=="LAR" and rob.rod_minor_version()==11:
72  #should check that it really is physics format
73  data = rob.rod_data()
74  newdata=reducedLARFEB(data)
75  if len(data)>data[0]:
76  newdata+=[data[data[0]+ii] for ii in range(7)] #middle "ROD" header
77  data=data[data[0]+7:]
78  newdata+=reducedLARFEB(data)
79  newrob.rod_data(newdata)
80  new_event.append(newrob)
81  return new_event.readonly()
82 
83 if __name__ == "__main__":
84  if len(sys.argv)!=3:
85  print('usage: %s <infile> <outfile>' % sys.argv[0])
86  sys.exit(1)
87  input_file = sys.argv[1]
88  output_file = sys.argv[2]
89 
90  input = eformat.istream([input_file])
91  dr=EventStorage.pickDataReader(input_file)
92  output = eformat.ostream(core_name="subset",
93  run_number=dr.runNumber(),
94  trigger_type=dr.triggerType(),
95  detector_mask=dr.detectorMask(),
96  beam_type=dr.beamType(),
97  beam_energy=dr.beamEnergy())
98  for event in input:
99  output.write(modify(event))
100  tmp_file_name = output.last_filename()
101  del output
102  os.rename(tmp_file_name,output_file)
python.slimHLTBSFile.reducedLARFEB
def reducedLARFEB(data)
Definition: slimHLTBSFile.py:27
python.slimHLTBSFile.hi16
def hi16(word)
Definition: slimHLTBSFile.py:21
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.slimHLTBSFile.reducedTILE
def reducedTILE(data)
Definition: slimHLTBSFile.py:44
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
python.slimHLTBSFile.lo16
def lo16(word)
Definition: slimHLTBSFile.py:24
python.slimHLTBSFile.modify
def modify(event)
Definition: slimHLTBSFile.py:55