]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliSurveyObj.cxx
Increasing the class version number.
[u/mrichter/AliRoot.git] / STEER / AliSurveyObj.cxx
index b43ff8c8164cb2dfa20617c09c6bbcdee144cc21..0afda085ef5e58b4d677ce22c109f98e122c3e01 100644 (file)
@@ -23,8 +23,6 @@
 #include "AliSurveyObj.h"
 
 //ROOT includes
-//#include "TROOT.h"
-//#include "Riostream.h"
 #include "TObjArray.h"
 #include "TGrid.h"
 #include "TGridResult.h"
@@ -42,7 +40,7 @@ const TString AliSurveyObj::fgkStorage = "alien://alice.cern.ch";
 const TString AliSurveyObj::fgkBaseFolder = "/alice/data/Reference";
 const TString AliSurveyObj::fgkValidDetectors = "ACORDE,BABYFRAME,BACKFRAME,\
 EMCAL,FMD,HMPID,ITS,L3 MAGNET,MUON,MUON ABSORBERS,MUON DIPOLE,PHOS,PMD,\
-SPACEFRAME,SUPERSTRUCTURE,T0,TOF,TPC,TRD,V0,ZDC,GRP";
+SPACEFRAME,SUPERSTRUCTURE,T0,TOF,TPC,TRD,VZERO,ZDC,GRP";
 const TString AliSurveyObj::fgkGRPDetectors = "BABYFRAME,BACKFRAME,L3 MAGNET,\
 SPACEFRAME,MUON DIPOLE,MUON ABSORBERS,GRP";
 const TString AliSurveyObj::fgkMUONDetectors = "MUON,SUPERSTRUCTURE";
