ARA ROOT v3.10 Software

utilities/Atri/makeSimpleAtriEventTree.cxx

00001 #include <cstdio>
00002 #include <fstream>
00003 #include <iostream>
00004 #include <zlib.h>
00005 #include <libgen.h>     
00006 #include <cstdlib>
00007  
00008 using namespace std;
00009 
00010 #include "TTree.h"
00011 #include "TFile.h"
00012 #include "TSystem.h"
00013 
00014 #define HACK_FOR_ROOT
00015 
00016 #include "araAtriStructures.h"
00017 #include "RawAtriSimpleStationEvent.h"  
00018 
00019 void process();
00020 void makeTree(char *inputName, char *outDir);
00021 
00022 AraSimpleStationEvent_t theEventStruct;
00023 TFile *theFile;
00024 TTree *eventTree;
00025 RawAtriSimpleStationEvent *theEvent=0;
00026 char outName[FILENAME_MAX];
00027 UInt_t realTime;
00028 Int_t runNumber;
00029 Int_t lastRunNumber;
00030 
00031 
00032 int main(int argc, char **argv) {
00033   if(argc<3) {
00034     std::cout << "Usage: " << basename(argv[0]) << " <file list> <out dir>" << std::endl;
00035     return -1;
00036   }
00037   if(argc==4) 
00038     runNumber=atoi(argv[3]);
00039   makeTree(argv[1],argv[2]);
00040   return 0;
00041 }
00042   
00043 
00044 void makeTree(char *inputName, char *outFile) {
00045   cout << inputName << "\t" << outFile << endl;
00046   strncpy(outName,outFile,FILENAME_MAX);
00047   theEvent = new RawAtriSimpleStationEvent();
00048   //    cout << sizeof(AraSimpleStationEvent_t) << endl;
00049   ifstream SillyFile(inputName);
00050 
00051   int numBytes=0;
00052   char fileName[180];
00053   int error=0;
00054   //    int eventNumber=1;
00055   int counter=0;
00056   while(SillyFile >> fileName) {
00057     if(counter%100==0) 
00058       cout << fileName << endl;
00059     counter++;
00060     
00061     //    const char *subDir = gSystem->DirName(fileName);
00062     //    const char *subSubDir = gSystem->DirName(subDir);
00063     //    const char *eventDir = gSystem->DirName(subSubDir);
00064     //    const char *runDir = gSystem->DirName(eventDir);
00065     //    const char *justRun = gSystem->BaseName(runDir);
00066     //  cout << justRun << endl;
00067     //    sscanf(justRun,"run%d",&runNumber);
00068     
00069     gzFile infile = gzopen (fileName, "rb");    
00070     //    std::cout << "gzeof: " << gzeof(infile) << "\n";
00071     for(int i=0;i<1000;i++) {   
00072       //      cout << i << endl;
00073       numBytes=gzread(infile,&theEventStruct,sizeof(AraSimpleStationEvent_t));
00074       //      std::cout << numBytes << "\n";
00075       if(numBytes==0) break;
00076       if(numBytes!=sizeof(AraSimpleStationEvent_t)) {
00077         if(numBytes)
00078           cerr << "Read problem: " <<numBytes << " of " << sizeof(AraSimpleStationEvent_t) << endl;
00079         error=1;
00080         break;
00081       }
00082       //      cout << ": " << theEventStruct.unixTime << endl;
00083       process();
00084     }
00085     gzclose(infile);
00086     //  if(error) break;
00087   }
00088   if(eventTree)
00089     eventTree->AutoSave();
00090   //    theFile->Close();
00091 }
00092 
00093 
00094 void process() {
00095   //  cout << "process:\t" << theEventStruct.eventNumber << endl;
00096   static int doneInit=0;
00097   
00098   if(!doneInit) {
00099     //    char dirName[FILENAME_MAX];
00100     //    char fileName[FILENAME_MAX];
00101     //    sprintf(dirName,"%s/run%d",outDirName,runNumber);
00102     //    gSystem->mkdir(dirName,kTRUE);
00103     //    sprintf(fileName,"%s/eventFile%d.root",dirName,runNumber);
00104     cout << "Creating File: " << outName << endl;
00105     theFile = new TFile(outName,"RECREATE");
00106     eventTree = new TTree("eventTree","Tree of ARA Event's");
00107     eventTree->Branch("run",&runNumber,"run/I");
00108     eventTree->Branch("event","RawAtriSimpleStationEvent",&theEvent);
00109     
00110     doneInit=1;
00111   }  
00112   //  cout << "Here: "  << theEvent.eventNumber << endl;
00113   if(theEvent) delete theEvent;
00114   theEvent = new RawAtriSimpleStationEvent(&theEventStruct);
00115   eventTree->Fill();  
00116   lastRunNumber=runNumber;
00117   //  delete theEvent;
00118 }

Generated on Tue Jul 16 16:58:02 2013 for ARA ROOT v3.10 Software by doxygen 1.4.7