-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeEventRunTree.cxx
127 lines (108 loc) · 3.36 KB
/
makeEventRunTree.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
#include <cstdio>
#include <fstream>
#include <iostream>
#include <zlib.h>
#include <libgen.h>
using namespace std;
#include "TTree.h"
#include "TFile.h"
#include "TSystem.h"
#define HACK_FOR_ROOT
#include "simpleStructs.h"
#include "RawAnitaEvent.h"
void processBody();
void makeBodyTree(char *inputName, char *outDir);
PedSubbedEventBody_t theBody;
TFile *theFile;
TTree *eventTree;
RawAnitaEvent *theEvent=0;
char outDirName[FILENAME_MAX];
UInt_t realTime;
Int_t runNumber;
Int_t lastRunNumber;
int main(int argc, char **argv) {
if(argc<3) {
std::cout << "Usage: " << basename(argv[0]) << " <file list> <out dir>" << std::endl;
return -1;
}
makeBodyTree(argv[1],argv[2]);
return 0;
}
void makeBodyTree(char *inputName, char *outDir) {
cout << inputName << "\t" << outDir << endl;
strncpy(outDirName,outDir,FILENAME_MAX);
theEvent = new RawAnitaEvent();
// cout << sizeof(PedSubbedEventBody_t) << endl;
std::ifstream SillyFile(inputName);
int numBytes=0;
char fileName[180];
int error=0;
// int bodyNumber=1;
int counter=0;
int lastEventNumber=0;
while(SillyFile >> fileName) {
if(counter%100==0)
cout << fileName << endl;
counter++;
const char *subDir = gSystem->DirName(fileName);
const char *subSubDir = gSystem->DirName(subDir);
const char *eventDir = gSystem->DirName(subSubDir);
const char *runDir = gSystem->DirName(eventDir);
const char *justRun = gSystem->BaseName(runDir);
// cout << justRun << endl;
sscanf(justRun,"run%d",&runNumber);
gzFile infile = gzopen (fileName, "rb");
for(int i=0;i<100;i++) {
numBytes=gzread(infile,&theBody,sizeof(PedSubbedEventBody_t));
if(numBytes!=sizeof(PedSubbedEventBody_t)) {
if(numBytes>0) {
cerr << "Read problem: " << i << "\t" << numBytes << " of " << sizeof(PedSubbedEventBody_t) << " Last Event -- " << lastEventNumber << endl;
cout << fileName << endl;
}
error=1;
break;
}
//RJN hack for now
if(runNumber>=10000 && runNumber<=10057) {
if(counter>1 && i==1) {
if(theBody.eventNumber!=lastEventNumber+1) {
gzrewind(infile);
numBytes=gzread(infile,&theBody,sizeof(PedSubbedEventBody_t));
gzread(infile,&theBody,616);
numBytes=gzread(infile,&theBody,sizeof(PedSubbedEventBody_t));
}
}
}
// cout << "Event: " << i << "\t" << theBody.eventNumber << endl;
processBody();
lastEventNumber=theBody.eventNumber;
}
gzclose(infile);
// if(error) break;
}
eventTree->AutoSave();
// theFile->Close();
}
void processBody() {
// cout << "processBody:\t" << theBody.eventNumber << endl;
static int doneInit=0;
if(!doneInit) {
char dirName[FILENAME_MAX];
char fileName[FILENAME_MAX];
sprintf(dirName,"%s/run%d",outDirName,runNumber);
gSystem->mkdir(dirName,kTRUE);
sprintf(fileName,"%s/eventFile%d.root",dirName,runNumber);
cout << "Creating File: " << fileName << endl;
theFile = new TFile(fileName,"RECREATE");
eventTree = new TTree("eventTree","Tree of Anita Events");
eventTree->Branch("run",&runNumber,"run/I");
eventTree->Branch("event","RawAnitaEvent",&theEvent);
doneInit=1;
}
// cout << "Here: " << theBody.eventNumber << endl;
if(theEvent) delete theEvent;
theEvent = new RawAnitaEvent(&theBody);
eventTree->Fill();
lastRunNumber=runNumber;
// delete theEvent;
}