Added two missing includes to allow macro compilation (thanks to Laurent for remarkin...
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSPDscanSingle.cxx
index 0fadffa..ffcd197 100644 (file)
 #include "AliITSOnlineSPDscanSingle.h"
 #include "AliITSOnlineSPDscanInfo.h"
 
-AliITSOnlineSPDscanSingle::AliITSOnlineSPDscanSingle(const Char_t *fileName) {
+AliITSOnlineSPDscanSingle::AliITSOnlineSPDscanSingle(const Char_t *fileName, Bool_t readFromGridFile) {
   // constructor
   fFileName=fileName;
+  fModified=kFALSE;
+  fInfoModified=kFALSE;
   // 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) {
+
+  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: AliITSOnlineSPDscan: File %s not found! Creating 'test999.root' file instead\n",fFileName.Data());
+      // create default empty file:
+      fFileName = "test999.root";
+      fScanInfo = new AliITSOnlineSPDscanInfo();
+      fInfoModified=kTRUE;
+      fFile = new TFile(fFileName.Data(), "RECREATE");
+      fWrite=kTRUE;
+    }
+    else { // read from file (grid or local)
+      fWrite=kFALSE;
+      fFile->GetObject("AliITSOnlineSPDscanInfo", fScanInfo);
+    }
+  }
+  else { // create new local file
     fScanInfo = new AliITSOnlineSPDscanInfo();
+    fInfoModified=kTRUE;
     fFile = new TFile(fFileName.Data(), "RECREATE");
     fWrite=kTRUE;
   }
-  else {
-    fclose(fp0);
-    fFile = new TFile(fFileName.Data(), "READ");
-    fWrite=kFALSE;
-    fFile->GetObject("AliITSOnlineSPDscanInfo", fScanInfo);
-  }
+
   Init();
 }
 AliITSOnlineSPDscanSingle::~AliITSOnlineSPDscanSingle() {}