]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - SHUTTLE/TestShuttle/AliTestPreprocessor.cxx
new EMCal tasks for PA analysis
[u/mrichter/AliRoot.git] / SHUTTLE / TestShuttle / AliTestPreprocessor.cxx
index 40cb519e95ed39c36245220df313d9607d7be054..cbc503357a10fe9583c040537d6e72d97a8fdc6a 100644 (file)
@@ -1,11 +1,14 @@
 #include "AliTestPreprocessor.h"
 
 #include "AliCDBMetaData.h"
+#include "AliCDBEntry.h"
 #include "AliDCSValue.h"
 #include "AliLog.h"
 #include "AliTestDataDCS.h"
 
 #include <TTimeStamp.h>
+#include <TObjString.h>
+#include <TList.h>
 
 //
 // This class is an example for a simple preprocessor.
@@ -21,6 +24,9 @@ AliTestPreprocessor::AliTestPreprocessor(AliShuttleInterface* shuttle) :
   fData(0)
 {
   // constructor
+  
+  AddRunType("PHYSICS");
+  AddRunType("CALIBRATION");
 }
 
 //______________________________________________________________________________________________
@@ -37,37 +43,155 @@ void AliTestPreprocessor::Initialize(Int_t run, UInt_t startTime,
 
   AliPreprocessor::Initialize(run, startTime, endTime);
 
-       AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
+       Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
                TTimeStamp(startTime).AsString(),
                TTimeStamp(endTime).AsString()));
 
        fData = new AliTestDataDCS(fRun, fStartTime, fEndTime);
 }
 
