]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/TestMUONPreprocessor.C
Protection against not accessible input OCDB (Laurent)
[u/mrichter/AliRoot.git] / MUON / TestMUONPreprocessor.C
index 4f28c1bb3a06e0123844382991fa301da0ca2674..55c3302316315ec501adb21e064f3e29fc2322a1 100644 (file)
 
 #if !defined(__CINT__) || defined(__MAKECINT__)
 
-// This macro runs the test preprocessor
-// It uses AliTestShuttle to simulate a full Shuttle process
-
-// The input data is created in the functions
-//   CreateDCSAliasMap() creates input that would in the same way come from DCS
-//   ReadDCSAliasMap() reads from a file
-//   CreateInputFilesMap() creates a list of local files, that can be accessed by the shuttle
-//
-// According to SHUTTLE/TestShuttle/TestPreprocessor.C
+/// This macro runs the test preprocessor for MUON.
+/// It uses AliTestShuttle to simulate a full Shuttle process
+///
+/// The input data has to be created first by other processes (or is created
+/// here by CreateDCSAliasMap() for tracker HV).
+///
+/// To play with it, you'll have to set/modify several lines, to
+/// a) select input files, using shuttle->AddInputFile()
+/// b) select run type, using shuttle->AddInputRunParameter() (the run type
+///    dictates which task is really performed by the MUONPreprocessor
+///
+/// You must load relevant libraries (besides normal MUON ones) before
+/// compiling this macro :
+///
+/// gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle");
+/// gSystem->Load("libMUONshuttle.so");
+///
+///
+/// For more information on usage, please see READMEshuttle.
+///
 // By Laurent Aphecetche, SUBATECH Nantes
 
+#include "TestMUONPreprocessor.h"
+
+#include "AliMUONTrackerPreprocessor.h"
+
+#include "AliLog.h"
+
+#include "AliMpExMap.h"
+#include "AliMpHelper.h"
+#include "AliMpHVNamer.h"
+#include "AliMpCDB.h"
+
 #include "AliCDBManager.h"
-#include "AliShuttleInterface.h"
+#include "AliCDBEntry.h"
 #include "AliCDBId.h"
+#include "AliShuttleInterface.h"
 #include "AliTestShuttle.h"
-#include "TMap.h"
+#include "AliDCSValue.h"
+
 #include "Riostream.h"
 #include "TSystem.h"
-#include "AliMpExMap.h"
 #include "TMap.h"
-#include "TString.h"
 #include "TObjArray.h"
-#include "AliMpHelper.h"
-#include "AliDCSValue.h"
 #include "TObjString.h"
+#include "TString.h"
 #include "TRandom.h"
-#include "AliMUONPreprocessor.h"
-#include "AliCDBEntry.h"
 #endif
 
