]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - SHUTTLE/TestShuttle/AliTestShuttle.cxx
1) Storing of files to the Grid is now done _after_ your preprocessors succeeded...
[u/mrichter/AliRoot.git] / SHUTTLE / TestShuttle / AliTestShuttle.cxx
index 3baa641eb8a3f949359efa3415a8768714e5dfa1..9ce785149d93a56a863bed6f744f68fd29e3de7c 100644 (file)
 
 /*
 $Log$
+Revision 1.10  2007/02/28 10:41:01  acolla
+Run type field added in SHUTTLE framework. Run type is read from "run type" logbook and retrieved by
+AliPreprocessor::GetRunType() function.
+Added some ldap definition files.
+
+Revision 1.8  2007/02/13 11:22:25  acolla
+Shuttle getters and setters of main/local OCDB/Reference storages, temp and log
+folders moved to AliShuttleInterface
+
+Revision 1.6  2006/11/06 14:22:47  jgrosseo
+major update (Alberto)
+o) reading of run parameters from the logbook
+o) online offline naming conversion
+o) standalone DCSclient package
+
+Revision 1.5  2006/10/02 12:58:52  jgrosseo
+Small interface change in StoreReferenceData
+
+Revision 1.4  2006/08/08 14:19:07  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.3  2006/07/11 12:44:32  jgrosseo
+adding parameters for extended validity range of data produced by preprocessor
+
+Revision 1.2  2006/06/06 14:20:05  jgrosseo
+o) updated test preprocessor (alberto)
+o) added comments to example macro
+o) test shuttle implements new interface
+
 Revision 1.2  2006/03/07 07:52:34  hristov
 New version (B.Yordanov)
 
@@ -47,27 +83,39 @@ some docs added
 #include "AliLog.h"
 
 #include "AliCDBManager.h"
+#include "AliCDBStorage.h"
 #include "AliCDBMetaData.h"
+#include "AliCDBPath.h"
 #include "AliCDBId.h"
 #include "AliPreprocessor.h"
 
 #include <TMap.h>
 #include <TList.h>
-#include <TString.h>
 #include <TObjString.h>
+#include <TSystem.h>
 
 ClassImp(AliTestShuttle)
 
 //______________________________________________________________________________________________
-AliTestShuttle::AliTestShuttle() :
+AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
+  fRun(run),
+  fStartTime(startTime),
+  fEndTime(endTime),
   fInputFiles(0),
+  fRunParameters(0),
+  fRunType(),
   fPreprocessors(0),
   fDcsAliasMap(0)
 {
   // constructor
 
   fInputFiles = new TMap;
+  fRunParameters = new TMap;
   fPreprocessors = new TObjArray;
+
+  fInputFiles->SetOwner(1);
+  fRunParameters->SetOwner(1);
+  fPreprocessors->SetOwner(1);
 }
 
 //______________________________________________________________________________________________
@@ -78,6 +126,9 @@ AliTestShuttle::~AliTestShuttle()
   delete fInputFiles;
   fInputFiles = 0;
 
+  delete fRunParameters;
+  fRunParameters = 0;
+
   delete fPreprocessors;
   fPreprocessors = 0;
 
@@ -86,7 +137,8 @@ AliTestShuttle::~AliTestShuttle()
 }
 
 //______________________________________________________________________________________________
-UInt_t AliTestShuttle::Store(const char* detector, TObject* object, AliCDBMetaData* metaData)
+Bool_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
+                               Int_t validityStart, Bool_t validityInfinite)
 {
   // Stores the CDB object
   // This function should be called at the end of the preprocessor cycle
@@ -94,9 +146,81 @@ UInt_t AliTestShuttle::Store(const char* detector, TObject* object, AliCDBMetaDa
   // This implementation just stores it on the local disk, the full AliShuttle
   // puts it to the Grid FileCatalog
 
-  AliCDBId id(Form("%s/SHUTTLE/Data", detector), 0, 0);
+  Int_t startRun = fRun - validityStart;
+  if(startRun < 0) {
+       AliError("First valid run happens to be less than 0! Setting it to 0...");
+       startRun=0;
+  }
+
+  Int_t endRun = -1;
+  if(validityInfinite) {
+       endRun = AliCDBRunRange::Infinity();
+  } else {
+       endRun = fRun;
+  }
+
+  AliCDBId id(path, startRun, endRun);
+
+  return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
+}
+
+//______________________________________________________________________________________________
+Bool_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
+{
+  // Stores the object as reference data
+  // This function should be called at the end of the preprocessor cycle
+  //
+  // This implementation just stores it on the local disk, the full AliShuttle
+  // puts it to the Grid FileCatalog
+
+  AliCDBId id(path, fRun, fRun);
 
-  return AliCDBManager::Instance()->Put(object, id, metaData);
+  return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
+}
+
+//______________________________________________________________________________________________
+Bool_t AliTestShuttle::StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName)
+{
+       //
+       // Stores reference file directly (without opening it). 
+       //
+       // This implementation just stores it on the local disk, the full AliShuttle 
+       // puts it to the Grid FileCatalog
+       
+       AliCDBManager* man = AliCDBManager::Instance();
+       AliCDBStorage* sto = man->GetStorage(fgkMainRefStorage);
+       
+       TString localBaseFolder = sto->GetBaseFolder();
+       
+       TString targetDir;
+       targetDir.Form("%s/%s", localBaseFolder.Data(), detector);
+       
+       TString target;
+       target.Form("%s/%d_%s", targetDir.Data(), fRun, gridFileName);
+       
+       Int_t result = gSystem->GetPathInfo(targetDir, 0, (Long64_t*) 0, 0, 0);
+       if (result)
+       {
+               result = gSystem->mkdir(targetDir, kTRUE);
+               if (result != 0)
+               {
+                       Log("SHUTTLE", Form("StoreReferenceFile - Error creating base directory %s", targetDir.Data()));
+                       return kFALSE;
+               }
+       }
+               
+       result = gSystem->CopyFile(localFile, target);
+
+       if (result == 0)
+       {
+               Log("SHUTTLE", Form("StoreReferenceFile - Stored file %s locally to %s", localFile, target.Data()));
+               return kTRUE;
+       }
+       else
+       {
+               Log("SHUTTLE", Form("StoreReferenceFile - Storing file %s locally to %s failed with %d", localFile, target.Data(), result));
+               return kFALSE;
+       }               
 }
 
 //______________________________________________________________________________________________
@@ -197,6 +321,36 @@ void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char
   sourceList->Add(new TObjString(source), new TObjString(fileName));
 }
 
+//______________________________________________________________________________________________
+Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry)
+{
+  // This function adds an object in the OCDB to be later retrieved with GetFromOCDB
+
+       AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
+       if (!sto)
+       {
+               Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
+               return 0;
+       }
+
+       return sto->Put(entry);
+}
+
+//______________________________________________________________________________________________
+AliCDBEntry* AliTestShuttle::GetFromOCDB(const char* detector, const AliCDBPath& path)
+{
+// returns obiect from OCDB valid for current run
+
+       AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
+       if (!sto)
+       {
+               Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
+               return 0;
+       }
+
+       return (AliCDBEntry*) sto->Get(path, fRun);
+}
+
 //______________________________________________________________________________________________
 void AliTestShuttle::Process()
 {
@@ -208,7 +362,7 @@ void AliTestShuttle::Process()
     AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
     if (preprocessor)
     {
-      preprocessor->Initialize(0, 1, 0);
+      preprocessor->Initialize(fRun, fStartTime, fEndTime);
       preprocessor->Process(fDcsAliasMap);
     }
   }
@@ -219,5 +373,65 @@ void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
 {
   // registers a preprocessor
 
-  fPreprocessors->Add(preprocessor);
+       const char* detName = preprocessor->GetName();
+       if(strcmp("DET", detName) != 0) {
+               if(GetDetPos(detName) < 0)
+                       AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName));
+       }
+
+       fPreprocessors->Add(preprocessor);
+}
+
+//______________________________________________________________________________________________
+void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
+// set a run parameter (in reality it will be read from the DAQ logbook)
+
+       TObjString* keyObj = new TObjString(key);
+       if (fRunParameters->Contains(key)) {
+               AliWarning(Form("Parameter %s already existing and it will be replaced.", key));
+               delete fRunParameters->Remove(keyObj);
+
+       }
+       fRunParameters->Add(keyObj, new TObjString(value));
+       AliDebug(2, Form("Number of parameters: %d", fRunParameters->
+       GetEntries()));
+}
+
+//______________________________________________________________________________________________
+const char* AliTestShuttle::GetRunType()
+{
+       //
+       // get a run parameter
+       //
+
+       return fRunType;
 }
+
+//______________________________________________________________________________________________
+const char* AliTestShuttle::GetRunParameter(const char* key){
+// get a run parameter
+
+       TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
+       if(!value) {
+               AliError(Form("No such parameter: %s", key));
+               return 0;
+       }
+       return value->GetName();
+}
+
+//______________________________________________________________________________________________
+void AliTestShuttle::SetShuttleTempDir(const char* tmpDir)
+{
+// sets Shuttle temp directory
+
+       fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir);
+}
+
+//______________________________________________________________________________________________
+void AliTestShuttle::SetShuttleLogDir(const char* logDir)
+{
+// sets Shuttle log directory
+
+       fgkShuttleLogDir = gSystem->ExpandPathName(logDir);
+}
+