+//______________________________________________________________________________________________
+Bool_t AliTestPreprocessor::ProcessDCS()
+{
+       //
+       // decide here if DCS data is to be processed
+       //
+       
+       // TODO implement a decision, e.g. based on the run type
+       // In this example: Skip DCS if run type is CALIB
+       if (strcmp(GetRunType(), "CALIB") == 0)
+               return kFALSE;
+       
+       return kTRUE;
+}
+
 //______________________________________________________________________________________________
 UInt_t AliTestPreprocessor::Process(TMap* dcsAliasMap)
 {
   // Fills data into a AliTestDataDCS object
 
   if (!dcsAliasMap)
-    return 0;
+  {
+       Log("ERROR: No DCS map provided by SHUTTLE!");
+       return 1;
+  }
 
   // The processing of the DCS input data is forwarded to AliTestDataDCS
-       fData->ProcessData(*dcsAliasMap);
+  fData->ProcessData(*dcsAliasMap);
+
+  // Example of how to retrieve the run type from the Shuttle, using GetRunType() function
+  // TODO Here the run type for the "DET" detector must be set manually with SetInputRunType function,
+  // in reality it will be read from the "run type" logbook!
+  TString runType = GetRunType();
+  Log(Form("Run type for run %d: %s", fRun, runType.Data()));
+
+  // Example of how to retrieve the list of sources that produced the file with id DRIFTVELOCITY
+  TList* sourceList = GetFileSources(kDAQ, "DRIFTVELOCITY");
+  sourceList = GetFileSources(kHLT, "HLTData");
+  if (!sourceList)
+  {
+       Log("Error retrieving list of sources from FXS!");
+       return 1;
+  }
+
+  if (sourceList->GetEntries() == 0)
+  {
+       Log("No sources found for id HLTData!");
+       // TODO What to do now depends on the expected behaviour of the
+       // online DA: if it expected to produce data for the FXS every run, then
+       // if no sources are found it means a problem happened and you should return error;
+       // if DA may or may not send files to FXS, then you shouldn't return error
+       // and go on with the analysis!
+       return 1;
+  }
+
+  // TODO We have the list of sources that produced the files with Id DRIFTVELOCITY.
+  // Now we will loop on the list and we'll query the files one by one. 
+  Log("The following sources produced files with the id DRIFTVELOCITY");
+  sourceList->Print();
+
+  TIter iter(sourceList);
+  TObjString *source = 0;
+  while((source=dynamic_cast<TObjString*> (iter.Next()))){
+       TString fileName = GetFile(kDAQ, "DRIFTVELOCITY", source->GetName());
+       if (fileName.Length() > 0)
+               Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
+  }
+
+  delete sourceList;
 
-  const char* fileName = GetFile(kDAQ, "PEDESTALS", "GDC");
-  if (fileName)
-    AliInfo(Form("Got the file %s, now we can extract some values.", fileName));
-  //TODO here the file could be opened, some values extracted and  written to e.g. fData
+  // Example of retrieving files from HLT, including how to query HLT status
 
-  TList* list = GetFileSources(kDAQ, "DRIFTVELOCITY");
-  if (list)
+  Bool_t hltStatus = GetHLTStatus(); // 1 = HLT ON (=> Query HLT), 0 = HLT OFF (=> skip HLT query)
+
+  if (hltStatus)
   {
-    AliInfo("The following sources produced files with the id DRIFTVELOCITY");
-    list->Print();
-    delete list;
+       Log("HLT is ON, let's query our files");
+       sourceList = GetFileSources(kHLT, "HLTData");
+       if (!sourceList)
+       {
+               Log("Error retrieving list of sources from FXS!");
+               return 1;
+       }
+
+       if (sourceList->GetEntries() == 0)
+       {
+               Log("No sources found for id HLTData!");
+               // TODO What to do now depends on the expected behaviour of the
+               // online DA: if it expected to produce data for the FXS every run, then
+               // if no sources are found it means a problem happened and you should return error;
+               // if DA may or may not send files to FXS, then you shouldn't return error
+               // and go on with the analysis!
+               return 1;
+       }
+       Log("The following sources produced files with the id HLTData");
+
+       sourceList->Print();
+
+       TIter iter(sourceList);
+       TObjString *source = 0;
+       while((source=dynamic_cast<TObjString*> (iter.Next()))){
+               TString fileName = GetFile(kHLT, "HLTData", source->GetName());
+               if (fileName.Length() > 0)
+                       Log(Form("Got the file %s from HLT, now we can extract some values.", fileName.Data()));
+       }
+
+       delete sourceList;
+
+  } else {
+       Log("HLT is OFF, skipping query...");
   }
-  //TODO here the files could be opened, some values extracted and  written to e.g. fData
+
+  // Example of how to retrieve the list of sources that produced files
+  sourceList = GetFileSources(kDAQ);
+  if (!sourceList)
+  {
+       Log("Error: No sources found!");
+       return 1;
+  }
+  
+  Log("The following sources produced files");
+  sourceList->Print();
+  delete sourceList;
+  
+  // Example of how to retrieve the list of ids from a given source
+  TList* idList = GetFileIDs(kDAQ, "LDC0");
+  if (!idList)
+  {
+       Log("Error: No IDs found!");
+       return 1;
+  }
+  
+  Log("The following ids are available");
+  idList->Print();
+  delete idList;
+  
+  // Example to store a file directly to the reference storage
+  // Suppose we have queried the file from the FXS. Now the file is available locally and is called "file1.root".
+  const char* refFileName="file1.root";
+  if (!StoreReferenceFile(refFileName, "InputData.root"))
+       return 1;
+  
 
   // Example of how to retrieve a run parameter using GetRunParameter function
   // TODO Here the parameter must be set manually with SetInputRunParameter function,
@@ -81,17 +205,31 @@ UInt_t AliTestPreprocessor::Process(TMap* dcsAliasMap)
        Log(Form("Number of events not put in logbook!"));
   }
 
+  // Example of how to retrieve a condition object from OCDB
+
+  AliCDBEntry *entry = GetFromOCDB("Calib", "Data");
+  if (!entry)
+  {
+       Log("No object found in OCDB!");
+  } else {
+       Log("Got TPC/Calib/Data object from OCDB. The object's metadata is: ");
+       entry->PrintMetaData();
+  }
+
 
   //Now we have to store the final CDB file
   AliCDBMetaData metaData;
        metaData.SetBeamPeriod(0);
-       metaData.SetResponsible("Alberto Colla");
+       metaData.SetResponsible("TPC expert");
        metaData.SetComment("This preprocessor fills an AliTestDataDCS object.");
 
-       UInt_t result = Store("SHUTTLE", "Data", fData, &metaData, 0, 0);
+       Bool_t result = Store("Calib", "Data", fData, &metaData, 0, 0);
        delete fData;
        fData = 0;
 
-  return result;
+  if (!result)
+       return 1;
+  
+  return 0;
 }