]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSOnlineSPDphys.cxx
General macro to estimate tracking efficiency
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSPDphys.cxx
index 11e8af7ca5f5aa8fdaff64df6c416ed25f49d128..5315fabea1ee705b362b82ea57c89bbf73e3c39f 100644 (file)
@@ -9,13 +9,12 @@
 ////////////////////////////////////////////////////////////
 
 #include <math.h>
-
 #include <TFile.h>
 #include "AliITSOnlineSPDphys.h"
 #include "AliITSOnlineSPDphysInfo.h"
 #include "AliITSOnlineSPDHitArray.h"
 
-AliITSOnlineSPDphys::AliITSOnlineSPDphys(const Char_t *fileName) :
+AliITSOnlineSPDphys::AliITSOnlineSPDphys(const Char_t *fileName, Bool_t readFromGridFile) :
   fFile(NULL),
   fWrite(kFALSE),
   fModified(kFALSE),
@@ -26,21 +25,45 @@ AliITSOnlineSPDphys::AliITSOnlineSPDphys(const Char_t *fileName) :
   // constructor, open file for reading or writing
   // look for a previously saved info object 
   // (if file not found create a new one and return, else read)
-  FILE* fp0 = fopen(fFileName.Data(), "r");
-  if (fp0 == NULL) {
+
+  for(Int_t ihs =0; ihs<6; ihs++) fHitArray[ihs]=0x0;
+
+  Bool_t bRead = readFromGridFile;
+
+  if (!bRead) {
+    FILE* fp0 = fopen(fFileName.Data(), "r");
+    if (fp0 != NULL) {
+      bRead=kTRUE;
+      fclose(fp0);
+    }
+  }
+
+  if (bRead) { // open file for reading
+    fFile = TFile::Open(fFileName.Data(), "READ");
+    if (fFile==NULL) { // grid file not found, create new local default file
+      printf("ERROR: AliITSOnlineSPDphys: File %s not found! Creating 'test999.root' file instead\n",fFileName.Data());
+      // create default empty file:
+      fFileName = "test999.root";
+      fPhysInfo = new AliITSOnlineSPDphysInfo();
+      fInfoModified=kTRUE;
+      fFile = new TFile(fFileName.Data(), "RECREATE");
+      fWrite=kTRUE;
+      InitHitmap();
+    }
+    else { // read from file (grid or local)
+      fWrite=kFALSE;
+      fFile->GetObject("AliITSOnlineSPDphysInfo", fPhysInfo);
+      ReadHitmap();
+    }
+  }
+  else { // create new local file
     fPhysInfo = new AliITSOnlineSPDphysInfo();
     fInfoModified=kTRUE;
     fFile = new TFile(fFileName.Data(), "RECREATE");
     fWrite=kTRUE;
     InitHitmap();
   }
-  else {
-    fclose(fp0);
-    fFile = new TFile(fFileName.Data(), "READ");
-    fWrite=kFALSE;
-    fFile->GetObject("AliITSOnlineSPDphysInfo", fPhysInfo);
-    ReadHitmap();
-  }
+
 }
 
 AliITSOnlineSPDphys::AliITSOnlineSPDphys(const AliITSOnlineSPDphys& /*phys*/) :
@@ -51,6 +74,7 @@ AliITSOnlineSPDphys::AliITSOnlineSPDphys(const AliITSOnlineSPDphys& /*phys*/) :
   fPhysInfo(NULL),
   fFileName(".")
 {
+  for(Int_t i=0; i<6; i++) fHitArray[i]=0x0;
   printf("This object should not be copied!");
 }
 
@@ -272,3 +296,5 @@ UInt_t AliITSOnlineSPDphys::GetEqNr() const {
 UInt_t AliITSOnlineSPDphys::GetNrEvents() const {
   return fPhysInfo->GetNrEvents();
 }
+
+