ARA ROOT v3.10 Software

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

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