]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
o) updated test preprocessor (alberto)
authorjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 6 Jun 2006 14:20:05 +0000 (14:20 +0000)
committerjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 6 Jun 2006 14:20:05 +0000 (14:20 +0000)
o) added comments to example macro
o) test shuttle implements new interface

SHUTTLE/TestShuttle/AliTestDataDCS.cxx
SHUTTLE/TestShuttle/AliTestDataDCS.h
SHUTTLE/TestShuttle/AliTestPreprocessor.cxx
SHUTTLE/TestShuttle/AliTestPreprocessor.h
SHUTTLE/TestShuttle/AliTestShuttle.cxx
SHUTTLE/TestShuttle/AliTestShuttle.h
SHUTTLE/TestShuttle/TestCDB/DET/DCS/Data/Run0_0_v0_s0.root [new file with mode: 0644]
SHUTTLE/TestShuttle/TestCDB/TPC/DCS/Data/Run21200_21200_v0_s0.root [deleted file]
SHUTTLE/TestShuttle/TestPreprocessor.C

index 689ef4fe1d6a6219e163ee1249060466f13feb0a..4ba74a224dd2e6cfa7c9ac3e0bd4b2fc9a93cca7 100644 (file)
@@ -82,6 +82,7 @@ void AliTestDataDCS::ProcessData(TMap& aliasMap){
 
                UInt_t ne=0;
                while ((aValue = (AliDCSValue*) iterarray.Next())) {
+
                val[ne] = aValue->GetSimpleValue().GetFloat();
                time[ne] = (Double_t) (aValue->GetTimeStamp());
                // fill histos (alias 0-2)
@@ -119,13 +120,12 @@ void AliTestDataDCS::Init(){
        fGraphs.SetOwner(1);
 
        for(int i=0;i<kNAliases;i++){
-               fAliasNames[i] = "TpcHvSect0";
+               fAliasNames[i] = "DCSAlias";
                fAliasNames[i] += i;
-               fAliasNames[i] += ".FloatValue";
        }
 
        for(int i=0;i<kNHistos;i++){
-               fHv[i] = new TH1F(fAliasNames[0].Data(),fAliasNames[0].Data(), 20, kHvMin, kHvMax);
+               fHv[i] = new TH1F(fAliasNames[i].Data(),fAliasNames[i].Data(), 20, kHvMin, kHvMax);
                fHv[i]->GetXaxis()->SetTitle("Hv");
        }
 }
index decc61fcbc18dd228c65ef1a38cf136965da9bcb..c648919dc7d88fd5a310df7c1b2463ad54ddfa94 100644 (file)
@@ -10,7 +10,7 @@
 class AliTestDataDCS : public TObject {
 public:
        enum {kNAliases=6, kNHistos=3, kNGraphs=3, kNFunctions=2};
-       enum {kHvMin=0, kHvMax=500};
+       enum {kHvMin=0, kHvMax=20};
 
        AliTestDataDCS();
        AliTestDataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime);
index 1d3f3b130ebf3fb2e15e1df32ea2e278432d9ca5..461f8a4077bddb727b98549f418cc29cdd53fc45 100644 (file)
@@ -15,6 +15,7 @@
 
 ClassImp(AliTestPreprocessor)
 
+//______________________________________________________________________________________________
 AliTestPreprocessor::AliTestPreprocessor(const char* detector, AliShuttleInterface* shuttle) :
   AliPreprocessor(detector, shuttle),
   fData(0)
@@ -22,11 +23,13 @@ AliTestPreprocessor::AliTestPreprocessor(const char* detector, AliShuttleInterfa
   // constructor
 }
 
+//______________________________________________________________________________________________
 AliTestPreprocessor::~AliTestPreprocessor()
 {
   // destructor
 }
 
+//______________________________________________________________________________________________
 void AliTestPreprocessor::Initialize(Int_t run, UInt_t startTime,
        UInt_t endTime)
 {
@@ -41,29 +44,41 @@ void AliTestPreprocessor::Initialize(Int_t run, UInt_t startTime,
        fData = new AliTestDataDCS(fRun, fStartTime, fEndTime);
 }
 
-Int_t AliTestPreprocessor::Process(TMap* dcsAliasMap)
+//______________________________________________________________________________________________
+UInt_t AliTestPreprocessor::Process(TMap* dcsAliasMap)
 {
   // Fills data into a AliTestDataDCS object
 
   if (!dcsAliasMap)
-    return -1;
+    return 0;
 
+  // The processing of the DCS input data is forwarded to AliTestDataDCS
        fData->ProcessData(*dcsAliasMap);
 
   const char* fileName = GetFile(kDAQ, "PEDESTALS", "GDC");
   if (fileName)
     AliInfo(Form("Got the file %s, now we can extract some values.", fileName));
-  // open file, extract some values, write them to fData
-
+  //TODO here the file could be opened, some values extracted and  written to e.g. fData
+
+  TList* list = GetFileSources(kDAQ, "DRIFTVELOCITY");
+  if (list)
+  {
+    AliInfo("The following sources produced files with the id DRIFTVELOCITY");
+    list->Print();
+    delete list;
+  }
+  //TODO here the files could be opened, some values extracted and  written to e.g. fData
+
+  //Now we have to store the final CDB file
   AliCDBMetaData metaData;
        metaData.SetBeamPeriod(0);
        metaData.SetResponsible("Alberto Colla");
        metaData.SetComment("This preprocessor fills an AliTestDataDCS object.");
 
-       Store(fData, &metaData);
+       UInt_t result = Store(fData, &metaData);
        delete fData;
        fData = 0;
 
-  return 0;
+  return result;
 }
 
index 5c57439d69e3346e0e4c951fcbe1fce2a6f40d37..060d480af1dd008a4c462b3ad7730a46c6c12eae 100644 (file)
@@ -15,7 +15,7 @@ class AliTestPreprocessor : public AliPreprocessor
 
   protected:
     virtual void Initialize(Int_t run, UInt_t startTime, UInt_t endTime);
-    virtual Int_t Process(TMap* dcsAliasMap);
+    virtual UInt_t Process(TMap* dcsAliasMap);
 
   private:
     AliTestDataDCS *fData;    // CDB class that stores the data
index 6f2e95eb0f2275ba823a14f9b9f74babb1818d96..3baa641eb8a3f949359efa3415a8768714e5dfa1 100644 (file)
@@ -49,6 +49,7 @@ some docs added
 #include "AliCDBManager.h"
 #include "AliCDBMetaData.h"
 #include "AliCDBId.h"
+#include "AliPreprocessor.h"
 
 #include <TMap.h>
 #include <TList.h>
@@ -57,19 +58,35 @@ some docs added
 
 ClassImp(AliTestShuttle)
 
-AliTestShuttle::AliTestShuttle(TMap* inputFiles) : fInputFiles(inputFiles)
+//______________________________________________________________________________________________
+AliTestShuttle::AliTestShuttle() :
+  fInputFiles(0),
+  fPreprocessors(0),
+  fDcsAliasMap(0)
 {
   // constructor
-  // inputFiles contains the map of local files that can be retrieved by the preprocessor
-  // check TestPreprocessor.C for an example of its structure
+
+  fInputFiles = new TMap;
+  fPreprocessors = new TObjArray;
 }
 
+//______________________________________________________________________________________________
 AliTestShuttle::~AliTestShuttle()
 {
   // destructor
+
+  delete fInputFiles;
+  fInputFiles = 0;
+
+  delete fPreprocessors;
+  fPreprocessors = 0;
+
+  delete fDcsAliasMap;
+  fDcsAliasMap = 0;
 }
 
-Int_t AliTestShuttle::Store(const char* detector, TObject* object, AliCDBMetaData* metaData)
+//______________________________________________________________________________________________
+UInt_t AliTestShuttle::Store(const char* detector, TObject* object, AliCDBMetaData* metaData)
 {
   // Stores the CDB object
   // This function should be called at the end of the preprocessor cycle
@@ -79,11 +96,10 @@ Int_t AliTestShuttle::Store(const char* detector, TObject* object, AliCDBMetaDat
 
   AliCDBId id(Form("%s/SHUTTLE/Data", detector), 0, 0);
 
-  AliCDBManager::Instance()->Put(object, id, metaData);
-
-  return -1;
+  return AliCDBManager::Instance()->Put(object, id, metaData);
 }
 
+//______________________________________________________________________________________________
 const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
 {
   // This function retrieves a file from the given system (kDAQ, kDCS, kHLT) with the given file id
@@ -109,13 +125,15 @@ const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const ch
   TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
   if (!fileName)
   {
-    AliError(Form("Could not find files from source %s in %s with id %s", source, fkSystemNames[system], id));
+    AliError(Form("Could not find files from source %s in %s with id %s",
+                       source, fkSystemNames[system], id));
     return 0;
   }
 
   return fileName->GetString().Data();
 }
 
+//______________________________________________________________________________________________
 TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
 {
   // Returns a list of sources in a given system that saved a file with the given id
@@ -150,6 +168,7 @@ TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const
   return list;
 }
 
+//______________________________________________________________________________________________
 void AliTestShuttle::Log(const char* detector, const char* message)
 {
   // test implementation of Log
@@ -158,3 +177,47 @@ void AliTestShuttle::Log(const char* detector, const char* message)
   AliInfo(Form("%s: %s", detector, message));
 }
 
+//______________________________________________________________________________________________
+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
+
+  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)
+  {
+    sourceList = new TMap;
+    fInputFiles->Add(new TObjString(key), sourceList);
+  }
+
+  sourceList->Add(new TObjString(source), new TObjString(fileName));
+}
+
+//______________________________________________________________________________________________
+void AliTestShuttle::Process()
+{
+  // This function tests all preprocessors that are registered to it
+  // All preprocessors get the same dcs alias map and have access to the same list of files.
+
+  for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
+  {
+    AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
+    if (preprocessor)
+    {
+      preprocessor->Initialize(0, 1, 0);
+      preprocessor->Process(fDcsAliasMap);
+    }
+  }
+}
+
+//______________________________________________________________________________________________
+void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
+{
+  // registers a preprocessor
+
+  fPreprocessors->Add(preprocessor);
+}
index b51567dbdfb1ae8a1af43f98ca81d140c9d9b728..c9e163db54e031beba2e1950aabd872da11334d8 100644 (file)
@@ -19,16 +19,26 @@ class AliCDBMetaData;
 class AliTestShuttle : public AliShuttleInterface
 {
   public:
-    AliTestShuttle(TMap* inputFiles);
+    AliTestShuttle();
     virtual ~AliTestShuttle();
 
-    virtual Int_t Store(const char* detector, TObject* object, AliCDBMetaData* metaData);
+    void AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName);
+    void SetDCSInput(TMap* dcsAliasMap) { fDcsAliasMap = dcsAliasMap; }
+
+    void Process();
+
+    // AliShuttleInterface functions
+    virtual UInt_t Store(const char* detector, TObject* object, AliCDBMetaData* metaData);
     virtual const char* GetFile(Int_t system, const char* detector, const char* id, const char* source);
     virtual TList* GetFileSources(Int_t system, const char* detector, const char* id);
     virtual void Log(const char* detector, const char* message);
 
+    virtual void RegisterPreprocessor(AliPreprocessor* preprocessor);
+
   protected:
     TMap* fInputFiles;   // files for GetFile, GetFileSources
+    TObjArray* fPreprocessors; // list of preprocessors that are to be tested
+    TMap* fDcsAliasMap; // DCS data for testing
 
   private:
     ClassDef(AliTestShuttle, 0);
diff --git a/SHUTTLE/TestShuttle/TestCDB/DET/DCS/Data/Run0_0_v0_s0.root b/SHUTTLE/TestShuttle/TestCDB/DET/DCS/Data/Run0_0_v0_s0.root
new file mode 100644 (file)
index 0000000..125b4a2
Binary files /dev/null and b/SHUTTLE/TestShuttle/TestCDB/DET/DCS/Data/Run0_0_v0_s0.root differ
diff --git a/SHUTTLE/TestShuttle/TestCDB/TPC/DCS/Data/Run21200_21200_v0_s0.root b/SHUTTLE/TestShuttle/TestCDB/TPC/DCS/Data/Run21200_21200_v0_s0.root
deleted file mode 100644 (file)
index 50a0cd2..0000000
Binary files a/SHUTTLE/TestShuttle/TestCDB/TPC/DCS/Data/Run21200_21200_v0_s0.root and /dev/null differ
index 23065fa9756fcb16c97e1a924b7d2cd3c2141325..adba4ba9163898b47a9469322d8ec44a203b020e 100644 (file)
@@ -1,3 +1,5 @@
+/* $Id$ */
+
 // This class runs the test preprocessor
 // It uses AliTestShuttle to simulate a full Shuttle process
 
 
 void TestPreprocessor()
 {
-  gSystem->Load("libTestShuttle");
+  // load library
+  gSystem->Load("libTestShuttle.so");
 
   // initialize location of CDB
-  AliCDBManager *man = AliCDBManager::Instance();
-  man->SetDefaultStorage("local://TestCDB");
-
-  // TODO decide where to read the data
-  TMap* dcsAliasMap = 0;
-  //dcsAliasMap = CreateDCSAliasMap();
-  dcsAliasMap = ReadDCSAliasMap();
-
-  // create TMap of available files
-  TMap* inputFiles = CreateInputFilesMap();
+  AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
 
   // create AliTestShuttle instance
-  AliTestShuttle* shuttle = new AliTestShuttle(inputFiles);
-  TestShuttle(shuttle);
-
-  // create preprocessor
-  AliPreprocessor* pp = new AliTestPreprocessor("TPC", shuttle);
-
-  // call preprocessor
-  pp->Initialize(0, 0, 1);
-  pp->Process(dcsAliasMap);
+  AliTestShuttle* shuttle = new AliTestShuttle();
+
+  // TODO(1)
+  //
+  // The shuttle can read DCS data, if the preprocessor should be tested to process DCS data,
+  // some fake data has to be created.
+  //
+  // The "fake" input data can be taken using either (a) or (b):
+  // (a) data from a file: Use ReadDCSAliasMap()
+  //     the format of the file is explained in ReadDCSAliasMap()
+  //     To use it uncomment the following line:
+  //
+  //TMap* dcsAliasMap = ReadDCSAliasMap();
+  //
+  // (b) generated in this macro: Use CreateDCSAliasMap() and its documentation
+  //     To use it uncomment the following line:
+  //
+  TMap* dcsAliasMap = CreateDCSAliasMap();
+
+  // now give the alias map to the shuttle
+  shuttle->SetDCSInput(dcsAliasMap);
+
+  // TODO(2)
+  //
+  // The shuttle can also process files that originate from DCS, DAQ and HLT.
+  // To test it, we provide some local files and locations where these would be found when
+  // the online machinery would be there.
+  // In real life this functions would be produces by the sub-detectors
+  // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
+  //
+  // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
+  // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
+  // In this example we add a file originating from the GDC with the id PEDESTALS
+  // Three files originating from different LDCs but with the same id are also added
+  shuttle->AddInputFile(AliTestShuttle::kDAQ, "DET", "PEDESTALS", "GDC", "file1.root");
+  shuttle->AddInputFile(AliTestShuttle::kDAQ, "DET", "DRIFTVELOCITY", "LDC0", "file2a.root");
+  shuttle->AddInputFile(AliTestShuttle::kDAQ, "DET", "DRIFTVELOCITY", "LDC1", "file2b.root");
+  shuttle->AddInputFile(AliTestShuttle::kDAQ, "DET", "DRIFTVELOCITY", "LDC2", "file2b.root");
+
+  // TODO(3)
+  // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
+  AliPreprocessor* pp = new AliTestPreprocessor("DET", shuttle);
+
+  // Test the preprocessor
+  shuttle->Process();
+
+  // TODO(4)
+  // In the preprocessor AliShuttleInterface::Store should be called to put the final
+  // data to the CDB. To check if all went fine have a look at the files produced in
+  // $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/SHUTTLE/Data
+  //
+  // Check the file which should have been created
+  AliCDBEntry* entry = AliCDBManager::Instance()->Get("DET/SHUTTLE/Data", 0);
+  if (!entry)
+  {
+    printf("The file is not there. Something went wrong.\n");
+    return;
+  }
+
+  AliTestDataDCS* output = dynamic_cast<AliTestDataDCS*> (entry->GetObject());
+  // If everything went fine, draw the result
+  if (output)
+    output->Draw();
 }
 
 TMap* CreateDCSAliasMap()
 {
-  // fill fake DCS object
+  // Creates a DCS structure
+  // The structure is the following:
+  //   TMap (key --> value)
+  //     <DCSAlias> --> <valueList>
+  //     <DCSAlias> is a string
+  //     <valueList> is a TObjArray of AliDCSValue
+  //     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
 
-  TObjArray* valueSet1 = new TObjArray;
+  // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
+  // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
 
+  TMap* aliasMap = new TMap;
+  aliasMap->SetOwner(1);
 
-  valueSet1->Add();
+  TRandom random;
 
-  TObjArray* valueSet2 = new TObjArray;
-  valueSet2->Add();
+  for(int nAlias=0;nAlias<6;nAlias++)
+  {
+    TObjArray* valueSet = new TObjArray;
+    valueSet->SetOwner(1);
 
-  TMap* aliasMap = new TMap;
-  aliasMap->Add(new TObjString("DCSAlias1"), valueSet1);
-  aliasMap->Add(new TObjString("DCSAlias2"), valueSet2);
+    TString aliasName="DCSAlias";
+    aliasName += nAlias;
+    //printf("\n\n alias: %s\n\n",aliasName.Data());
+
+    for (int timeStamp=0;timeStamp<1000;timeStamp+=10)
+    {
+      AliSimpleValue* simVal = new AliSimpleValue((Float_t) (random.Gaus()+5*nAlias));
+      AliDCSValue* dcsVal = new AliDCSValue(*simVal, timeStamp);
+      //printf("%s\n",dcsVal->ToString().Data());
+      valueSet->Add(dcsVal);
+    }
+    aliasMap->Add(new TObjString(aliasName), valueSet);
+  }
 
   return aliasMap;
 }
 
 TMap* ReadDCSAliasMap()
 {
-  // open the file
-  AliCDBEntry *entry = AliCDBManager::Instance()->Get("TPC/DCS/Data",21200);
+  // Open a file that contains DCS input data
+  // The CDB framework is used to open the file, this means the file is located
+  // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
+  // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
+  // An explanation of the structure can be found in CreateDCSAliasMap()
+
+  AliCDBEntry *entry = AliCDBManager::Instance()->Get("DET/DCS/Data", 0);
   return dynamic_cast<TMap*> (entry->GetObject());
 }
 
-TMap* CreateInputFilesMap()
+void WriteDCSAliasMap()
 {
-  // create a list of files which will be available from the AliTestShuttle
+  // This writes the output from CreateDCSAliasMap to a CDB file
 
-  inputFile1 = new TMap;
-  inputFile1->Add(new TObjString("GDC"), new TObjString("file1.root"));
+  TMap* dcsAliasMap = CreateDCSAliasMap();
 
-  inputFile2 = new TMap;
-  inputFile2->Add(new TObjString("LDC0"), new TObjString("file2a.root"));
-  inputFile2->Add(new TObjString("LDC1"), new TObjString("file2b.root"));
-  inputFile2->Add(new TObjString("LDC2"), new TObjString("file2c.root"));
+  AliCDBMetaData metaData;
+       metaData.SetBeamPeriod(0);
+       metaData.SetResponsible("Responsible person");
+       metaData.SetComment("Test object for TestPreprocessor.C");
 
-  TMap* inputFiles = new TMap;
-  inputFiles->Add(new TObjString("DAQ-TPC-PEDESTALS"), inputFile1);
-  inputFiles->Add(new TObjString("DAQ-TPC-DRIFTVELOCITY"), inputFile2);
-
-  return inputFiles;
-}
+  AliCDBId id("DET/DCS/Data", 0, 0);
 
-void TestShuttle(AliShuttleInterface* shuttle)
-{
-  const char* file = shuttle->GetFile(AliShuttleInterface::kDAQ, "TPC", "PEDESTALS", "GDC");
-  cout << "GetFile: " << file << endl;
-  cout << "GetFileSources: " << endl;
-  shuttle->GetFileSources(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY")->Print();
-
-  shuttle->Log("TPC", "Log test");
+  // initialize location of CDB
+  AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
 
-  //shuttle->Store();
+  AliCDBManager::Instance()->Put(dcsAliasMap, id, &metaData);
 }