-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrootdata.py
More file actions
95 lines (79 loc) · 3.26 KB
/
Copy pathrootdata.py
File metadata and controls
95 lines (79 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
import ROOT
from array import array
class DataFile:
def __init__(self, rootFile, suffix):
self.__rootFile = rootFile
self.__dataTree = ROOT.TTree("data" + suffix, "Data " + suffix)
self.__step1 = array('f', [0])
self.__dataTree.Branch("step1", self.__step1, "step1/F")
self.__step2 = array('f', [0])
self.__dataTree.Branch("step2", self.__step2, "step2/F")
self.__frame = array('L', [0])
self.__dataTree.Branch("frame", self.__frame, "frame/L")
self.__asic = array('i', [0])
self.__dataTree.Branch("asic", self.__asic, "asic/I")
self.__channel = array('i', [0])
self.__dataTree.Branch("channel", self.__channel, "channel/I")
self.__tac = array('i', [0])
self.__dataTree.Branch("tac", self.__tac, "tac/I")
self.__tcoarse = array('i', [0])
self.__dataTree.Branch("tcoarse", self.__tcoarse, "tcoarse/I")
self.__ecoarse = array('i', [0])
self.__dataTree.Branch("ecoarse", self.__ecoarse, "ecoarse/I")
self.__tfine = array('i', [0])
self.__dataTree.Branch("tfine", self.__tfine, "tfine/I")
self.__efine = array('i', [0])
self.__dataTree.Branch("efine", self.__efine, "efine/I")
self.__tacIdleTime = array('l', [0])
self.__dataTree.Branch("tacIdleTime", self.__tacIdleTime, "tacIdleTime/L")
self.__channelIdleTime = array('l', [0])
self.__dataTree.Branch("channelIdleTime", self.__channelIdleTime, "channelIdleTime/L")
self.__indexTree = ROOT.TTree("index3" + suffix, "Index v3 " + suffix)
self.__indexTree.Branch("step1", self.__step1, "step1/F")
self.__indexTree.Branch("step2", self.__step2, "step2/F")
self.__stepBegin = array('i', [0])
self.__indexTree.Branch("stepBegin", self.__stepBegin, "stepBegin/I")
self.__stepEnd = array('i', [0])
self.__indexTree.Branch("stepEnd", self.__stepEnd, "stepEnd/I")
self.__firstEvent = True
return None
def addEvent(self, step1, step2, frame, asic, channel, tac, tcoarse, ecoarse, tfine, efine, channelIdleTime, tacIdleTime):
if self.__firstEvent:
self.__firstEvent = False
self.__step1[0] = step1
self.__step2[0] = step2
self.__stepBegin[0] = 0
self.__stepEnd[0] = 0
a1 = array('f', [step1])
a2 = array('f', [step2])
if self.__step1 != a1 or self.__step2 != a2:
#print "Adding old step ", self.__step1[0], self.__step2[0], self.__stepBegin[0], self.__stepEnd[0]
self.__indexTree.Fill()
self.__stepBegin[0] = self.__stepEnd[0]
self.__step1[0] = step1
self.__step2[0] = step2
self.__frame[0] = frame
self.__asic[0] = asic
self.__channel[0] = channel
self.__tac[0] = tac
self.__tcoarse[0] = tcoarse
self.__ecoarse[0] = ecoarse
self.__tfine[0] = tfine
self.__efine[0] = efine
self.__channelIdleTime[0] = channelIdleTime
self.__tacIdleTime[0] = tacIdleTime
self.__dataTree.Fill()
self.__stepEnd[0] = self.__stepEnd[0] + 1
return None
def write(self):
self.__rootFile.Write()
return None
def close(self):
self.__indexTree.Fill()
return None
if __name__ == '__main__':
d = DataFile("/tmp/z2.root");
d.addEvent(0, 0, 2, 3, 3, 3, 4, 4, 4, 5, 5)
d.write()
d.close()