ARA ROOT v3.10 Software

utilities/Icrr/makeIcrrCalibratedEventTree.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 "araIcrrStructures.h"
00017 #include "araAtriStructures.h"
00018 #include "RawIcrrStationEvent.h"  
00019 #include "UsefulIcrrStationEvent.h"
00020 
00021 void processEvent(UInt_t stationId);
00022 void makeEventTree(char *inputName, char *outDir, UInt_t stationId);
00023 
00024 IcrrEventBody_t theEventBody;
00025 TFile *theFile;
00026 TTree *eventTree;
00027 RawIcrrStationEvent *theEvent=0;
00028 UsefulIcrrStationEvent *theUsefulEvent=0;
00029 char outName[FILENAME_MAX];
00030 UInt_t realTime;
00031 Int_t runNumber;
00032 Int_t lastRunNumber;
00033 
00034 
00035 int main(int argc, char **argv) {
00036   if(argc<4) {
00037     std::cout << "Usage: " << basename(argv[0]) << " <file list> <out file> <stationId (TestBed==0 Station1==1)>" << std::endl;
00038     return -1;
00039   }
00040   makeEventTree(argv[1],argv[2], atoi(argv[3]));
00041   return 0;
00042 }
00043   
00044 
00045 void makeEventTree(char *inputName, char *outFile, UInt_t stationId) {
00046 
00047   bool debug = false; // set to true to increase the amount of commentary output
00048 
00049   cout << "user specification - input file list = " << inputName << "\t" << "outFile = " << outFile << endl;
00050   strncpy(outName,outFile,FILENAME_MAX);
00051   if ( debug ) {
00052      cout << "                   - full outFile = " << outFile << endl;
00053   }
00054   theEvent = new RawIcrrStationEvent();
00055   theUsefulEvent = new UsefulIcrrStationEvent();
00056 
00057   //    cout << sizeof(IcrrEventBody_t) << endl;
00058   ifstream SillyFile(inputName);
00059 
00060   int numBytes=0;
00061   char fileName[FILENAME_MAX];
00062   int error=0;
00063   //    int eventNumber=1;
00064 
00065   int total_evt_count = 0;
00066   int file_count=0;
00067   while( SillyFile >> fileName ) {
00068     cout << "processing file: " << fileName << endl;
00069     file_count++;
00070     static int lastEventNumber=-1;    
00071     const char *subDir = gSystem->DirName(fileName);
00072     //    const char *subSubDir = gSystem->DirName(subDir);
00073     //    const char *eventDir = gSystem->DirName(subSubDir);
00074     const char *runDir = gSystem->DirName(subDir);
00075     const char *justRun = gSystem->BaseName(runDir);
00076     sscanf(justRun,"run_%d",&runNumber);
00077     //    cout << justRun << "\t" << runNumber <<endl;
00078     
00079     gzFile infile = gzopen(fileName, "rb");    
00080     numBytes=gzread(infile,&theEventBody,sizeof(IcrrEventBody_t));
00081     int evt_count = 1;
00082     total_evt_count++;
00083     while ( numBytes == sizeof(IcrrEventBody_t) ) {
00084       if ( debug                      ||
00085            ( (evt_count % 100) == 1 ) ) {
00086          cout << "Event count: " << "for_file = " << evt_count << " - all_toll = " << total_evt_count << endl;
00087       }
00088       if(numBytes!=sizeof(IcrrEventBody_t)) {
00089         if(numBytes)
00090           cerr << "Read problem: " <<numBytes << " of " << sizeof(IcrrEventBody_t) << endl;
00091         error=1;
00092         break;
00093       }
00094       //      cout << "Event: " << theEventBody.hd.eventNumber << endl;
00095       if(TMath::Abs(Double_t(theEventBody.hd.eventNumber)-lastEventNumber)>1000 && lastEventNumber>=0) {
00096         std::cerr << "Dodgy event\t" << theEventBody.hd.eventNumber << "\n";
00097       } 
00098       else {     
00099         processEvent(stationId);
00100         lastEventNumber=theEventBody.hd.eventNumber;
00101       }
00102       numBytes=gzread(infile,&theEventBody,sizeof(IcrrEventBody_t));
00103       evt_count++;
00104       total_evt_count++;
00105     } // end of while loop over events in the input file
00106     gzclose(infile);
00107     //  if(error) break;
00108 
00109   } // end of while loop over the ev_ files in the file list
00110   eventTree->AutoSave();
00111   //    theFile->Close();
00112 }
00113 
00114 void processEvent(UInt_t stationId) {
00115   //  cout << "processEvent:\t" << theEventBody.eventNumber << endl;
00116   static int doneInit=0;
00117   
00118   if(!doneInit) {
00119     //    char dirName[FILENAME_MAX];
00120     //    char fileName[FILENAME_MAX];
00121     //    sprintf(dirName,"%s/run%d",outDirName,runNumber);
00122     //    gSystem->mkdir(dirName,kTRUE);
00123     //    sprintf(fileName,"%s/eventFile%d.root",dirName,runNumber);
00124     cout << "Creating File: " << outName << endl;
00125     theFile = new TFile(outName,"RECREATE");
00126     eventTree = new TTree("eventTree","Tree of ARA Events");
00127     eventTree->Branch("run",&runNumber,"run/I");
00128     eventTree->Branch("event","RawIcrrStationEvent",&theEvent);
00129     eventTree->Branch("calevent","UsefulIcrrStationEvent",&theUsefulEvent);
00130     
00131     doneInit=1;
00132   }
00133   //  cout << "Here: "  << theEvent.eventNumber << endl;
00134   if(theEvent) delete theEvent;
00135   if(theUsefulEvent) delete theUsefulEvent;
00136   theEvent = new RawIcrrStationEvent(&theEventBody, stationId);
00137   theUsefulEvent = new UsefulIcrrStationEvent( theEvent , AraCalType::kLatestCalib );
00138   eventTree->Fill();  
00139   lastRunNumber=runNumber;
00140   //  delete theEvent;
00141 }

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