]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - SHUTTLE/TestShuttle/AliTestShuttle.cxx
- adding some logging
[u/mrichter/AliRoot.git] / SHUTTLE / TestShuttle / AliTestShuttle.cxx
index 2fc67aa1b51053c790b11f758978017dbf2a2951..7718f95a149763aeddc29eb3fc63c7d976c39dd1 100644 (file)
 
 /*
 $Log$
+Revision 1.14  2007/08/06 12:25:47  acolla
+Function Bool_t GetHLTStatus added to preprocessor. It returns the status of HLT
+read from the run logbook.
+TestShuttle setup updated.
+TRD data point configuration updated.
+
+Revision 1.13  2007/05/30 06:35:21  jgrosseo
+Adding functionality to the Shuttle/TestShuttle:
+o) Function to retrieve list of sources from a given system (GetFileSources with id=0)
+o) Function to retrieve list of IDs for a given source      (GetFileIDs)
+These functions are needed for dealing with the tag files that are saved for the GRP preprocessor
+Example code has been added to the TestProcessor in TestShuttle
+
+Revision 1.12  2007/04/27 07:06:48  jgrosseo
+GetFileSources returns empty list in case of no files, but successful query
+No mails sent in testmode
+
+Revision 1.11  2007/04/04 10:33:36  jgrosseo
+1) Storing of files to the Grid is now done _after_ your preprocessors succeeded. This is transparent, which means that you can still use the same functions (Store, StoreReferenceData) to store files to the Grid. However, the Shuttle first stores them locally and transfers them after the preprocessor finished. The return code of these two functions has changed from UInt_t to Bool_t which gives you the success of the storing.
+In case of an error with the Grid, the Shuttle will retry the storing later, the preprocessor does not need to be run again.
+
+2) The meaning of the return code of the preprocessor has changed. 0 is now success and any other value means failure. This value is stored in the log and you can use it to keep details about the error condition.
+
+3) New function StoreReferenceFile to _directly_ store a file (without opening it) to the reference storage.
+
+4) The memory usage of the preprocessor is monitored. If it exceeds 2 GB it is terminated.
+
+5) New function AliPreprocessor::ProcessDCS(). If you do not need to have DCS data in all cases, you can skip the processing by implemting this function and returning kFALSE under certain conditions. E.g. if there is a certain run type.
+If you always need DCS data (like before), you do not need to implement it.
+
+6) The run type has been added to the monitoring page
+
+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
@@ -84,30 +125,35 @@ some docs added
 #include <TList.h>
 #include <TObjString.h>
 #include <TSystem.h>
+#include <TTimeStamp.h>
 
 ClassImp(AliTestShuttle)
 
-TString AliTestShuttle::fgkMainCDB("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
-TString AliTestShuttle::fgkMainRefStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestReference");
-
-TString AliTestShuttle::fgkShuttleTempDir = gSystem->ExpandPathName("$ALICE_ROOT/SHUTTLE/TestShuttle/temp");
-TString AliTestShuttle::fgkShuttleLogDir = gSystem->ExpandPathName("$ALICE_ROOT/SHUTTLE/TestShuttle/log");
-
 //______________________________________________________________________________________________
 AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
   fRun(run),
   fStartTime(startTime),
   fEndTime(endTime),
+  fTimeCreated(startTime),
+  fDCSQueryOffset(0),
   fInputFiles(0),
   fRunParameters(0),
+  fRunType(),
   fPreprocessors(0),
-  fDcsAliasMap(0)
+  fDcsAliasMap(0),
+  fTriggerConfiguration(""),
+  fTriggerDetectorMask(""),
+  fCTPtiming("")
 {
   // constructor
 
   fInputFiles = new TMap;
   fRunParameters = new TMap;
   fPreprocessors = new TObjArray;
+
+  fInputFiles->SetOwner(1);
+  fRunParameters->SetOwner(1);
+  fPreprocessors->SetOwner(1);
 }
 
 //______________________________________________________________________________________________
@@ -129,7 +175,7 @@ AliTestShuttle::~AliTestShuttle()
 }
 
 //______________________________________________________________________________________________
-UInt_t AliTestShuttle::Store(const AliCDBPath& path, 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
@@ -157,7 +203,7 @@ UInt_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMeta
 }
 
 //______________________________________________________________________________________________
-UInt_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* 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
@@ -170,6 +216,131 @@ UInt_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* objec
   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(fgkLocalRefStorage);
+       
+       TString localBaseFolder = sto->GetBaseFolder();
+       
+       TString targetDir = GetRefFilePrefix(localBaseFolder.Data(), detector); 
+       
+       return CopyFileLocally(targetDir, localFile, gridFileName);
+}
+
+//______________________________________________________________________________________________
+Bool_t AliTestShuttle::StoreRunMetadataFile(const char* localFile, const char* gridFileName)
+{
+       //
+       // Stores Run metadata file to the Grid, in the run folder
+       //
+       // Only GRP can call this function.
+       
+       AliCDBManager* man = AliCDBManager::Instance();
+       AliCDBStorage* sto = man->GetStorage(fgkLocalRefStorage);
+       
+       TString localBaseFolder = sto->GetBaseFolder();
+       
+       // Build Run level folder
+       // folder = /alice/data/year/lhcPeriod/runNb/Raw
+       
+       TTimeStamp startTime(fStartTime);
+               
+       TString year =  Form("%d",startTime.GetDate());
+       year = year(0,4);
+               
+       TString lhcPeriod = GetRunParameter("LHCperiod");
+       
+       if (lhcPeriod.Length() == 0) 
+       {
+               Log("SHUTTLE","StoreRunMetaDataFile - LHCPeriod not found in logbook!");
+               return 0;
+       }
+       
+       // TODO: currently SHUTTLE cannot write in /alice/data/ !!!!!
+       //TString targetDir = Form("%s/GRP/RunMetadata/alice/data/%s/%s/%d/Raw", 
+       //                      localBaseFolder.Data(), year.Data(), 
+       //                      lhcPeriod.Data(), fRun);
+       
+       TString targetDir = Form("%s/GRP/RunMetadata/alice/simulation/%s/%s/%d/Raw", 
+                               localBaseFolder.Data(), year.Data(), 
+                               lhcPeriod.Data(), fRun);
+                                       
+       return CopyFileLocally(targetDir, localFile, gridFileName);
+}
+
+//______________________________________________________________________________________________
+Bool_t AliTestShuttle::CopyFileLocally(TString& targetDir, const char* localFile, const char* gridFileName)
+{
+       //
+       // Stores file locally. Called by StoreReferenceFile and StoreRunMetadataFile
+       //
+       
+       //try to open folder, if it does not exist
+       void* dir = gSystem->OpenDirectory(targetDir.Data());
+       if (dir == NULL) {
+               if (gSystem->mkdir(targetDir.Data(), kTRUE)) {
+                       Log("SHUTTLE", Form("StoreFileLocally - Can't open directory <%s>", targetDir.Data()));
+                       return kFALSE;
+               }
+
+       } else {
+               gSystem->FreeDirectory(dir);
+       }
+
+       TString target = Form("%s/%s", targetDir.Data(), gridFileName);
+       
+       Int_t result = gSystem->GetPathInfo(localFile, 0, (Long64_t*) 0, 0, 0);
+       if (result)
+       {
+               Log("SHUTTLE", Form("StoreFileLocally - %s does not exist", localFile));
+               return kFALSE;
+       }
+
+       result = gSystem->CopyFile(localFile, target);
+
+       if (result == 0)
+       {
+               Log("SHUTTLE", Form("StoreFileLocally - File %s stored locally to %s", localFile, target.Data()));
+               return kTRUE;
+       }
+       else
+       {
+               Log("SHUTTLE", Form("StoreFileLocally - Could not store file %s to %s!. Error code = %d", 
+                               localFile, target.Data(), result));
+               return kFALSE;
+       }       
+
+
+
+}
+
+//______________________________________________________________________________________________
+const char* AliTestShuttle::GetRefFilePrefix(const char* base, const char* detector)
+{
+       //
+       // Get folder name of reference files 
+       //
+
+       TString offDetStr(GetOfflineDetName(detector));
+       static TString dir;
+       if (offDetStr == "ITS" || offDetStr == "MUON" || offDetStr == "PHOS")
+       {
+               dir.Form("%s/%s/%s", base, offDetStr.Data(), detector);
+       } else {
+               dir.Form("%s/%s", base, offDetStr.Data());
+       }
+       
+       return dir.Data();
+}
+
 //______________________________________________________________________________________________
 const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
 {
@@ -192,8 +363,10 @@ const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const ch
     return 0;
   }
 
+  TObjString* fileName = 0;
   TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
-  TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
+  if (fileNamePair)
+       fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
   if (!fileName)
   {
     AliError(Form("Could not find files from source %s in %s with id %s",
@@ -213,46 +386,143 @@ TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const
   // takes files from the local disks, files are passen in a TMap in the constructor
 
   TString key;
-  key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
-  TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
-  TMap* sourceList = 0;
-  if (sourceListPair)
-    sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
-  if (!sourceList)
+  if (id)
+    key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
+  else
+    key.Form("%s-%s", fkSystemNames[system], detector);
+  
+  TList* list = new TList;
+  
+  TIterator* iter = fInputFiles->MakeIterator();
+  TObject* obj = 0;
+  while ((obj = iter->Next()))
   {
-    AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
-    return 0;
+       TObjString* objStr = dynamic_cast<TObjString*> (obj);
+       if (objStr)
+       {
+               Bool_t found = kFALSE;
+               if (id)
+               {
+                       found = (objStr->String().CompareTo(key) == 0);
+               }
+               else
+                       found = objStr->String().BeginsWith(key);
+               
+               if (found)
+               {
+                       TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
+                       TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
+       
+                       TIterator* iter2 = sourceList->GetTable()->MakeIterator();
+                       TObject* obj2 = 0;
+                       while ((obj2 = iter2->Next()))
+                       {
+                               TPair* pair = dynamic_cast<TPair*> (obj2);
+                               if (pair)
+                               {
+                                       if (!list->FindObject(pair->Key()))
+                                               list->Add(new TObjString(pair->Key()->GetName()));
+                               }
+                       }
+                       
+                       delete iter2;
+               }
+       }
   }
+  
+  if (list->GetEntries() == 0)
+    AliInfo(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
+  
+  return list;
+}
 
-  TIterator* iter = sourceList->GetTable()->MakeIterator();
-  TObject* obj = 0;
+//______________________________________________________________________________________________
+TList* AliTestShuttle::GetFileIDs(Int_t system, const char* detector, const char* source)
+{
+  // Returns a list of ids in a given system that saved a file with the given source
+  //
+  // test implementation of GetFileSources
+  // takes files from the local disks, files are passen in a TMap in the constructor
+
+
+  TString key;
+  key.Form("%s-%s", fkSystemNames[system], detector);
+  
   TList* list = new TList;
+  
+  TIterator* iter = fInputFiles->MakeIterator();
+  TObject* obj = 0;
   while ((obj = iter->Next()))
   {
-    TPair* pair = dynamic_cast<TPair*> (obj);
-    if (pair)
-      list->Add(pair->Key());
+       TObjString* objStr = dynamic_cast<TObjString*> (obj);
+       if (objStr)
+       {
+               if (objStr->String().BeginsWith(key))
+               {
+                       Bool_t found = kFALSE;
+               
+                       TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
+                       TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
+       
+                       TIterator* iter2 = sourceList->GetTable()->MakeIterator();
+                       TObject* obj2 = 0;
+                       while ((obj2 = iter2->Next()))
+                       {
+                               TPair* pair = dynamic_cast<TPair*> (obj2);
+                               if (pair)
+                               {
+                                       if (strcmp(pair->Key()->GetName(), source) == 0)
+                                               found = kTRUE;
+                               }
+                       }
+                       
+                       delete iter2;
+                       
+                       if (found)
+                       {
+                               TObjArray* tokens = objStr->String().Tokenize("-");
+                               if (tokens->GetEntries() == 3)
+                               {
+                                       TObjString* id = dynamic_cast<TObjString*> (tokens->At(2));
+                                       if (id && !list->FindObject(id->String()))
+                                               list->Add(new TObjString(id->String()));
+                               }
+                               
+                               delete tokens;
+       
+                       }
+               }
+       }
   }
-
-  delete iter;
-
+  
+  if (list->GetEntries() == 0)
+    AliInfo(Form("Could not find any file in %s with source %s (%s)", fkSystemNames[system], source, key.Data()));
+  
   return list;
 }
 
 //______________________________________________________________________________________________
-void AliTestShuttle::Log(const char* detector, const char* message)
+void AliTestShuttle::Log(const char* detector, const char* message, UInt_t level)
 {
   // test implementation of Log
   // just prints to the screen
 
-  AliInfo(Form("%s: %s", detector, message));
+  TString fullMessage = detector;
+  fullMessage.Append(Form(": %s",message));
+  AliLog::Message(level, fullMessage, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__);
 }
 
 //______________________________________________________________________________________________
 void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
 {
+  //
   // This function adds a file to the list of input files
-
+  // the list is stored in fInputFiles 
+  // fInputFiles: TMap (key -> value)
+  //    <system>-<detector>-<id> -> TMap (key -> value)
+  //                                <source> -> <filename>
+  //  
+  
   TString key;
   key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
   TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
@@ -268,6 +538,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()
 {
@@ -279,8 +579,12 @@ void AliTestShuttle::Process()
     AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
     if (preprocessor)
     {
-      preprocessor->Initialize(fRun, fStartTime, fEndTime);
-      preprocessor->Process(fDcsAliasMap);
+      if (preprocessor->ProcessRunType())
+             {
+                     preprocessor->Initialize(fRun, fStartTime, fEndTime);
+                     preprocessor->Process(fDcsAliasMap);
+             }
+      
     }
   }
 }
@@ -294,7 +598,7 @@ void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
        if(strcmp("DET", detName) != 0) {
                if(GetDetPos(detName) < 0)
                        AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName));
-               }
+       }
 
        fPreprocessors->Add(preprocessor);
 }
@@ -314,6 +618,16 @@ void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
        GetEntries()));
 }
 
+//______________________________________________________________________________________________
+const char* AliTestShuttle::GetRunType()
+{
+       //
+       // get a run parameter
+       //
+
+       return fRunType.Data();
+}
+
 //______________________________________________________________________________________________
 const char* AliTestShuttle::GetRunParameter(const char* key){
 // get a run parameter
@@ -342,3 +656,48 @@ void AliTestShuttle::SetShuttleLogDir(const char* logDir)
        fgkShuttleLogDir = gSystem->ExpandPathName(logDir);
 }
 
+//______________________________________________________________________________________________
+const char* AliTestShuttle::GetTriggerConfiguration()
+{
+       //returns trigger configuration
+       if (fTriggerConfiguration.Length()>0){
+               return fTriggerConfiguration;
+       }
+       return NULL;
+}
+//______________________________________________________________________________________________
+const char* AliTestShuttle::GetCTPTimeParams()
+{
+       //returns trigger configuration
+       if (fCTPtiming.Length()>0){
+               return fCTPtiming;
+       }
+       return NULL;
+}
+//______________________________________________________________________________________________
+const char* AliTestShuttle::GetTriggerDetectorMask()
+{
+       //returns trigger detector mask
+       if (fTriggerDetectorMask.Length()>0){
+               return fTriggerDetectorMask;
+       }
+       return NULL;
+}
+//______________________________________________________________________________________________
+UInt_t AliTestShuttle::GetStartTimeDCSQuery()
+{
+       // Return Start Time for the DCS query
+       //
+       // The call is delegated to AliShuttleInterface
+
+       return fTimeCreated-fDCSQueryOffset;
+}
+//______________________________________________________________________________________________
+UInt_t AliTestShuttle::GetEndTimeDCSQuery()
+{
+       // Return End Time for the DCS query
+       //
+       // The call is delegated to AliShuttleInterface
+
+       return fEndTime+fDCSQueryOffset;
+}