]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - SHUTTLE/AliShuttle.cxx
Changed default point-size in accordance with the new convention.
[u/mrichter/AliRoot.git] / SHUTTLE / AliShuttle.cxx
index 6e7fef84cd606cef4c307fab0ab343ee1d4305a9..ac00f3050da14f9e4f814caa32ca7542af9bd8ce 100644 (file)
 
 /*
 $Log$
+Revision 1.13  2006/08/15 10:50:00  jgrosseo
+effc++ corrections (alberto)
+
+Revision 1.12  2006/08/08 14:19:29  jgrosseo
+Update to shuttle classes (Alberto)
+
+- Possibility to set the full object's path in the Preprocessor's and
+Shuttle's  Store functions
+- Possibility to extend the object's run validity in the same classes
+("startValidity" and "validityInfinite" parameters)
+- Implementation of the StoreReferenceData function to store reference
+data in a dedicated CDB storage.
+
 Revision 1.11  2006/07/21 07:37:20  jgrosseo
 last run is stored after each run
 
@@ -115,10 +128,14 @@ some docs added
 
 ClassImp(AliShuttle)
 
+TString AliShuttle::fgkMainCDB("alien://DBFolder=ShuttleCDB");
 TString AliShuttle::fgkLocalCDB("local://LocalShuttleCDB");
 TString AliShuttle::fgkMainRefStorage("alien://DBFolder=ShuttleReference");
 TString AliShuttle::fgkLocalRefStorage("local://LocalReferenceStorage");
 
+Bool_t AliShuttle::fgkProcessDCS(kTRUE); 
+
+
 const char* AliShuttle::fgkShuttleTempDir = gSystem->ExpandPathName("$ALICE_ROOT/SHUTTLE/temp");
 const char* AliShuttle::fgkShuttleLogDir = gSystem->ExpandPathName("$ALICE_ROOT/SHUTTLE/log");
 
@@ -131,10 +148,14 @@ const char* AliShuttle::fgkDetectorCode[AliShuttle::fgkNDetectors] = {"SPD", "SD
 //______________________________________________________________________________________________
 AliShuttle::AliShuttle(const AliShuttleConfig* config,
                UInt_t timeout, Int_t retries):
-       fConfig(config),
-       fTimeout(timeout),
-       fRetries(retries), fCurrentRun(-1), fCurrentStartTime(0),
-       fCurrentEndTime(0), fStatusEntry(0)
+fConfig(config),
+fTimeout(timeout), fRetries(retries),
+fPreprocessorMap(),
+fCurrentRun(-1),
+fCurrentStartTime(0), fCurrentEndTime(0),
+fCurrentDetector(""),
+fStatusEntry(0),
+fGridError(kFALSE)
 {
        //
        // config: AliShuttleConfig used
@@ -151,7 +172,15 @@ AliShuttle::AliShuttle(const AliShuttleConfig* config,
 
 //______________________________________________________________________
 AliShuttle::AliShuttle(const AliShuttle& /*other*/):
