Belle II Software  release-06-02-00
checkInterimFEData.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ---------------------------------------------------------------------------------------
13 # Prints a summary of raw data given in Interim FE format v2.1
14 # usage: basf2 checkInterimFEData.py -i <file_name.sroot> [-n <num_of_events_to_process>]
15 # ---------------------------------------------------------------------------------------
16 
17 import basf2 as b2
18 from ROOT import Belle2
19 
20 
21 class InspectRawTOP(b2.Module):
22  ''' Print summary of raw data given in Interim FE format '''
23 
24  def swap32(self, x):
25  '''' Swap bytes '''
26 
27  return (((x << 24) & 0xFF000000) |
28  ((x << 8) & 0x00FF0000) |
29  ((x >> 8) & 0x0000FF00) |
30  ((x >> 24) & 0x000000FF))
31 
32  def event(self):
33  ''' Event processor '''
34 
35  rawTOPs = Belle2.PyStoreArray('RawTOPs')
36  if rawTOPs.getEntries() == 0:
37  print('RawTOP is empty - maybe component ID was not set properly at DAQ')
38  indx = 0
39  for raw in rawTOPs:
40  expno = raw.GetExpNo(0)
41  runno = raw.GetRunNo(0)
42  subno = raw.GetSubRunNo(0)
43  eveno = raw.GetEveNo(0)
44  copper = raw.GetNodeID(0) & 0x00FFFFFF
45  print('RawTOP[' + str(indx) + ']:',
46  'COPPER=' + str(copper),
47  'EXP=' + str(expno),
48  'RUN=' + str(runno),
49  'SUBRUN=' + str(subno),
50  'EVENT=' + str(eveno))
51  indx = indx + 1
52  for finesse in range(4):
53  size = raw.GetDetectorNwords(0, finesse)
54  if size == 0:
55  print(' HLSB', str(finesse),
56  ': size =', str(size), 'words')
57  continue
58  data = raw.GetDetectorBuffer(0, finesse)
59  scrod = self.swap32swap32(data[0]) & 0x0FFF
60  numFE = 0
61  numWF = 0
62  numPoz = 0
63  numNeg = 0
64  for i in range(size):
65  word = self.swap32swap32(data[i])
66  k = 0
67  if word == 0xaaaa0100:
68  numFE = numFE + 1
69  k = i + 4
70  elif word == 0xaaaa0103:
71  numFE = numFE + 1
72  numWF = numWF + 1
73  k = i + 4
74  if k > 0 and k < size - 6:
75  if self.swap32swap32(data[k]) != 0xd8f1ffff:
76  numPoz = numPoz + 1
77  if self.swap32swap32(data[k + 6]) != 0x270fffff:
78  numNeg = numNeg + 1
79  print(' HLSB', str(finesse),
80  ': size =', str(size), 'words,',
81  'SCROD', str(scrod) + ',',
82  'FE headers=' + str(numFE),
83  'signalsPoz=' + str(numPoz),
84  'signalsNeg=' + str(numNeg),
85  'Waveforms=' + str(numWF))
86  print()
87 
88 
89 # Create path
90 main = b2.create_path()
91 
92 # input
93 roinput = b2.register_module('SeqRootInput')
94 # roinput = register_module('RootInput')
95 main.add_module(roinput)
96 
97 # conversion from RawCOPPER or RawDataBlock to RawDetector objects
98 converter = b2.register_module('Convert2RawDet')
99 main.add_module(converter)
100 
101 # event info printer
102 main.add_module('EventInfoPrinter')
103 
104 # summary print-out
105 main.add_module(InspectRawTOP())
106 
107 # Process events
108 b2.process(main)
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:56