14 from ROOT
import Belle2
18 from bitstring
import BitArray
33 hslb = ((
'11000001',
'b'),
38 integrity_check =
False
40 [steering, srootFile] = sys.argv[:2]
41 if len(sys.argv) >= 3:
42 pickleSigFile = sys.argv[2]
43 isPickleFile = pickleSigFile[pickleSigFile.rfind(
'.'):] ==
'.p'
48 pickleIt = len(sys.argv) == 2
or isPickleFile
51 def finesse(x):
return ord(x) - ord(
'a')
54 def copper(x):
return int(x, 16)
57 hslb = [(copper(ele[0]), finesse(ele[1]))
for ele
in hslb]
61 return BitArray([]).join([BitArray(uint=i, length=32)
for i
in ary])
71 Example module to drop into ipython and create some objects to look at.
72 If you just want to start IPython and create PyStoreArray etc.
73 interactively in your own steering file, the 'Interactive' module
79 reimplement Module::event()
83 frombuffer = np.frombuffer
84 GetNodeID = Belle2.RawTRG.GetNodeID
85 GetDetectorNwords = Belle2.RawTRG.GetDetectorNwords
86 GetDetectorBuffer = Belle2.RawTRG.GetDetectorBuffer
94 print(len(trgary),
'copper(s)')
96 for entry
in range(evt.GetNumEntries()):
97 print(
'{:0x}'.format(GetNodeID(evt, entry)))
100 if (GetNodeID(evt, entry), bid)
in hslb:
101 count = GetDetectorNwords(evt, entry, bid)
102 print(bid,
"exist, ", count,
"words.")
107 for entry
in range(evt.GetNumEntries()):
111 if (GetNodeID(evt, entry), bid)
not in hslb:
113 count = GetDetectorNwords(evt, entry, bid)
117 bf = GetDetectorBuffer(evt, entry, bid)
118 ary = frombuffer(bf, np.uintc, count)
125 dataList.append(join(ary))
127 event = evtmeta.getEvent()
128 run = evtmeta.getRun()
129 subrun = evtmeta.getSubrun()
130 meta.append((event, run, subrun))
131 data.append(dataList)
136 b2.set_log_level(b2.LogLevel.INFO)
139 main = b2.create_path()
142 if srootFile[-5:] ==
'sroot':
143 root_input = b2.register_module(
'SeqRootInput')
145 root_input = b2.register_module(
'RootInput')
146 root_input.param(
'inputFileName', srootFile)
148 prog = b2.register_module(
'Progress')
151 main.add_module(root_input)
152 main.add_module(prog)
155 main.add_module(readout)
157 emptypath = b2.create_path()
158 readout.if_false(emptypath)
163 vcdFile = sys.argv[3]
if len(sys.argv) >= 4
else re.sub(
r'.+/',
'', re.sub(
r'sroot',
'vcd', srootFile))
164 with open(pickleSigFile)
as fin:
165 evtsize = [int(width)
for width
in fin.readline().split()]
166 b2.B2INFO(
'Interpreting B2L data format with dimension ' + str(evtsize))
167 atlas = b2vcd_48.makeAtlas(fin.read(), evtsize)
173 pica = pickleSigFile
if isPickleFile
else re.sub(
r'.+/',
'ana/', re.sub(
r'sroot',
'p', srootFile))
174 wfp = open(pica,
'wb')
175 pickle.dump(data, wfp, protocol=2)
176 pickle.dump(meta, wfp, protocol=2)
182 b2.B2INFO(
'Output pickle file ' + pica +
' saved.')
184 b2vcd_48.writeVCD(meta, data, atlas, vcdFile, evtsize)
a (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.