-AliShuttleInterface()
+AliShuttleInterface(),
+fConfig(0),
+fTimeout(0), fRetries(0),
+fPreprocessorMap(),
+fCurrentRun(-1),
+fCurrentStartTime(0), fCurrentEndTime(0),
+fCurrentDetector(""),
+fStatusEntry(0),
+fGridError(kFALSE)
 {
 // copy constructor (not implemented)
 
@@ -204,60 +233,10 @@ UInt_t AliShuttle::Store(const AliCDBPath& path, TObject* object,
   // Stores a CDB object in the storage for offline reconstruction. Objects that are not needed for
   // offline reconstruction, but should be stored anyway (e.g. for debugging) should NOT be stored
   // using this function. Use StoreReferenceData instead!
-  //
-
-  // The parameters are
-  //   1) the object's path.
-  //   2) the object to be stored
-  //   3) the metaData to be associated with the object
-  //   4) the validity start run number w.r.t. the current run,
-  //      if the data is valid only for this run leave the default 0
-  //   5) specifies if the calibration data is valid for infinity (this means until updated),
-  //      typical for calibration runs, the default is kFALSE
-  //
-  //
-  // returns 0 if fail
-  //        1 if stored in main (Grid) CDB storage
-  //        2 if stored in backup (Local) CDB storage
-
-
-       Int_t firstRun = GetCurrentRun() - validityStart;
-       if(firstRun < 0) {
-               AliError("First valid run happens to be less than 0! Setting it to 0...");
-               firstRun=0;
-       }
+  // It calls WriteToCDB function which perform actual storage
 
-       Int_t lastRun = -1;
-       if(validityInfinite) {
-               lastRun = AliCDBRunRange::Infinity();
-       } else {
-               lastRun = GetCurrentRun();
-       }
-
-       AliCDBId id(path, firstRun, lastRun);
-
-       UInt_t result = 0;
-
-       if (!(AliCDBManager::Instance()->IsDefaultStorageSet())) {
-               Log(fCurrentDetector, "No CDB storage set!");
-       } else {
-               result = (UInt_t) AliCDBManager::Instance()->Put(object, id, metaData);
-       }
-       if(!result) {
-
-               Log(fCurrentDetector,
-                       "Error while storing object in main storage: it will go to local storage!");
-
-               result = AliCDBManager::Instance()->GetStorage(fgkLocalCDB)
-                                       ->Put(object, id, metaData);
-
-               if(result) {
-                       result = 2;
-               }else{
-                       Log(fCurrentDetector, "Can't store data!");
-               }
-       }
-       return result;
+       return WriteToCDB(fgkMainCDB, fgkLocalCDB, path, object,
+                               metaData, validityStart, validityInfinite);
 
 }
 
@@ -267,23 +246,37 @@ UInt_t AliShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object,
 {
   // Stores a CDB object in the storage for reference data. This objects will not be available during
   // offline reconstrunction. Use this function for reference data only!
-  //
+  // It calls WriteToCDB function which perform actual storage
+
+       return WriteToCDB(fgkMainRefStorage, fgkLocalRefStorage, path, object,
+                               metaData, validityStart, validityInfinite);
 
-  // The parameters are
-  //   1) the object's path.
-  //   2) the object to be stored
-  //   3) the metaData to be associated with the object
-  //   4) the validity start run number w.r.t. the current run,
+}
+
+//______________________________________________________________________________________________
+UInt_t AliShuttle::WriteToCDB(const char* mainUri, const char* localUri,
+                       const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
+                       Int_t validityStart, Bool_t validityInfinite)
+{
+  // write object into the CDB. Parameters are passed by Store and StoreReferenceData functions.
+  // The parameters are:
+  //   1) Uri of the main storage (Grid)
+  //   2) Uri of the backup storage (Local)
+  //   3) the object's path.
+  //   4) the object to be stored
+  //   5) the metaData to be associated with the object
+  //   6) the validity start run number w.r.t. the current run,
   //      if the data is valid only for this run leave the default 0
-  //   5) specifies if the calibration data is valid for infinity (this means until updated),
+  //   7) specifies if the calibration data is valid for infinity (this means until updated),
   //      typical for calibration runs, the default is kFALSE
   //
-  //
   // returns 0 if fail
-  //        1 if stored in main (Grid) reference storage
-  //        2 if stored in backup (Local) reference storage
+  //        1 if stored in main (Grid) storage
+  //        2 if stored in backup (Local) storage
 
-       Int_t firstRun = GetCurrentRun() - validityStart;
+       const char* cdbType = (mainUri == fgkMainCDB) ? "CDB" : "Reference";
+       
+       Int_t firstRun = GetCurrentRun() - validityStart;
        if(firstRun < 0) {
                AliError("First valid run happens to be less than 0! Setting it to 0...");
                firstRun=0;
@@ -296,29 +289,30 @@ UInt_t AliShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object,
                lastRun = GetCurrentRun();
        }
 
-       AliCDBId id(path, firstRun, lastRun);
+       AliCDBId id(path, firstRun, lastRun);
 
        UInt_t result = 0;
 
-       if (!(AliCDBManager::Instance()->GetStorage(fgkMainRefStorage))) {
-               Log(fCurrentDetector, "Cannot activate main reference storage!");
+       if (!(AliCDBManager::Instance()->GetStorage(mainUri))) {
+               Log(fCurrentDetector, Form("Cannot activate main %s storage!", cdbType));
        } else {
-               result = (UInt_t) AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)
+               result = (UInt_t) AliCDBManager::Instance()->GetStorage(mainUri)
                                        ->Put(object, id, metaData);
        }
 
        if(!result) {
 
                Log(fCurrentDetector,
-                       "Error while storing object in main reference storage: it will go to local ref storage!");
+                       Form("Problem with main %s storage. Object will go to local storage!", cdbType));
 
-               result = AliCDBManager::Instance()->GetStorage(fgkLocalRefStorage)
+               result = AliCDBManager::Instance()->GetStorage(localUri)
                                        ->Put(object, id, metaData);
 
                if(result) {
                        result = 2;
+                       fGridError = kTRUE;
                }else{
-                       Log(fCurrentDetector, "Can't store reference data!");
+                       Log(fCurrentDetector, "Can't store data!");
                }
        }
        return result;
@@ -438,6 +432,13 @@ Bool_t AliShuttle::ContinueProcessing()
     return kFALSE;
   }
 
