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
93 print(len(trgary),
'copper(s)')
95 for entry
in range(evt.GetNumEntries()):
96 print(
'{:0x}'.format(GetNodeID(evt, entry)))
98 if (GetNodeID(evt, entry), bid)
in hslb:
99 count = GetDetectorNwords(evt, entry, bid)
100 print(bid,
"exist, ", count,
"words.")
105 for entry
in range(evt.GetNumEntries()):
108 if (GetNodeID(evt, entry), bid)
not in hslb:
110 count = GetDetectorNwords(evt, entry, bid)
114 bf = GetDetectorBuffer(evt, entry, bid)
115 ary = frombuffer(bf, np.uintc, count)
122 dataList.append(join(ary))
124 event = evtmeta.getEvent()
125 run = evtmeta.getRun()
126 subrun = evtmeta.getSubrun()
127 meta.append((event, run, subrun))
128 data.append(dataList)
133 b2.set_log_level(b2.LogLevel.INFO)
136 main = b2.create_path()
139 if srootFile[-5:] ==
'sroot':
140 root_input = b2.register_module(
'SeqRootInput')
142 root_input = b2.register_module(
'RootInput')
143 root_input.param(
'inputFileName', srootFile)
145 prog = b2.register_module(
'Progress')
148 main.add_module(root_input)
149 main.add_module(prog)
152 main.add_module(readout)
154 emptypath = b2.create_path()
155 readout.if_false(emptypath)
160 vcdFile = sys.argv[3]
if len(sys.argv) >= 4
else re.sub(
r'.+/',
'', re.sub(
r'sroot',
'vcd', srootFile))
161 with open(pickleSigFile)
as fin:
162 evtsize = [int(width)
for width
in fin.readline().split()]
163 b2.B2INFO(
'Interpreting B2L data format with dimension ' + str(evtsize))
164 atlas = b2vcd_48.makeAtlas(fin.read(), evtsize)
170 pica = pickleSigFile
if isPickleFile
else re.sub(
r'.+/',
'ana/', re.sub(
r'sroot',
'p', srootFile))
171 wfp = open(pica,
'wb')
172 pickle.dump(data, wfp, protocol=2)
173 pickle.dump(meta, wfp, protocol=2)
179 b2.B2INFO(
'Output pickle file ' + pica +
' saved.')
181 b2vcd_48.writeVCD(meta, data, atlas, vcdFile, evtsize)
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.