-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeOtherTree.cxx
96 lines (77 loc) · 2.18 KB
/
makeOtherTree.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
#include <cstdio>
#include <fstream>
#include <iostream>
#include <zlib.h>
#include <libgen.h>
#include "TTree.h"
#include "TFile.h"
#include "TSystem.h"
#include "TTreeIndex.h"
#define HACK_FOR_ROOT
#include "simpleStructs.h"
#include "OtherMonitorHk.h"
void processMonitor();
void makeMonitorTree(char *inName, char *outName);
//Global Variable
OtherMonitorHk *theOtherHkPtr;
OtherMonitorStruct_t theOther;
TFile *theFile;
TTree *otherTree;
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;
}
makeMonitorTree(argv[1],argv[2]);
return 0;
}
void makeMonitorTree(char *inName, char *outName) {
strncpy(rootFileName,outName,FILENAME_MAX);
std::ifstream PosFile(inName);
int numBytes=0;
char fileName[180];
int error=0;
int counter=0;
while(PosFile >> fileName) {
const char *subDir = gSystem->DirName(fileName);
const char *subSubDir = gSystem->DirName(subDir);
const char *monitorDir= gSystem->DirName(subSubDir);
const char *houseDir = gSystem->DirName(monitorDir);
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 << std::endl;
counter++;
gzFile infile = gzopen (fileName, "rb");
for(int i=0;i<1000;i++) {
numBytes=gzread(infile,&theOther,sizeof(OtherMonitorStruct_t));
if(numBytes!=sizeof(OtherMonitorStruct_t)) {
error=1;
break;
}
processMonitor();
}
gzclose(infile);
// if(error) break;
}
otherTree->AutoSave();
theFile->Close();
doneInit=0;
}
void processMonitor() {
if(!doneInit) {
theFile = new TFile(rootFileName,"UPDATE");
otherTree = new TTree("otherTree","Tree of Anita Other Monitor Stuff");
otherTree->Branch("othermon","OtherMonitorHk",&theOtherHkPtr);
doneInit=1;
}
if(theOtherHkPtr) delete theOtherHkPtr;
theOtherHkPtr = new OtherMonitorHk(runNumber,theOther.unixTime,&theOther);
otherTree->Fill();
}