+  // TODO what to do in case of storage error? currently it does not do anything
+  if (status->GetStatus() == AliShuttleStatus::kStoreFailed)
+  {
+    Log("SHUTTLE", Form("%s: Grid storage failed at least once for run %d", fCurrentDetector.Data(), fCurrentRun));
+    return kFALSE;
+  }
+
   // if we get here, there is a restart
 
   // abort conditions
@@ -469,7 +470,7 @@ Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime)
        // Returns kFALSE in case of error occured and kTRUE otherwise
        //
 
-       AliInfo(Form("\n\n ^*^*^*^*^*^* Processing run %d ^*^*^*^*^*^*", run));
+       AliInfo(Form("\n\n \t\t\t^*^*^*^*^*^*^*^*^*^*^*^* run %d: START ^*^*^*^*^*^*^*^*^*^*^*^* \n", run));
 
        // Initialization
        Bool_t hasError = kFALSE;
@@ -491,12 +492,14 @@ Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime)
 
                if (ContinueProcessing() == kFALSE) continue;
 
+               AliInfo(Form("\n\n \t\t\t****** %s: START  ******", aDetector->GetName()));
+
                if(!Process()) {
                        hasError = kTRUE;
                        detectorError=kTRUE;
                        continue;
                }
-               AliInfo(Form("Process ended successfully for detector %s!",aDetector->GetName()));
+               AliInfo(Form("\n \t\t\t****** %s: FINISH ****** \n\n", aDetector->GetName()));
 
                // Process successful: Update time_processed field in FES logbooks!
                if(fFESCalled[kDAQ]) {
@@ -512,13 +515,15 @@ Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime)
                //      fFESlist[kHLT].Clear();
                //}
 
-               UpdateShuttleStatus(AliShuttleStatus::kDone);
+               // UpdateShuttleStatus(AliShuttleStatus::kDone);
        }
 
        fCurrentRun = -1;
        fCurrentStartTime = 0;
        fCurrentEndTime = 0;
 
+       AliInfo(Form("\n\n \t\t\t^*^*^*^*^*^*^*^*^*^*^*^* run %d: FINISH ^*^*^*^*^*^*^*^*^*^*^*^* \n", run));
+
        return hasError == kFALSE;
 }
 
@@ -552,39 +557,46 @@ Bool_t AliShuttle::Process()
        TObjString* anAlias;
        TMap aliasMap;
 
