ARA ROOT v3.10 Software

analysis/getAtriRunStatistics.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 "AraGeomTool.h"
00017 #include "araAtriStructures.h"
00018 #include "RawAtriStationEvent.h"  
00019 
00020 void process();
00021 void processFileList(char *inputName, char *outDir, int run);
00022 
00023 AraStationEventHeader_t theEventHeader;
00024 
00025 char *dataBuffer;
00026 TFile *outFile;
00027 TTree *outTree;
00028 RawAtriStationEvent *theEvent=0;
00029 char outName[FILENAME_MAX];
00030 UInt_t realTime;
00031 Int_t runNumber;
00032 Int_t stationIdInt;
00033 AraStationId_t stationId;
00034 
00035 //For statistics
00036 
00037 Int_t numEvents=0;
00038 Int_t numEvents_CPU=0;
00039 Int_t numEvents_RF0=0;
00040 Int_t numEvents_CALPULSER=0;
00041 Double_t eventRate=0;
00042 
00043 Int_t lastNumEvents=0;
00044 Int_t lastNumEvents_CPU=0;
00045 Int_t lastNumEvents_RF0=0;
00046 Int_t lastNumEvents_CALPULSER=0;
00047 
00048 
00049 //For Tree
00050 UInt_t lastUnixTime=0;
00051 UInt_t thisUnixTime=0;
00052 Double_t calPulserRate=0;
00053 Double_t RF0Rate=0;
00054 Double_t CPURate=0;
00055 Int_t lastTime=0;
00056 Int_t firstTime=0;
00057 
00058 
00059 int main(int argc, char **argv) {
00060   dataBuffer = new char[200000];
00061   theEvent=0;
00062   if(argc<4) {
00063     std::cout << "Usage: " << basename(argv[0]) << " <file list> <outFileName> <run>" << std::endl;
00064     return -1;
00065   }
00066 
00067   processFileList(argv[1],argv[2], atoi(argv[3]));
00068   delete [] dataBuffer;
00069   return 0;
00070 }
00071   
00072 
00073 void processFileList(char *inputName, char *outFileName, int run) {
00074   cout << inputName << "\t" << outFileName << endl;
00075 
00076   theEvent = new RawAtriStationEvent();
00077 
00078   ifstream SillyFile(inputName);
00079   outFile = new TFile(outFileName, "RECREATE");
00080   outTree = new TTree("runStatsTree", "Tree of run statistics");
00081   outTree->Branch("lastUnixTime", &lastUnixTime, "lastUnixTime/i");
00082   outTree->Branch("thisUnixTime", &thisUnixTime, "thisUnixTime/i");
00083   outTree->Branch("calPulserRate", &calPulserRate, "calPulserRate/D");
00084   outTree->Branch("RF0Rate", &RF0Rate, "RF0Rate/D");
00085   outTree->Branch("CPURate", &CPURate, "CPURate/D");
00086 
00087   outTree->Branch("eventRate", &eventRate, "eventRate/D");
00088   outTree->Branch("numEvents", &numEvents, "numEvents/I");
00089   outTree->Branch("numEvents_CALPULSER", &numEvents_CALPULSER, "numEvents_CALPULSER/I");
00090   outTree->Branch("numEvents_RF0", &numEvents_RF0, "numEvents_RF0/I");
00091   outTree->Branch("numEvents_CPU", &numEvents_CPU, "numEvents_CPU/I");
00092   outTree->Branch("stationId", &stationId, "stationId/I");
00093   outTree->Branch("lastTime", &lastTime, "lastTime/I");
00094   outTree->Branch("firstTime", &firstTime, "firstTime/I");
00095   outTree->Branch("runNumber", &runNumber, "runNumber/I");
00096 
00097   runNumber = run;
00098 
00099 
00100   firstTime=1;
00101   int numBytes=0;
00102   char fileName[180];
00103   int error=0;
00104   //    int eventNumber=1;
00105   int counter=0;
00106   while(SillyFile >> fileName) {
00107     if(counter%100==0) 
00108       cout << fileName << endl;
00109     counter++;
00110     
00111     gzFile infile = gzopen (fileName, "rb");    
00112     //    std::cout << "gzeof: " << gzeof(infile) << "\n";
00113     for(int i=0;i<1000;i++) {   
00114       //      cout << i << endl;
00115       numBytes=gzread(infile,&theEventHeader,sizeof(AraStationEventHeader_t));
00116       //      std::cout << numBytes << "\n";
00117       if(numBytes==0) break;
00118       if(numBytes!=sizeof(AraStationEventHeader_t)) {
00119         if(numBytes)
00120           cerr << "Read problem: " <<numBytes << " of " << sizeof(AraStationEventHeader_t) << endl;
00121         error=1;
00122         break;
00123       }
00124 
00125       if(theEventHeader.gHdr.numBytes>0) {
00126         //      std::cout << "Num bytes: " << theEventHeader.gHdr.numBytes << "\t" << theEventHeader.numBytes << "\n";
00127         //      std::cout << "Event number: " << theEventHeader.eventNumber << "\t" << theEventHeader.unixTime << "\t" << theEventHeader.unixTimeUs << "\n";
00128         
00129         
00130         Int_t numDataBytes=theEventHeader.gHdr.numBytes-sizeof(AraStationEventHeader_t);
00131         numBytes=gzread(infile,dataBuffer,numDataBytes);
00132         //      std::cout << numBytes << "\n";
00133         if(numBytes==0) break;
00134         if(numBytes!=numDataBytes) {
00135           if(numBytes)
00136             cerr << "Read problem: " <<numBytes << " of " <<  numDataBytes << endl;
00137           error=1;
00138           break;
00139         }
00140         stationId = theEventHeader.gHdr.stationId;
00141 
00142         process();
00143         //      exit(0);
00144       }
00145       else {
00146         std::cerr << "How can gHdr.numBytes = " << theEventHeader.gHdr.numBytes << "\n";
00147         error=1;
00148         break;
00149       }
00150 
00151       //      cout << ": " << theEventHeader.unixTime << endl;
00152      }
00153     gzclose(infile);
00154     //  if(error) break;
00155   }
00156   lastTime=1;
00157   process();
00158 
00159   outFile->Write();
00160 
00161 }
00162 
00163 
00164 void process() {
00165   static int doneInit=0;
00166   if(!doneInit) {
00167     doneInit=1;
00168   }  
00169   if(theEvent) delete theEvent;
00170   
00171   theEvent = new RawAtriStationEvent(&theEventHeader,dataBuffer);
00172 
00173 
00174   //Create stats
00175   if(firstTime){
00176     lastUnixTime=theEvent->unixTime;
00177     thisUnixTime=lastUnixTime;
00178     outTree->Fill();
00179     firstTime=0;
00180   }
00181   thisUnixTime=theEvent->unixTime;
00182   numEvents++;
00183   if(theEvent->numReadoutBlocks<80) numEvents_CPU++;
00184   else numEvents_RF0++;
00185   if(theEvent->isCalpulserEvent()) numEvents_CALPULSER++;
00186 
00187 
00188   if(thisUnixTime >= lastUnixTime + 60*30 || lastTime){
00189     
00190     if(thisUnixTime > lastUnixTime){
00191 
00192       eventRate= (1.*(numEvents - lastNumEvents)) / (thisUnixTime - lastUnixTime);
00193       calPulserRate= (1.*(numEvents_CALPULSER - lastNumEvents_CALPULSER)) / (thisUnixTime - lastUnixTime);
00194       RF0Rate= (1.*(numEvents_RF0 - lastNumEvents_RF0)) / (thisUnixTime - lastUnixTime);
00195       CPURate= (1.*(numEvents_CPU - lastNumEvents_CPU)) / (thisUnixTime - lastUnixTime);
00196 
00197     }
00198     //Otherwise they are just the last rate
00199 
00200     outTree->Fill();
00201     lastUnixTime=thisUnixTime;
00202     lastNumEvents=numEvents;
00203     lastNumEvents_CPU=numEvents_CPU;
00204     lastNumEvents_RF0=numEvents_RF0;
00205     lastNumEvents_CALPULSER=numEvents_CALPULSER;
00206   }
00207 
00208 
00209 }

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