13from ROOT
import Belle2
17from bitstring
import BitArray
32hslb = ((
'11000001',
'b'),
37integrity_check =
False
39[steering, srootFile] = sys.argv[:2]
41 pickleSigFile = sys.argv[2]
42 isPickleFile = pickleSigFile[pickleSigFile.rfind(
'.'):] ==
'.p'
47pickleIt = len(sys.argv) == 2
or isPickleFile
50def finesse(x):
return ord(x) - ord(
'a')
53def copper(x):
return int(x, 16)
56hslb = [(copper(ele[0]), finesse(ele[1]))
for ele
in hslb]
60 return BitArray([]).join([BitArray(uint=i, length=32)
for i
in ary])
70 Example module to drop into ipython and create some objects to look at.
71 If you just want to start IPython
and create PyStoreArray etc.
72 interactively
in your own steering file, the
'Interactive' module
78 reimplement Module::event()
82 frombuffer = np.frombuffer
83 GetNodeID = Belle2.RawTRG.GetNodeID
84 GetDetectorNwords = Belle2.RawTRG.GetDetectorNwords
85 GetDetectorBuffer = Belle2.RawTRG.GetDetectorBuffer
92 print(len(trgary),
'copper(s)')
94 for entry
in range(evt.GetNumEntries()):
95 print(f
'{GetNodeID(evt, entry):0x}')
97 if (GetNodeID(evt, entry), bid)
in hslb:
98 count = GetDetectorNwords(evt, entry, bid)
99 print(bid,
"exist, ", count,
"words.")
104 for entry
in range(evt.GetNumEntries()):
107 if (GetNodeID(evt, entry), bid)
not in hslb:
109 count = GetDetectorNwords(evt, entry, bid)
113 bf = GetDetectorBuffer(evt, entry, bid)
114 ary = frombuffer(bf, np.uintc, count)
121 dataList.append(join(ary))
123 event = evtmeta.getEvent()
124 run = evtmeta.getRun()
125 subrun = evtmeta.getSubrun()
126 meta.append((event, run, subrun))
127 data.append(dataList)
132b2.set_log_level(b2.LogLevel.INFO)
135main = b2.create_path()
138if srootFile[-5:] ==
'sroot':
139 root_input = b2.register_module(
'SeqRootInput')
141 root_input = b2.register_module(
'RootInput')
142root_input.param(
'inputFileName', srootFile)
144prog = b2.register_module(
'Progress')
147main.add_module(root_input)
151main.add_module(readout)
153emptypath = b2.create_path()
154readout.if_false(emptypath)
159 vcdFile = sys.argv[3]
if len(sys.argv) >= 4
else re.sub(
r'.+/',
'', re.sub(
r'sroot',
'vcd', srootFile))
160 with open(pickleSigFile)
as fin:
161 evtsize = [int(width)
for width
in fin.readline().split()]
162 b2.B2INFO(
'Interpreting B2L data format with dimension ' + str(evtsize))
163 atlas = b2vcd_48.makeAtlas(fin.read(), evtsize)
169 pica = pickleSigFile
if isPickleFile
else re.sub(
r'.+/',
'ana/', re.sub(
r'sroot',
'p', srootFile))
170 wfp = open(pica,
'wb')
171 pickle.dump(data, wfp, protocol=2)
172 pickle.dump(meta, wfp, protocol=2)
178 b2.B2INFO(
'Output pickle file ' + pica +
' saved.')
180 b2vcd_48.writeVCD(meta, data, atlas, vcdFile, evtsize)
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.