-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeSummedTurfRateTree.cxx
171 lines (144 loc) · 4.26 KB
/
makeSummedTurfRateTree.cxx
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <zlib.h>
#include <libgen.h>
#include "TTree.h"
#include "TFile.h"
#include "TSystem.h"
#include "TTreeIndex.h"
#include "SummedTurfRate.h"
#include "simpleStructs.h"
using namespace std;
void processTurfRate(int version);
void makeSummedTurfRateTree(char *inName, char *outName);
//Global Variable
SummedTurfRateStruct_t theSummedTurfRate;
SummedTurfRateStructVer40_t theSummedTurfRateVer40;
TFile *theFile;
TTree *sumTurfRateTree=0;
SummedTurfRate *theSummedTurfRateClass;
char rootFileName[FILENAME_MAX];
int doneInit=0;
int runNumber;
UInt_t realTime;
int main(int argc, char **argv) {
if(argc<3) {
std::cout << "Usage: " << basename(argv[0]) << " <file list> <outfile>" << std::endl;
return -1;
}
makeSummedTurfRateTree(argv[1],argv[2]);
return 0;
}
void makeSummedTurfRateTree(char *inName, char *outName) {
doneInit=0;
strncpy(rootFileName,outName,FILENAME_MAX);
std::ifstream PosFile(inName);
int numBytes=0;
char fileName[180];
int error=0;
int counter=0;
int firstTime=1;
GenericHeader_t gHdr;
int version=VER_SUM_TURF_RATE;
while(PosFile >> fileName) {
const char *subDir = gSystem->DirName(fileName);
const char *subSubDir = gSystem->DirName(subDir);
const char *turfRateDir= gSystem->DirName(subSubDir);
const char *houseDir = gSystem->DirName(turfRateDir);
const char *runDir = gSystem->DirName(houseDir);
const char *justRun = gSystem->BaseName(runDir);
// std::cout << justRun << endl;
sscanf(justRun,"run%d",&runNumber);
if(counter%100==0)
std::cout << fileName << std::endl;
counter++;
gzFile infile = gzopen (fileName, "rb");
if(firstTime) {
//Need to work out which version this is
numBytes=gzread(infile,&gHdr,sizeof(GenericHeader_t));
if(numBytes!=sizeof(GenericHeader_t)) {
std::cerr << "Error reading GenericHeader_t to determine version\n";
exit(0);
}
gzrewind(infile);
if(gHdr.code != PACKET_SUM_TURF_RATE) {
std::cerr << "not a SummedTurfRateStruct_t\n";
exit(0);
}
if(gHdr.verId != VER_SUM_TURF_RATE) {
std::cout << "Got version:\t" << version << " current " << VER_SUM_TURF_RATE << "\n";
switch(gHdr.verId) {
case 40:
if(gHdr.numBytes==sizeof(SummedTurfRateStructVer40_t)) {
std::cout << "Size matches will proceed\n";
version=40;
}
default:
std::cerr << "This version is not currently supported someone needs, to update me\n";
exit(0);
}
}
firstTime=0;
}
for(int i=0;i<1000;i++) {
if(version==VER_SUM_TURF_RATE) {
numBytes=gzread(infile,&theSummedTurfRate,sizeof(SummedTurfRateStruct_t));
if(numBytes!=sizeof(SummedTurfRateStruct_t)) {
error=1;
break;
}
}
else {
int numBytesExpected=sizeof(SummedTurfRateStruct_t);
switch(version) {
case 40:
numBytesExpected=sizeof(SummedTurfRateStructVer40_t);
numBytes=gzread(infile,&theSummedTurfRateVer40,numBytesExpected);
break;
default:
std::cerr << "Shouldn't ever get here\n";
exit(0);
}
}
processTurfRate(version);
}
gzclose(infile);
// if(error) break;
}
sumTurfRateTree->AutoSave();
theFile->Close();
doneInit=0;
}
void processTurfRate(int version) {
if(!doneInit) {
theFile = new TFile(rootFileName,"RECREATE");
sumTurfRateTree = new TTree("sumTurfRateTree","Tree of Anita TURF Trigger Rates");
sumTurfRateTree->Branch("sumturf","SummedTurfRate",&theSummedTurfRateClass);
doneInit=1;
std::cout << sumTurfRateTree << "\n";
}
cout << theSummedTurfRate.unixTime
<< "\t" << theSummedTurfRate.gHdr.code
<< endl;
if(theSummedTurfRateClass)
delete theSummedTurfRateClass;
if(version == VER_SUM_TURF_RATE) {
theSummedTurfRateClass = new SummedTurfRate(runNumber,
theSummedTurfRate.unixTime,
&theSummedTurfRate);
}
else {
switch(version) {
case 40:
theSummedTurfRateClass = new SummedTurfRate(runNumber,theSummedTurfRateVer40.unixTime,&theSummedTurfRateVer40);
break;
default:
std::cout << "And shouldn't ever get here\n";
exit(0);
}
}
sumTurfRateTree->Fill();
// delete theSummedTurfRateClass;
}