-       Bool_t hasError = kFALSE;
-       Bool_t result=kFALSE;
+       Bool_t aDCSError = kFALSE;
+       fGridError = kFALSE;
+       UInt_t aPPResult;
 
        while ((anAlias = (TObjString*) iter.Next())) {
                TObjArray valueSet;
-               //result = GetValueSet(host, port, anAlias->String(), valueSet);
-               AliInfo(Form("Port = %d",port));
-               result = kTRUE;
-               if(result) {
+               // TODO Test only... I've added a flag that allows to
+               // exclude DCS archive DB query
+               if(fgkProcessDCS){
+                       AliInfo("Querying DCS archive DB data...");
+                       aDCSError = (GetValueSet(host, port, anAlias->String(), valueSet) == 0);
+               } else {
+                       AliInfo(Form("Skipping DCS processing. Port = %d",port));
+                       aDCSError = kFALSE;
+               }
+               if(!aDCSError) {
                        aliasMap.Add(anAlias->Clone(), valueSet.Clone());
                }else{
                        TString message = Form("Error while retrieving alias %s !",
                                        anAlias->GetName());
                        Log(fCurrentDetector, message.Data());
-                       hasError = kTRUE;
+                       aDCSError = kTRUE;
                        break;
                }
        }
 
-       if (hasError)
+       if (aDCSError)
        {
                UpdateShuttleStatus(AliShuttleStatus::kDCSError);
                return kFALSE;
        }
 
-  UpdateShuttleStatus(AliShuttleStatus::kPPStarted);
+       UpdateShuttleStatus(AliShuttleStatus::kPPStarted);
 
-  AliPreprocessor* aPreprocessor =
+       AliPreprocessor* aPreprocessor =
                dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(fCurrentDetector));
        if(aPreprocessor)
        {
                aPreprocessor->Initialize(fCurrentRun, fCurrentStartTime, fCurrentEndTime);
-               hasError = (aPreprocessor->Process(&aliasMap) == 0);
+               aPPResult = aPreprocessor->Process(&aliasMap);
        }else{
     // TODO default behaviour?
                AliInfo(Form("No Preprocessor for %s: storing TMap of DP arrays into CDB!", fCurrentDetector.Data()));
@@ -594,17 +606,20 @@ Bool_t AliShuttle::Process()
                metaData.SetProperty("StartEndTime", &dcsValue);
                metaData.SetComment("Automatically stored by Shuttle!");
                AliCDBPath path(fCurrentDetector,"DCS","Data");
-               hasError = (Store(path, &aliasMap, &metaData) == 0);
+               aPPResult = Store(path, &aliasMap, &metaData);
        }
 
-  if (hasError)
-    UpdateShuttleStatus(AliShuttleStatus::kPPError);
-  else
-    UpdateShuttleStatus(AliShuttleStatus::kPPDone);
+       if (aPPResult == 0) { // Preprocessor error
+               UpdateShuttleStatus(AliShuttleStatus::kPPError);
+       } else if (fGridError == kFALSE) { // process and Grid storage ok!
+               UpdateShuttleStatus(AliShuttleStatus::kDone);
+        } else { // Grid storage error (process ok, but object put in local storage)
+               UpdateShuttleStatus(AliShuttleStatus::kStoreFailed);
+       }
 
-       aliasMap.Delete();
+       aliasMap.Delete();
 
-       return hasError == kFALSE;
+       return (aPPResult > 0);
 }
 
 //______________________________________________________________________________________________
@@ -1040,7 +1055,7 @@ void AliShuttle::Log(const char* detector, const char* message)
                gSystem->FreeDirectory(dir);
        }
 
-       TString toLog = Form("%s: %s, run %d - %s", TTimeStamp(time(0)).AsString(),
+       TString toLog = Form("%s: %s, run %d - %s", TTimeStamp(time(0)).AsString("s"),
        detector, GetCurrentRun(), message);
        AliInfo(toLog.Data());