-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeSurfHkTree.cxx
204 lines (179 loc) · 5.34 KB
/
makeSurfHkTree.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <zlib.h>
#include <libgen.h>
#include "TTree.h"
#include "TChain.h"
#include "TFile.h"
#include "TSystem.h"
#include "TTreeIndex.h"
#define HACK_FOR_ROOT
#include "SurfHk.h"
#include "simpleStructs.h"
void processSurfHk(int version);
void makeSurfHkTree(char *inName, char *outName);
//Global Variable
SurfHk *surfHkPtr=0;
FullSurfHkStruct_t theSurfHk;
FullSurfHkStructVer14_t theSurfHkVer14;
FullSurfHkStructVer13_t theSurfHkVer13;
FullSurfHkStructVer12_t theSurfHkVer12;
TFile *theFile;
TTree *surfhkTree;
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;
}
makeSurfHkTree(argv[1],argv[2]);
return 0;
}
void makeSurfHkTree(char *inName, char *outName) {
//Now things are a little more tricky as we are going to try and
//work out which Version we have and use the appropriate pointer
strncpy(rootFileName,outName,FILENAME_MAX);
// std::cout << sizeof(FullSurfHkStruct_t) << std::endl;
std::ifstream PosFile(inName);
int numBytes=0;
char fileName[180];
int error=0;
int counter=0;
int firstTime=1;
int version=VER_SURF_HK;
GenericHeader_t gHdr;
while(PosFile >> fileName) {
const char *subDir = gSystem->DirName(fileName);
const char *subSubDir = gSystem->DirName(subDir);
const char *surfhkDir= gSystem->DirName(subSubDir);
const char *houseDir = gSystem->DirName(surfhkDir);
const char *runDir = gSystem->DirName(houseDir);
const char *justRun = gSystem->BaseName(runDir);
// std::cout << justRun << std::endl;
sscanf(justRun,"run%d",&runNumber);
if(counter%100==0)
std::cout << fileName << "\t" << theSurfHk.threshold[0][0] << 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_SURF_HK) {
std::cerr << "not a FullSurfHkStruct_t\n";
exit(0);
}
if(gHdr.verId != VER_SURF_HK) {
std::cout << "Old version of FullSurfHkStruct_t -- " << (int)gHdr.verId
<< std::endl;
switch(gHdr.verId) {
case 14:
if(gHdr.numBytes==sizeof(FullSurfHkStructVer14_t)) {
std::cout << "Size matches will proceed\n";
version=14;
}
break;
case 13:
if(gHdr.numBytes==sizeof(FullSurfHkStructVer13_t)) {
std::cout << "Size matches will proceed\n";
version=13;
}
break;
case 12:
case 11:
case 10:
if(gHdr.numBytes==sizeof(FullSurfHkStructVer12_t)) {
std::cout << "Size matches will proceed\n";
version=12;
}
break;
default:
std::cerr << "This version is not currently supported someone needs, to update me\n";
exit(0);
}
}
firstTime=0;
std::cout << "Proceeding with version " << (int)version << " ("
<< VER_SURF_HK << ")\n";
}
for(int i=0;i<1000;i++) {
if(version==VER_SURF_HK) {
numBytes=gzread(infile,&theSurfHk,sizeof(FullSurfHkStruct_t));
if(numBytes!=sizeof(FullSurfHkStruct_t)) {
error=1;
break;
}
}
else {
int numBytesExpected=sizeof(FullSurfHkStruct_t);
switch(version) {
case 14:
numBytesExpected=sizeof(FullSurfHkStructVer14_t);
numBytes=gzread(infile,&theSurfHkVer14,numBytesExpected);
break;
case 13:
numBytesExpected=sizeof(FullSurfHkStructVer13_t);
numBytes=gzread(infile,&theSurfHkVer13,numBytesExpected);
break;
case 12:
numBytesExpected=sizeof(FullSurfHkStructVer12_t);
numBytes=gzread(infile,&theSurfHkVer12,numBytesExpected);
break;
default:
std::cerr << "Shouldn't ever get here\n";
exit(0);
}
if(numBytes!=numBytesExpected) {
error=1;
break;
}
}
// std::cout << theSurfHk.gHdr.code << "\t" << theSurfHk.unixTime << std::endl;
processSurfHk(version);
}
gzclose(infile);
// if(error) break;
}
surfhkTree->AutoSave();
// theFile->Close();
doneInit=0;
}
void processSurfHk(int version) {
if(!doneInit) {
theFile = new TFile(rootFileName,"RECREATE");
surfhkTree = new TTree("surfHkTree","Tree of Anita Scalers And Thresholds");
surfhkTree->Branch("surf","SurfHk",&surfHkPtr);
doneInit=1;
}
// std::cout << theSurfHk.threshold[0][0] << std::endl;
if(surfHkPtr) delete surfHkPtr;
if(version==VER_SURF_HK) {
surfHkPtr = new SurfHk(runNumber,theSurfHk.unixTime,&theSurfHk);
}
else {
switch(version) {
case 14:
surfHkPtr = new SurfHk(runNumber,theSurfHkVer14.unixTime,&theSurfHkVer14);
break;
case 13:
surfHkPtr = new SurfHk(runNumber,theSurfHkVer13.unixTime,&theSurfHkVer13);
break;
case 12:
surfHkPtr = new SurfHk(runNumber,theSurfHkVer12.unixTime,&theSurfHkVer12);
break;
default:
std::cout << "And shouldn't ver get here\n";
exit(0);
}
}
surfhkTree->Fill();
}