-void TestMUONPreprocessor()
+void TestMUONPreprocessor(Int_t runNumber=80, const char* runType="PEDESTAL_RUN")
 {
-  // load library
-  gSystem->Load("../SHUTTLE/TestShuttle/libTestShuttle.so");
-  gSystem->Load("libMUONshuttle.so");
+  // runType can be :
+  //
+  // PEDESTAL_RUN -> pedestals
+  // ELECTRONICS_CALIBRATION_RUN -> gains
+  // PHYSICS -> HV
+  // GMS
   
-  // initialize location of CDB
-  AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
-
   // create AliTestShuttle instance
   // The parameters are run, startTime, endTime
-  AliTestShuttle* shuttle = new AliTestShuttle(800, 0, 1);
-
-  // 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);
+  AliTestShuttle* shuttle = new AliTestShuttle(runNumber, 0, 1);
+  
+  const char* inputCDB = "local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB";
+    
+  AliTestShuttle::SetMainCDB(inputCDB);
+  AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestReference");
 
-  // TODO(2)
-  //
-  // The shuttle can also process files that originate from DCS, DAQ and HLT.
+  // Create DCS HV aliases
+  TMap* dcsAliasMap = CreateDCSAliasMap(inputCDB);
+  
+  if ( dcsAliasMap ) 
+  {
+    // now give the alias map to the shuttle
+    shuttle->SetDCSInput(dcsAliasMap);
+  }
+  
+  
+  printf("Test Shuttle temp dir: %s\n", AliShuttleInterface::GetShuttleTempDir());
+  printf("Test Shuttle log dir: %s\n", AliShuttleInterface::GetShuttleLogDir());
+  printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
+  printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
+  
+  // The shuttle can 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
@@ -90,45 +107,118 @@ void TestMUONPreprocessor()
   //
   // 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");
+  // In this example we add 4 files originating from different LDCs but with the same id (PEDESTALS)
 
   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC0","$ALICE_ROOT/MUON/data/LDC0.ped");
   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC1","$ALICE_ROOT/MUON/data/LDC1.ped");
   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC2","$ALICE_ROOT/MUON/data/LDC2.ped");
   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC3","$ALICE_ROOT/MUON/data/LDC3.ped");
   
-  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GMS","GMS","$ALICE_ROOT/MUON/data/GMS.root");
+  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC0","$ALICE_ROOT/MUON/data/LDC0.gain");
+  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC1","$ALICE_ROOT/MUON/data/LDC1.gain");
+  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC2","$ALICE_ROOT/MUON/data/LDC2.gain");
+  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC3","$ALICE_ROOT/MUON/data/LDC3.gain");
+  
+  // and GMS file
+  shuttle->AddInputFile(AliTestShuttle::kDCS,"MCH","GMS","GMS","$ALICE_ROOT/MUON/data/GMS.root");
 
-  // TODO(3)
+  // The shuttle can read run parameters stored in the DAQ run logbook.
+  // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
+  // using GetRunParameter function.
+  // In real life the parameters will be retrieved automatically from the run logbook;
+  shuttle->SetInputRunType(runType);
+  
   // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
-//  AliPreprocessor* pp = new AliTestPreprocessor("DET", shuttle);
-  new AliMUONPreprocessor("MCH", shuttle);
+  new AliMUONTrackerPreprocessor(shuttle);
 
   shuttle->Print();
   
   // 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", 7);
-//  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(const char* inputCDB)
+{
+  /// Creates a DCS structure for MUON Tracker HV
+  ///
+  /// 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
+  
+  Bool_t undefStorage(kFALSE);
+  
+  AliCDBManager* man = AliCDBManager::Instance();
+  if (!man->IsDefaultStorageSet())
+  {
+    undefStorage = kTRUE;
+    man->SetDefaultStorage(inputCDB);
+  }
+  
+  // Load mapping
+  Bool_t ok = AliMpCDB::LoadDDLStore();
+  
+  if (undefStorage)
+  {
+    man->UnsetDefaultStorage();
+  }
+  
+  if (!ok)
+  {
+    AliErrorGeneral("CreateDCSAliasMap","Could not load DDLStore from OCDB");
+    return 0x0;
+  }
+
+  TMap* aliasMap = new TMap;
+  aliasMap->SetOwner(kTRUE);
+  
+  TRandom random(0);
+  
+  AliMpHVNamer hvNamer;
+  
+  TObjArray* aliases = hvNamer.GenerateAliases();
+  
+  for ( Int_t i = 0; i < aliases->GetEntries(); ++i ) 
+  {
+    TObjString* alias = static_cast<TObjString*>(aliases->At(i));
+    TString& aliasName = alias->String();
+    if ( aliasName.Contains("sw") ) 
+    {
+      // HV Switch (St345 only)
+      TObjArray* valueSet = new TObjArray;
+      valueSet->SetOwner(kTRUE);
+      Bool_t value = kTRUE;
+//      Float_t r = random.Uniform();
+//      if ( r < 0.007 ) value = kFALSE;      
+//      if ( aliasName.Contains("DE513sw2") ) value = kFALSE;
+      
+      for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
+      {
+        AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
+        valueSet->Add(dcsValue);
+      }
+      aliasMap->Add(new TObjString(*alias),valueSet);
+    }
+    else
+    {
+      TObjArray* valueSet = new TObjArray;
+      valueSet->SetOwner(kTRUE);
+      for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
+      {
+        Float_t value = random.Gaus(1750,62.5);
+        if ( aliasName == "MchHvLvLeft/Chamber00Left/Quad2Sect1.actual.vMon") value = 500;
+        AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
+        valueSet->Add(dcsValue);
+      }
+      if ( aliasName == "MchHvLvLeft/Chamber04Left/Slat06.actual.vMon" ) continue;
+      aliasMap->Add(new TObjString(*alias),valueSet);
+    }
+  }
+  
+  delete aliases;
+    
+  return aliasMap;
 }
+