@@ -150,11 +148,11 @@ Bool_t AliSurveyObj::Connect(const char *gridUrl, const char *user) {
 
   // If the same "Grid" is alreay active, skip connection
   if (!gGrid || gridUrl != gGrid->GridUrl() ||
-      (( user != "" ) && ( user != gGrid->GetUser() )) ) {
+      (( strcmp(user,"") ) && ( strcmp(user,gGrid->GetUser()) )) ) {
     // connection to the Grid
     AliInfo("\nConnecting to the Grid...");
     if (gGrid) {
-      AliInfo(Form("gGrid = %x; GridUrl = %s; gGrid->GridUrl() = %s", 
+      AliInfo(Form("gGrid = %p; GridUrl = %s; gGrid->GridUrl() = %s", 
                   gGrid, gridUrl, gGrid->GridUrl()));
       AliInfo(Form("User = %s; gGrid->GetUser() = %s",
                   user, gGrid->GetUser()));
@@ -174,7 +172,7 @@ Bool_t AliSurveyObj::Connect(const char *gridUrl, const char *user) {
 Bool_t AliSurveyObj::OpenFile(TString openString) {
   // Opens the file and reads it to a buffer
 
-  Printf("Open string: \n -> \"%s\"\n", openString.Data());
+  AliInfo(Form("Opening file \"%s\"\n for survey data", openString.Data()));
 
   if (openString.BeginsWith("alien://"))
     if (!Connect(fgkStorage.Data(), fGridUser.Data())) {
@@ -198,13 +196,13 @@ Bool_t AliSurveyObj::OpenFile(TString openString) {
     AliError("Error reading file contents to buffer!");
     return kFALSE;
   }
-  Printf("%d bytes read!\n", file->GetBytesRead());
+  AliInfo(Form("%lld bytes read!\n", file->GetBytesRead()));
   
-  ParseBuffer(buf);
+  Bool_t goodParsing = ParseBuffer(buf);
 
   file->Close();
   delete[] buf;
-  return kTRUE;
+  return goodParsing;
 }
 
 
@@ -417,34 +415,30 @@ Int_t AliSurveyObj::FileNamePathToReportVersion(TString filename) const {
 
 //_____________________________________________________________________________
 void AliSurveyObj::ListValidDetectors() {
-  // List the valid detector names
-  Printf("");
-  Printf("Listing all valid detectors:\n");
-  TObjArray *dets = fgkValidDetectors.Tokenize(',');
-  for (int i = 0; i < dets->GetEntries(); ++i) 
-    Printf("%s", ((TObjString *) dets->At(i))->GetString().Data());
-  dets->Delete();
-  dets = 0;
-  Printf("");
-  Printf("Some reports are stored in more general folders.");
-  Printf("These reports can be opened using either name, the original or the");
-  Printf("folder name. Example: 'SPACEFRAME' or 'GRP' are both valid when");
-  Printf("opening a report for the Spaceframe.");
-  Printf("");
-  Printf("Detectors stored in 'MUON' folder:");
-  dets = fgkMUONDetectors.Tokenize(',');
-  for (int i = 0; i < dets->GetEntries(); ++i) 
-    Printf("%s", ((TObjString *) dets->At(i))->GetString().Data());
-  dets->Delete();
-  dets = 0;
-  Printf("");
-  Printf("Detectors stored in 'GRP' folder:");
-  dets = fgkGRPDetectors.Tokenize(',');
-  for (int i = 0; i < dets->GetEntries(); ++i) 
-    Printf("%s", ((TObjString *) dets->At(i))->GetString().Data());
-  dets->Delete();
-  dets = 0;
-  return;
+    // List the valid detector names
+    Printf("Listing all valid detectors:\n");
+    TObjArray *dets = fgkValidDetectors.Tokenize(',');
+    for (int i = 0; i < dets->GetEntries(); ++i) 
+       Printf("%s", ((TObjString *) dets->At(i))->GetString().Data());
+    dets->Delete();
+    dets = 0;
+    Printf("Some reports are stored in more general folders.\n"
+           "These reports can be opened using either name, the original or the\n"
+           "folder name. Example: 'SPACEFRAME' or 'GRP' are both valid when\n"
+           "opening a report for the Spaceframe.\n\n"
+           "Detectors stored in 'MUON' folder:");
+    dets = fgkMUONDetectors.Tokenize(',');
+    for (int i = 0; i < dets->GetEntries(); ++i) 
+       Printf("%s", ((TObjString *) dets->At(i))->GetString().Data());
+    dets->Delete();
+    dets = 0;
+    Printf("Detectors stored in 'GRP' folder:");
+    dets = fgkGRPDetectors.Tokenize(',');
+    for (int i = 0; i < dets->GetEntries(); ++i) 
+       Printf("%s", ((TObjString *) dets->At(i))->GetString().Data());
+    dets->Delete();
+    dets = 0;
+    return;
 }
 
 
@@ -484,8 +478,7 @@ TGridResult * AliSurveyObj::QueryReports(TString detector, Int_t year,
 
   lsArg += yearFolder + reportFolder + versionFolder + ".txt";
 
-  Printf("");
-  Printf(Form("Looking for:  %s \n", lsArg.Data()));
+  AliInfo(Form("\nLooking for:  %s \n", lsArg.Data()));
   
   // Check if fGridUser is set and Connect to AliEn
   if (0 == fGridUser.Length()) {
@@ -517,15 +510,14 @@ Int_t AliSurveyObj::ListReports(TString detector, Int_t year,
   Int_t numberEntries = res->GetEntries();
 
   if (numberEntries > 0) {
-    Printf("");
-    Printf(Form("%d reports found:", numberEntries));
+    Printf("%d reports found:", numberEntries);
     for (int i = 0; i < res->GetEntries(); ++i) {
       fn = res->GetFileNamePath(i);
-      Printf(Form("Detector:%s\tYear:%d\tEDMS Report Number:%d\tVersion:%d",
+      Printf("Detector:%s\tYear:%d\tEDMS Report Number:%d\tVersion:%d",
                  FileNamePathToDetector(fn).Data(),
                  FileNamePathToReportYear(fn),
                  FileNamePathToReportNumber(fn),
-                 FileNamePathToReportVersion(fn)));
+                 FileNamePathToReportVersion(fn));
     }
     delete res;
     return numberEntries;
@@ -553,6 +545,7 @@ TString &AliSurveyObj::Sanitize(TString str) {
   str.Remove(TString::kTrailing, '\r');
   str.Remove(TString::kTrailing, '\n');
   str.Remove(TString::kTrailing, '\r');
+
   if (!str.IsAscii()) {
     AliWarning("Warning: Non-ASCII characters!\n");
     str = "";
@@ -571,7 +564,26 @@ Bool_t AliSurveyObj::ParseBuffer(const Char_t* buf) {
 
   // Copy the buffer to a TString to use Tokenize
   TString buffer = TString(buf);
-  TObjArray *lines = buffer.Tokenize('\n');
+  TObjArray *linesRaw = buffer.Tokenize('\n');
+  // replace the array of lines with an array of sanitized lines
+  // in the process we remove empty lines, particularly disturbing
+  // in case of dos fileformat
+  TString oneLine = "";
+  TObjString* oneLineObj = 0;
+  TObjArray *lines = new TObjArray();
+  for(Int_t i=0; i<linesRaw->GetEntries(); i++)
+  {
+         oneLine = ((TObjString *)(linesRaw->At(i)))->GetString().Data();
+         oneLine = Sanitize(oneLine);
+         if (oneLine.Length() == 0) continue;
+         oneLineObj = new TObjString(oneLine);
+         lines->Add(oneLineObj);
+  }
+
+  linesRaw->Delete();
+  delete linesRaw;
+  linesRaw = NULL;
+
   TObjArray *dataLine = NULL; // Used to Tokenize each point/line read
   TObjArray *colLine = NULL; // Used to Tokenize the column names
 
@@ -598,15 +610,11 @@ Bool_t AliSurveyObj::ParseBuffer(const Char_t* buf) {
     // Get the next line
     currLine = ((TObjString *)(lines->At(i)))->GetString().Data();
     nextLine = ((i + 1) < nrLines ? ((TObjString *)(lines->At(i + 1)))->GetString().Data() : "");
-    currLine = Sanitize(currLine);
-    nextLine = Sanitize(nextLine);
-    // Printf("\n%d: \"\"%s\"\"\"\n", i + 1, currLine.Data());
+    // Printf("%d: \"%s\"", i, currLine.Data());
+    // Printf("%d:  \"%s\"\n", i+1, nextLine.Data());
     
-    // Skip empty line
-    if (0 == currLine.Length()) Printf("Info: Empty line skipped\n\n");
-
     // The line contains a keyword
-    else if (currLine.BeginsWith(">") && !nextLine.BeginsWith(">")) {
+    if (currLine.BeginsWith(">") && !nextLine.BeginsWith(">")) {
       currLine.Remove(TString::kLeading, '>');
       currLine.Remove(TString::kTrailing, ':');
       currLine.Remove(TString::kBoth, ' ');
@@ -634,25 +642,27 @@ Bool_t AliSurveyObj::ParseBuffer(const Char_t* buf) {
          nextLine.Remove(TString::kTrailing, '/');
          nextLine = nextLine(nextLine.Last('/') + 1, nextLine.Length() - nextLine.Last('/') + 1);
          
-         Int_t sscanftmp = 0;
-         if (1 != sscanf(nextLine.Data(), "%d", &sscanftmp)) {
-           AliError("Survey text file sintax error! (incorrectly formated Report URL)");
+         if (!nextLine.IsDigit()) {
+           AliError("Survey text file sintax error! (incorrectly formatted Report URL)");
+           AliError(Form("Wrong report number string: \"%s\"",nextLine.Data()));
            lines->Delete();
+           delete lines; lines = NULL;
            return kFALSE;
          }
          fReportNr = nextLine.Atoi();
          //Printf(" $$ %d $$\n", fReportNr);
          ++i;
        } else { 
-         // URL incorrectly formated
-         AliError("Survey text file sintax error! (incorrectly formated Report URL)");
+         // URL incorrectly formatted
+         AliError("Survey text file sintax error! (incorrectly formatted Report URL)");
          return kFALSE;
        }
       } else if (currLine.BeginsWith("Version", TString::kIgnoreCase)) {
        // Report version
        if (!nextLine.IsDigit()) {
          lines->Delete();
-         AliError("Survey text file sintax error! (incorrectly formated Report Version)");
+         delete lines; lines = NULL;
+         AliError("Survey text file sintax error! (incorrectly formatted Report Version)");
          return kFALSE;
        }
        fVersion = nextLine.Atoi();
@@ -665,7 +675,6 @@ Bool_t AliSurveyObj::ParseBuffer(const Char_t* buf) {
          fObs += (0 == fObs.Length()) ? nextLine : " / " + nextLine;
          ++i;
          nextLine = ((i + 1) < nrLines ? ((TObjString *)(lines->At(i + 1)))->GetString().Data() : "");
-         nextLine = Sanitize(nextLine);
        }
       } else if (currLine.BeginsWith("Coordinate System", TString::kIgnoreCase)) {
        // Coordinate System
@@ -679,7 +688,8 @@ Bool_t AliSurveyObj::ParseBuffer(const Char_t* buf) {
        // Number of columns in the "Data" section
        if (!nextLine.IsDigit()) {
          lines->Delete();
-         AliError("Survey text file sintax error! (incorrectly formated Number of Columns)");
+         delete lines; lines = NULL;
+         AliError("Survey text file sintax error! (incorrectly formatted Number of Columns)");
          return kFALSE;
        }
        fNrColumns = nextLine.Atoi();
@@ -692,6 +702,7 @@ Bool_t AliSurveyObj::ParseBuffer(const Char_t* buf) {
          AliError("Survey text file sintax error! (Declared number of Columns doesn't match number of column names)");
          colLine->Delete();
          lines->Delete();
+         delete lines; lines = NULL;
          return kFALSE;
        }
        ++i;
@@ -790,19 +801,19 @@ Bool_t AliSurveyObj::ParseBuffer(const Char_t* buf) {
 
        // Check if all the mandatory fields exist in the line with column names
        if(!check[0]){
-         Printf("Missing mandatory column \"Point Name\"!");
+         AliError("Missing mandatory column \"Point Name\"!");
          return kFALSE;
        }
        if(!(check[1]&&check[2]&&check[3])){
-         Printf("Missing one or more mandatory columns for coordinates \"X\",\"Y\",\"Z\"");
+         AliError("Missing one or more mandatory columns for coordinates \"X\",\"Y\",\"Z\"");
          return kFALSE;
        }
        if(!check[4]){
-         Printf("Missing mandatory column \"Point Type\"!");
+         AliError("Missing mandatory column \"Point Type\"!");
          return kFALSE;
        }
        if(!(check[6]&&check[7]&&check[8])){
-         Printf("Missing one or more mandatory columns for precision along \"X\",\"Y\",\"Z\" axes");
+         AliError("Missing one or more mandatory columns for precision along \"X\",\"Y\",\"Z\" axes");
          return kFALSE;
        }
 
@@ -821,6 +832,7 @@ Bool_t AliSurveyObj::ParseBuffer(const Char_t* buf) {
            // Error (No separator was found!)
            AliError("Survey text file syntax error! Error processing data line!");
            lines->Delete();
+           delete lines; lines = NULL;
            return kFALSE;
          }
 
@@ -829,6 +841,7 @@ Bool_t AliSurveyObj::ParseBuffer(const Char_t* buf) {
            AliError("Survey text file sintax error! (Number of entries in line is different from number of Columns)");
            dataLine->Delete();
            lines->Delete();
+           delete lines; lines = NULL;
            return kFALSE;
          }
 
@@ -847,23 +860,24 @@ Bool_t AliSurveyObj::ParseBuffer(const Char_t* buf) {
          if(orderedValues[5]) tmptarg = (orderedValues[5]->Data()[0] == 'Y') ? kTRUE : kFALSE;
 
          dp = new AliSurveyPoint(tmpname, tmpx, tmpy, tmpz, tmpprecX, tmpprecY, tmpprecZ, tmptype, tmptarg);
-         dp->PrintPoint();
+         if(AliLog::GetDebugLevel("","AliSurveyObj")>1) dp->PrintPoint();
          AddPoint(dp);
 
          dataLine->Delete();
          dataLine = NULL;
          ++i;
          nextLine = ((i + 1) < nrLines ? ((TObjString *)(lines->At(i + 1)))->GetString().Data() : "");
-         nextLine = Sanitize(nextLine);
        }
       }
     } else {
       AliError("Survey text file sintax error!");
       lines->Delete();
+      delete lines; lines = NULL;
       return kFALSE;
     }
   }
   lines->Delete();
+  delete lines; lines = NULL;
   fIsValid = kTRUE;
   return kTRUE;
 }