]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONCDB.cxx
Update of ACORDE-QA-Raw data histograms (now they go from -0.5 to 59.5)
[u/mrichter/AliRoot.git] / MUON / AliMUONCDB.cxx
index d14074f32eaaeaf18cfa81273ca151f5c13d8cbe..ec9eb12eb27d81c876aebd5b62f5f636ff3a1b4b 100644 (file)
 /* $Id$ */
 
 //-----------------------------------------------------------------------------
-/// \class AliMUONCDB
+/// \namespace AliMUONCDB
 ///
-/// Helper class to experience the OCDB
-/// It allows to generate dummy (but complete) containers for all the
+/// Helper functions to experience the OCDB
+///
+/// They allow to read magnetic field, mapping and recoParam from OCDB
+///
+/// And also to generate dummy (but complete) containers for all the
 /// calibration data types we have for tracker and trigger, and to write
 /// them into OCDB.
 ///
-/// For more information, please see READMECDB
+/// For more information, please see READMEcalib
 ///
-// \author Laurent Aphecetche
+/// \author Laurent Aphecetche
 //-----------------------------------------------------------------------------
 
 #include "AliMUONCDB.h"
 #include "AliMUON1DMap.h"
 #include "AliMUON2DMap.h"
 #include "AliMUON2DStoreValidator.h"
+#include "AliMUONCalibParamND.h"
 #include "AliMUONCalibParamNF.h"
 #include "AliMUONCalibParamNI.h"
 #include "AliMUONConstants.h"
+#include "AliMUONRejectList.h"
+#include "AliMUONTrackerIO.h"
 #include "AliMUONTriggerEfficiencyCells.h"
 #include "AliMUONTriggerLut.h"
 #include "AliMUONVStore.h"
 #include "AliMUONVCalibParam.h"
 #include "AliMUONVCalibParam.h"
+#include "AliMUONGlobalCrateConfig.h"
+#include "AliMUONRegionalTriggerConfig.h"
+#include "AliMUONRecoParam.h"
 
 #include "AliMpCDB.h"
 #include "AliMpConstants.h"
+#include "AliMpDEStore.h"
 #include "AliMpDDLStore.h"
-#include "AliMpDEIterator.h"
+#include "AliMpManuStore.h"
 #include "AliMpDEManager.h"
 #include "AliMpDetElement.h"
-#include "AliMpHVNamer.h"
+#include "AliMpFiles.h"
+#include "AliMpDCSNamer.h"
 #include "AliMpManuIterator.h"
 #include "AliMpSegmentation.h"
 #include "AliMpStationType.h"
@@ -58,6 +69,7 @@
 #include "AliCodeTimer.h"
 #include "AliCDBEntry.h"
 #include "AliCDBManager.h"
+#include "AliGRPManager.h"
 #include "AliDCSValue.h"
 #include "AliLog.h"
 
 #include <TStopwatch.h>
 #include <TSystem.h>
 #include <TMath.h>
+#include <TGeoGlobalMagField.h>
+#include <TClonesArray.h>
 
 
-/// \cond CLASSIMP
-ClassImp(AliMUONCDB)
-/// \endcond
-
 namespace
 {
   //_____________________________________________________________________________
@@ -114,7 +124,7 @@ void getBoundaries(const AliMUONVStore& store, Int_t dim,
         
     for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
     {
-      AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
+      AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
       if (!pad.IsValid()) continue;
       
       for ( Int_t i = 0; i < dim; ++i ) 
@@ -158,22 +168,166 @@ Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
 }
 
 //_____________________________________________________________________________
-AliMUONCDB::AliMUONCDB(const char* cdbpath)
-: TObject(),
-  fCDBPath(cdbpath),
-  fMaxNofChannelsToGenerate(-1)
+Bool_t AliMUONCDB::CheckOCDB(Bool_t pathOnly)
+{
+  /// Check that OCDB path and run number are properly set
+  
+  AliCDBManager* man = AliCDBManager::Instance();
+  
+  // first OCDB path
+  if (!man->IsDefaultStorageSet()) {
+    AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
+    return kFALSE;
+  }
+  
+  // then run number if required
+  if (pathOnly) return kTRUE;
+  if (man->GetRun() < 0) {
+    AliErrorGeneral("AliMUONCDB", "Run number must be properly set");
+    return kFALSE;
+  }
+  
+  return kTRUE;
+  
+}
+
+//_____________________________________________________________________________
+Bool_t AliMUONCDB::CheckMapping(Bool_t segmentationOnly)
+{
+  /// Check that the mapping has been loaded
+  
+  // first the segmentation
+  if (!AliMpSegmentation::Instance(false)) {
+    AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
+    return kFALSE;
+  }
+  
+  // then the others if required
+  if (segmentationOnly) return kTRUE;
+  if (!AliMpDDLStore::Instance(false) || !AliMpDEStore::Instance(false) || !AliMpManuStore::Instance(false)) {
+    AliErrorGeneral("AliMUONCDB", "Full mapping must be loaded first");
+    return kFALSE;
+  }
+  
+  return kTRUE;
+  
+}
+
+//_____________________________________________________________________________
+Bool_t AliMUONCDB::LoadField()
+{
+  /// Load magnetic field (existing field will be deleted).
+  /// OCDB path and run number are supposed to be set.
+  
+  AliInfoGeneral("AliMUONCDB","Loading field map from GRP...");
+  
+  if (!AliMUONCDB::CheckOCDB()) return kFALSE;
+  
+  AliGRPManager grpMan;
+  
+  // make sure the old field is deleted even if it is locked
+  if(TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
+  
+  if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
+    AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
+    return kFALSE;
+  }
+  
+  return kTRUE;
+  
+}
+
+//_____________________________________________________________________________
+Bool_t AliMUONCDB::LoadMapping(Bool_t segmentationOnly)
+{
+  /// Load mapping (existing mapping will be unloaded).
+  /// OCDB path and run number are supposed to be set.
+  
+  AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
+  
+  if (!AliMUONCDB::CheckOCDB()) return kFALSE;
+  
+  // in case it has already been set
+  AliMpCDB::UnloadAll();
+  
+  if (segmentationOnly) {
+    
+    if (!AliMpCDB::LoadMpSegmentation(kTRUE)){
+      AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
+      return kFALSE;
+    }
+    
+  } else {
+    
+    if (!AliMpCDB::LoadAll(kTRUE)) {
+      AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
+      return kFALSE;
+    }
+    
+  }
+  
+  return kTRUE;
+  
+}
+
+//_____________________________________________________________________________
+AliMUONRecoParam* AliMUONCDB::LoadRecoParam()
 {
-  /// ctor
-    // Load mapping
-    if ( ! AliMpCDB::LoadMpSegmentation() ) {
-      AliFatal("Could not access mapping from OCDB !");
+  /// Load and return reconstruction parameters.
+  /// OCDB path is supposed to be set.
+  
+  AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
+  
+  if (!AliMUONCDB::CheckOCDB()) return kFALSE;
+  
+  AliMUONRecoParam* recoParam = 0x0;
+  AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
+  
+  if(entry) {
+    
+    // load recoParam according OCDB content (single or array)
+    if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
+      
+      TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
+      
+      for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
+       recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
+       if (recoParam->IsDefault()) break;
+       recoParam = 0x0;
+      }
+      
     }
+    
+  }
+  
+  if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
+  
+  return recoParam;
+  
 }
 
 //_____________________________________________________________________________
-AliMUONCDB::~AliMUONCDB()
+TClonesArray* AliMUONCDB::LoadAlignmentData()
 {
-  /// dtor
+  /// Load and return the array of alignment objects.
+  
+  AliInfoGeneral("AliMUONCDB", "Loading Alignemnt from OCDB...");
+  
+  if (!AliMUONCDB::CheckOCDB()) return kFALSE;
+  
+  TClonesArray* alignmentArray = 0x0;
+  AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Align/Data");
+  
+  if (entry) {
+    // load alignement array
+    alignmentArray = dynamic_cast<TClonesArray*>(entry->GetObject());
+  }
+  
+  if (!alignmentArray) { 
+    AliErrorGeneral("AliMUONCDB", "failed to load Alignemnt from OCDB");
+  }  
+  
+  return alignmentArray;
 }
 
 //_____________________________________________________________________________
@@ -193,7 +347,7 @@ AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
   
   if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
   {
-    AliErrorClass(Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
+    AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
     return 0x0;
   }
   
@@ -253,6 +407,8 @@ AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
   /// contained inside store.
   /// It produces histograms named name_0, name_1, etc...
   
+  if (!AliMUONCDB::CheckMapping(kTRUE)) return;
+  
   TIter next(store.CreateIterator());
   AliMUONVCalibParam* param;
   Int_t n(0);
@@ -276,7 +432,7 @@ AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
       {
         h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
                             nbins,xmin[i],xmax[i]);
-        AliInfo(Form("Created histogram %s",h[i]->GetName()));
+        AliInfoGeneral("AliMUONCDB", Form("Created histogram %s",h[i]->GetName()));
       }
     }
     
@@ -289,7 +445,7 @@ AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
     
     for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
     {
-      AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
+      AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
       if (!pad.IsValid()) continue;
 
       ++n;
@@ -304,10 +460,10 @@ AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
   
   for ( Int_t i = 0; i < kNStations; ++i )
   {
-    AliInfo(Form("Station %d %d ",(i+1),nPerStation[i]));
+    AliInfoGeneral("AliMUONCDB", Form("Station %d %d ",(i+1),nPerStation[i]));
   }
 
-  AliInfo(Form("Number of channels = %d",n));
+  AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
   
   delete[] nPerStation;
 }
@@ -318,7 +474,9 @@ AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
 {
   /// Create a HV store
   
-  AliMpHVNamer hvNamer;
+  if (!AliMUONCDB::CheckMapping()) return 0;
+  
+  AliMpDCSNamer hvNamer("TRACKER");
   
   TObjArray* aliases = hvNamer.GenerateAliases();
   
@@ -369,11 +527,61 @@ AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
   
   delete aliases;
   
-  AliInfo(Form("%d HV channels and %d switches",nChannels,nSwitch));
+  AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches",nChannels,nSwitch));
   
   return nChannels+nSwitch;
 }
 
+//_____________________________________________________________________________
+Int_t 
+AliMUONCDB::MakeTriggerDCSStore(TMap& aliasMap, Bool_t defaultValues)
+{
+  /// Create a Trigger HV and Currents store
+  
+  if (!AliMUONCDB::CheckMapping()) return 0;
+  
+  AliMpDCSNamer triggerDCSNamer("TRIGGER");
+  
+  TObjArray* aliases = triggerDCSNamer.GenerateAliases();
+  
+  Int_t nChannels[2] = {0, 0};
+  
+  for ( Int_t i = 0; i < aliases->GetEntries(); ++i ) 
+  {
+    TObjString* alias = static_cast<TObjString*>(aliases->At(i));
+    TString& aliasName = alias->String();
+
+    TObjArray* valueSet = new TObjArray;
+    valueSet->SetOwner(kTRUE);
+    Int_t measureType = triggerDCSNamer.DCSvariableFromDCSAlias(aliasName.Data());
+    for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
+    {
+      Float_t value = 
+       (measureType == AliMpDCSNamer::kDCSI) ? 2. : 8000.;
+      if (!defaultValues) {
+       switch (measureType){
+       case AliMpDCSNamer::kDCSI:
+         value = GetRandom(2.,0.4,true);
+         break;
+       case AliMpDCSNamer::kDCSHV:
+         value = GetRandom(8000.,16.,true);
+         break;
+       }
+      }
+      AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
+      valueSet->Add(dcsValue);
+    }
+    aliasMap.Add(new TObjString(*alias),valueSet);
+    ++nChannels[measureType];
+  }
+  
+  delete aliases;
+  
+  AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i   HV -> %i",nChannels[0], nChannels[1]));
+  
+  return nChannels[0] + nChannels[1];
+}
+
 //_____________________________________________________________________________
 Int_t 
 AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
@@ -382,16 +590,28 @@ AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues
   /// otherwise mean and sigma are from a gaussian (with parameters
   /// defined below by the kPedestal* constants)
 
-  AliCodeTimerAuto("");
+  AliCodeTimerAutoGeneral("",0);
+  
+  if (!AliMUONCDB::CheckMapping()) return 0;
   
   Int_t nchannels(0);
   Int_t nmanus(0);
   
   const Int_t kChannels(AliMpConstants::ManuNofChannels());
-  const Float_t kPedestalMeanMean(200);
-  const Float_t kPedestalMeanSigma(10);
-  const Float_t kPedestalSigmaMean(1.0);
-  const Float_t kPedestalSigmaSigma(0.2);
+  
+  // bending
+  const Float_t kPedestalMeanMeanB(200.);
+  const Float_t kPedestalMeanSigmaB(10.);
+  const Float_t kPedestalSigmaMeanB(1.);
+  const Float_t kPedestalSigmaSigmaB(0.2);
+  
+  // non bending
+  const Float_t kPedestalMeanMeanNB(200.);
+  const Float_t kPedestalMeanSigmaNB(10.);
+  const Float_t kPedestalSigmaMeanNB(1.);
+  const Float_t kPedestalSigmaSigmaNB(0.2);
+  
+  const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
 
   Int_t detElemId;
   Int_t manuId;
@@ -400,6 +620,9 @@ AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues
   
   while ( it.Next(detElemId,manuId) )
   {
+    // skip a given fraction of manus
+    if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
+    
     ++nmanus;
 
     AliMUONVCalibParam* ped = 
@@ -425,12 +648,27 @@ AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues
       {
         Bool_t positive(kTRUE);
         meanPedestal = 0.0;
-        while ( meanPedestal == 0.0 ) // avoid strict zero 
-        {
-          meanPedestal = GetRandom(kPedestalMeanMean,kPedestalMeanSigma,positive);
-        }
-        sigmaPedestal = GetRandom(kPedestalSigmaMean,kPedestalSigmaSigma,positive);
+       
+       if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { // manu in non bending plane
+         
+         while ( meanPedestal == 0.0 ) // avoid strict zero 
+         {
+           meanPedestal = GetRandom(kPedestalMeanMeanNB,kPedestalMeanSigmaNB,positive);
+         }
+         sigmaPedestal = GetRandom(kPedestalSigmaMeanNB,kPedestalSigmaSigmaNB,positive);
+         
+       } else { // manu in bending plane
+         
+         while ( meanPedestal == 0.0 ) // avoid strict zero 
+         {
+           meanPedestal = GetRandom(kPedestalMeanMeanB,kPedestalMeanSigmaB,positive);
+         }
+         sigmaPedestal = GetRandom(kPedestalSigmaMeanB,kPedestalSigmaSigmaB,positive);
+         
+       }
+       
       }
+      
       ped->SetValueAsFloat(manuChannel,0,meanPedestal);
       ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
       
@@ -438,67 +676,94 @@ AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues
     Bool_t ok = pedestalStore.Add(ped);
     if (!ok)
     {
-      AliError(Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
+      AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
     }
-    if ( fMaxNofChannelsToGenerate > 0 && nchannels >= fMaxNofChannelsToGenerate ) break;
   }
   
-  AliInfo(Form("%d Manus and %d channels.",nmanus,nchannels));
+  AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
   return nchannels;
 }
 
 //_____________________________________________________________________________
-Int_t
-AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
+AliMUONRejectList* 
+AliMUONCDB::MakeRejectListStore(Bool_t defaultValues)
 {
-  /// Read the capacitance values from file and append them to the capaStore
+  /// Create a reject list
   
-  AliCodeTimerAuto(Form("file=%s",file));
+  AliCodeTimerAutoGeneral("",0);
+
+  AliMUONRejectList* rl = new AliMUONRejectList;
   
-  ifstream in(gSystem->ExpandPathName(file));
-  if (in.bad()) return 0;
+  if (!defaultValues)
+  {
+    rl->SetDetectionElementProbability(510);
+    rl->SetDetectionElementProbability(508);
+    return rl;
+  }
   
-  Int_t ngenerated(0);
+  return rl;
+}
+
+//_____________________________________________________________________________
+Int_t 
+AliMUONCDB::MakeOccupancyMapStore(AliMUONVStore& occupancyMapStore, Bool_t defaultValues)
+{
+  /// Create an occupancy map.
   
-  char line[1024];
-  Int_t serialNumber(-1);
-  AliMUONVCalibParam* param(0x0);
+  AliCodeTimerAutoGeneral("",0);
   
-  while ( in.getline(line,1024,'\n') )
+  if (!AliMUONCDB::CheckMapping()) return 0;
+  
+  Int_t nmanus(0);
+  
+  Int_t detElemId;
+  Int_t manuId;
+  
+  AliMpManuIterator it;
+  
+  Int_t nevents(1000);
+  
+  while ( it.Next(detElemId,manuId) )
   {
-    if ( isdigit(line[0]) ) 
+    ++nmanus;
+    
+    AliMUONVCalibParam* occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
+    
+    Double_t occ = 0.0;
+
+    AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
+    
+    Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
+    
+    if (!defaultValues) occ = gRandom->Rndm(1);
+
+    Double_t sumn = occ*nevents;
+    
+    occupancy->SetValueAsFloat(0,0,sumn); 
+    occupancy->SetValueAsFloat(0,1,sumn);
+    occupancy->SetValueAsFloat(0,2,sumn);
+    occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
+    occupancy->SetValueAsInt(0,4,nevents);
+    
+    Bool_t ok = occupancyMapStore.Add(occupancy);
+    if (!ok)
     {
-      serialNumber = atoi(line);
-      param = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
-      if (param)
-      {
-        AliError(Form("serialNumber %d appears several times !",serialNumber));
-        capaStore.Clear();
-        break;
-      }
-      param = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
-      Bool_t ok = capaStore.Add(param);
-      if (!ok)
-      {
-        AliError(Form("Could not set serialNumber=%d",serialNumber));
-        continue;
-      }      
-      continue;
+      AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
     }
-    Int_t channel;
-    Float_t capaValue;
-    Float_t injectionGain;
-    sscanf(line,"%d %f %f",&channel,&capaValue,&injectionGain);
-    AliDebug(1,Form("SerialNumber %10d Channel %3d Capa %f injectionGain %f",
-                    serialNumber,channel,capaValue,injectionGain));
-    param->SetValueAsFloat(channel,0,capaValue);
-    param->SetValueAsFloat(channel,1,injectionGain);
-    ++ngenerated;
   }
   
-  in.close();
+  return nmanus;
+}
+
+//_____________________________________________________________________________
+Int_t
+AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
+{
+  /// Read the capacitance values from file and append them to the capaStore
   
-  return ngenerated;
+  if (!AliMUONCDB::CheckMapping()) return 0;
+  
+  return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
 }
 
 //_____________________________________________________________________________
@@ -509,7 +774,9 @@ AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
   /// otherwise they are from a gaussian with parameters defined in the
   /// kCapa* constants below.
 
-  AliCodeTimerAuto("");
+  AliCodeTimerAutoGeneral("",0);
+  
+  if (!AliMUONCDB::CheckMapping()) return 0;
   
   Int_t nchannels(0);
   Int_t nmanus(0);
@@ -530,7 +797,7 @@ AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
     ++nmanus;
     
     AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId); 
-    Int_t serialNumber = de->GetManuSerialFromId(manuId);
+    Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
       
     if ( serialNumber <= 0 ) continue;
     
@@ -544,7 +811,7 @@ AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
       Bool_t ok = capaStore.Add(capa);
       if (!ok)
       {
-        AliError(Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
+        AliErrorGeneral("AliMUONCDB", Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
       }      
     }
     
@@ -574,12 +841,12 @@ AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
   
   Float_t percent = 0;
   if ( nmanus ) percent = 100*nmanusOK/nmanus;
-  AliInfo(Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
+  AliInfoGeneral("AliMUONCDB", Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
                nmanusOK,nmanus,percent));
-  AliInfo(Form("%5d channels",nchannels));
+  AliInfoGeneral("AliMUONCDB", Form("%5d channels",nchannels));
   if ( percent < 100 ) 
   {
-    AliWarning("Did not get all serial numbers. capaStore is incomplete !!!!");
+    AliWarningGeneral("AliMUONCDB", "Did not get all serial numbers. capaStore is incomplete !!!!");
   }
   return nchannels;
   
@@ -595,7 +862,9 @@ AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
   /// otherwise parameters are taken from gaussians with parameters 
   /// defined in the k* constants below.
   
-  AliCodeTimerAuto("");
+  AliCodeTimerAutoGeneral("",0);
+  
+  if (!AliMUONCDB::CheckMapping()) return 0;
   
   Int_t nchannels(0);
   Int_t nmanus(0);
@@ -655,27 +924,26 @@ AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
     Bool_t ok = gainStore.Add(gain);
     if (!ok)
     {
-      AliError(Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
+      AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
     }
-    if ( fMaxNofChannelsToGenerate > 0 && nchannels >= fMaxNofChannelsToGenerate ) break;
   }
   
-  AliInfo(Form("%d Manus and %d channels.",nmanus,nchannels));
+  AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
   return nchannels;
 }
 
 //_____________________________________________________________________________
 Int_t
-AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks) const
+AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks)
 {
   /// Generate local trigger masks store. All masks are set to FFFF
   
-  AliCodeTimerAuto("");
+  AliCodeTimerAutoGeneral("",0);
   
   Int_t ngenerated(0);
-  // Generate fake mask values for 234 localboards and put that into
+  // Generate fake mask values for all localboards and put that into
   // one single container (localBoardMasks)
-  for ( Int_t i = 1; i <= 234; ++i )
+  for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
   {
     AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
     for ( Int_t x = 0; x < 2; ++x )
@@ -694,51 +962,40 @@ AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks) const
 
 //_____________________________________________________________________________
 Int_t
-AliMUONCDB::MakeRegionalTriggerMaskStore(AliMUONVStore& rtm) const
+AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm)
 {
-  /// Make a regional trigger masks store. Mask is set to FFFF for each local board (Ch.F.)
+  /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
   
-  AliCodeTimerAuto("");
+  AliCodeTimerAutoGeneral("",0);
   
-  Int_t ngenerated(0);
-  for ( Int_t i = 0; i < 16; ++i )
-  {
-    AliMUONVCalibParam* regionalBoard = new AliMUONCalibParamNI(1,1,i,0,0);
-
-    regionalBoard->SetValueAsInt(0,0,0xFFFF);
-    ++ngenerated;
-      
-    rtm.Add(regionalBoard);
+  if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
+    AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
+    return 0;
   }
-  
-  return ngenerated;
+    
+  return rtm.GetNofTriggerCrates();  
 }
 
+
 //_____________________________________________________________________________
 Int_t 
-AliMUONCDB::MakeGlobalTriggerMaskStore(AliMUONVCalibParam& gtm) const
+AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm)
 {
-  /// Make a global trigger masks store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
-  
-  AliCodeTimerAuto("");
+  /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
   
-  Int_t ngenerated(0);
+  AliCodeTimerAutoGeneral("",0);
   
-  for ( Int_t j = 0; j < 2; ++j )
-  {
-    gtm.SetValueAsInt(j,0,0x00);
-    ++ngenerated;
-  }
-  return ngenerated;
+  return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
 }
 
+
 //_____________________________________________________________________________
 AliMUONTriggerLut* 
-AliMUONCDB::MakeTriggerLUT(const char* file) const
+AliMUONCDB::MakeTriggerLUT(const char* file)
 {
   /// Make a triggerlut object, from a file.
   
-  AliCodeTimerAuto("");
+  AliCodeTimerAutoGeneral("",0);
   
   AliMUONTriggerLut* lut = new AliMUONTriggerLut;
   lut->ReadFromFile(file);
@@ -747,11 +1004,11 @@ AliMUONCDB::MakeTriggerLUT(const char* file) const
 
 //_____________________________________________________________________________
 AliMUONTriggerEfficiencyCells*
-AliMUONCDB::MakeTriggerEfficiency(const char* file) const
+AliMUONCDB::MakeTriggerEfficiency(const char* file)
 {
   /// Make a trigger efficiency object from a file.
   
-  AliCodeTimerAuto("");
+  AliCodeTimerAutoGeneral("",0);
   
   return new AliMUONTriggerEfficiencyCells(file);
 }
@@ -764,14 +1021,9 @@ AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
 {
   /// Write a given object to OCDB
   
-  AliCDBId id(calibpath,startRun,endRun);
-  AliCDBMetaData md;
-  md.SetAliRootVersion(gROOT->GetVersion());
-  md.SetComment(gSystem->ExpandPathName(filename));
-  md.SetResponsible("Uploaded using AliMUONCDB class");
-  AliCDBManager* man = AliCDBManager::Instance();
-  man->SetDefaultStorage(fCDBPath);
-  man->Put(object,id,&md);
+  TString comment(gSystem->ExpandPathName(filename));
+  
+  WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
 }
 
 //_____________________________________________________________________________
@@ -781,22 +1033,28 @@ AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
 {
   /// Write a given object to OCDB
   
+  TString comment;
+  if ( defaultValues ) comment += "Test with default values";
+  else comment += "Test with random values";
+  
+  WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
+}
+
+//_____________________________________________________________________________
+void
+AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
+                      const char* comment, const char* responsible)
+{
+  /// Write a given object to OCDB
+  
+  if (!AliMUONCDB::CheckOCDB(kTRUE)) return;
+  
   AliCDBId id(calibpath,startRun,endRun);
   AliCDBMetaData md;
   md.SetAliRootVersion(gROOT->GetVersion());
-  if ( defaultValues )
-  {
-    md.SetComment("Test with default values");
-  }
-  else
-  {
-    md.SetComment("Test with random values");
-  }
-  md.SetResponsible("AliMUONCDB tester class");
-  
-  AliCDBManager* man = AliCDBManager::Instance();
-  man->SetDefaultStorage(fCDBPath);
-  man->Put(object,id,&md);
+  md.SetComment(comment);
+  md.SetResponsible(responsible);
+  AliCDBManager::Instance()->Put(object,id,&md);
 }
 
 //_____________________________________________________________________________
@@ -806,9 +1064,11 @@ AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
   /// Fill the neighbours store with, for each channel, a TObjArray of its
   /// neighbouring pads (including itself)
   
-  AliCodeTimerAuto("");
+  AliCodeTimerAutoGeneral("",0);
+  
+  if (!AliMUONCDB::CheckMapping()) return 0;
   
-  AliInfo("Generating NeighbourStore. This will take a while. Please be patient.");
+  AliInfoGeneral("AliMUONCDB", "Generating NeighbourStore. This will take a while. Please be patient.");
   
   Int_t nchannels(0);
   
@@ -836,14 +1096,14 @@ AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
       Bool_t ok = neighbourStore.Add(calibParam);
       if (!ok)
       {
-        AliError(Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
+        AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
         return -1;
       }      
     }
     
     for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
     {
-      AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
+      AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
       
       if (pad.IsValid()) 
       {
@@ -854,10 +1114,10 @@ AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
             
         for ( Int_t i = 0; i < nofPadNeighbours; ++i )
         {
-          AliMpPad* pad = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
+          AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
           Int_t x;
 //          Bool_t ok =
-          calibParam->PackValues(pad->GetLocation().GetFirst(),pad->GetLocation().GetSecond(),x);
+              calibParam->PackValues(p->GetManuId(),p->GetManuChannel(),x);
 //          if (!ok)
 //          {
 //            AliError("Could not pack value. Something is seriously wrong. Please check");
@@ -873,24 +1133,15 @@ AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
   return nchannels;
 }
 
-//_____________________________________________________________________________
-void
-AliMUONCDB::SetMaxNofChannelsToGenerate(Int_t n)
-{
-  /// Set the maximum number of channels to generate (used for testing only)
-  /// n < 0 means no limit
-  fMaxNofChannelsToGenerate = n;
-}
-
 //_____________________________________________________________________________
 void
 AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
 {  
   /// Write local trigger masks to OCDB
   
-  AliMUONVStore* ltm = new AliMUON1DArray(235);
+  AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
   Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
-  AliInfo(Form("Ngenerated = %d",ngenerated));
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
   if (ngenerated>0)
   {
     WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
@@ -900,37 +1151,39 @@ AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
 
 //_____________________________________________________________________________
 void
-AliMUONCDB::WriteRegionalTriggerMasks(Int_t startRun, Int_t endRun)
+AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
 {  
   /// Write regional trigger masks to OCDB
   
-  AliMUONVStore* rtm = new AliMUON1DArray(16);
-  Int_t ngenerated = MakeRegionalTriggerMaskStore(*rtm);
-  AliInfo(Form("Ngenerated = %d",ngenerated));
+  AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
+  Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
   if (ngenerated>0)
   {
-    WriteToCDB("MUON/Calib/RegionalTriggerBoardMasks",rtm,startRun,endRun,true);
+    WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
   }
   delete rtm;
 }
 
+
 //_____________________________________________________________________________
 void
-AliMUONCDB::WriteGlobalTriggerMasks(Int_t startRun, Int_t endRun)
+AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
 {  
   /// Write global trigger masks to OCDB
   
-  AliMUONVCalibParam* gtm = new AliMUONCalibParamNI(1,2,1,0,0);
+  AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
 
-  Int_t ngenerated = MakeGlobalTriggerMaskStore(*gtm);
-  AliInfo(Form("Ngenerated = %d",ngenerated));
+  Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
   if (ngenerated>0)
   {
-    WriteToCDB("MUON/Calib/GlobalTriggerBoardMasks",gtm,startRun,endRun,true);
+    WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
   }
   delete gtm;
 }
 
+
 //_____________________________________________________________________________
 void
 AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
@@ -967,7 +1220,7 @@ AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
   
   AliMUONVStore* neighbours = Create2DMap();
   Int_t ngenerated = MakeNeighbourStore(*neighbours);
-  AliInfo(Form("Ngenerated = %d",ngenerated));
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
   if (ngenerated>0)
   {
     WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
@@ -987,7 +1240,7 @@ AliMUONCDB::WriteHV(Bool_t defaultValues,
   
   TMap* hvStore = new TMap;
   Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
-  AliInfo(Form("Ngenerated = %d",ngenerated));
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
   if (ngenerated>0)
   {
     WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
@@ -995,6 +1248,26 @@ AliMUONCDB::WriteHV(Bool_t defaultValues,
   delete hvStore;
 }
 
+//_____________________________________________________________________________
+void 
+AliMUONCDB::WriteTriggerDCS(Bool_t defaultValues,
+                    Int_t startRun, Int_t endRun)
+{
+  /// generate Trigger HV and current values (either const if defaultValues=true or random
+  /// if defaultValues=false, see makeTriggerDCSStore) and
+  /// store them into CDB located at cdbpath, with a validity period
+  /// ranging from startRun to endRun
+  
+  TMap* triggerDCSStore = new TMap;
+  Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore,defaultValues);
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
+  if (ngenerated>0)
+  {
+    WriteToCDB("MUON/Calib/TriggerDCS",triggerDCSStore,startRun,endRun,defaultValues);
+  }
+  delete triggerDCSStore;
+}
+
 //_____________________________________________________________________________
 void 
 AliMUONCDB::WritePedestals(Bool_t defaultValues,
@@ -1007,11 +1280,43 @@ AliMUONCDB::WritePedestals(Bool_t defaultValues,
   
   AliMUONVStore* pedestalStore = Create2DMap();
   Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
-  AliInfo(Form("Ngenerated = %d",ngenerated));
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
   WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
   delete pedestalStore;
 }
 
+//_____________________________________________________________________________
+void 
+AliMUONCDB::WriteOccupancyMap(Bool_t defaultValues,
+                              Int_t startRun, Int_t endRun)
+{
+  /// generate occupancy map values (either empty one if defaultValues=true, or
+  /// random one, see MakeOccupancyMapStore) and
+  /// store them into CDB located at cdbpath, with a validity period
+  /// ranging from startRun to endRun
+  
+  AliMUONVStore* occupancyMapStore = Create2DMap();
+  Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore,defaultValues);
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
+  WriteToCDB("MUON/Calib/OccupancyMap",occupancyMapStore,startRun,endRun,defaultValues);
+  delete occupancyMapStore;
+}
+
+//_____________________________________________________________________________
+void 
+AliMUONCDB::WriteRejectList(Bool_t defaultValues,
+                              Int_t startRun, Int_t endRun)
+{
+  /// generate reject list values (either empty one if defaultValues=true, or
+  /// random one, see MakeRejectListStore) and
+  /// store them into CDB located at cdbpath, with a validity period
+  /// ranging from startRun to endRun
+  
+  AliMUONRejectList* rl = MakeRejectListStore(defaultValues);
+  WriteToCDB("MUON/Calib/RejectList",rl,startRun,endRun,defaultValues);
+  delete rl;
+}
+
 
 //_____________________________________________________________________________
 void 
@@ -1025,7 +1330,7 @@ AliMUONCDB::WriteGains(Bool_t defaultValues,
   
   AliMUONVStore* gainStore = Create2DMap();
   Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
-  AliInfo(Form("Ngenerated = %d",ngenerated));  
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));  
   WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
   delete gainStore;
 }
@@ -1041,7 +1346,7 @@ AliMUONCDB::WriteCapacitances(const char* filename,
   
   AliMUONVStore* capaStore = new AliMUON1DMap(16828);
   Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
-  AliInfo(Form("Ngenerated = %d",ngenerated));
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
   if ( ngenerated > 0 ) 
   {
     WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
@@ -1061,19 +1366,20 @@ AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
   
   AliMUONVStore* capaStore = new AliMUON1DMap(16828);
   Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
-  AliInfo(Form("Ngenerated = %d",ngenerated));
+  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
   WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
   delete capaStore;
 }
 
 //_____________________________________________________________________________
 void
-AliMUONCDB::WriteTrigger(Int_t startRun, Int_t endRun)
+AliMUONCDB::WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
 {
   /// Writes all Trigger related calibration to CDB
+  WriteTriggerDCS(defaultValues,startRun,endRun);
   WriteLocalTriggerMasks(startRun,endRun);
-  WriteRegionalTriggerMasks(startRun,endRun);
-  WriteGlobalTriggerMasks(startRun,endRun);
+  WriteRegionalTriggerConfig(startRun,endRun);
+  WriteGlobalTriggerConfig(startRun,endRun);
   WriteTriggerLut(startRun,endRun);
   WriteTriggerEfficiency(startRun,endRun);
 }
@@ -1088,4 +1394,7 @@ AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
   WriteGains(defaultValues,startRun,endRun);
   WriteCapacitances(defaultValues,startRun,endRun);
   WriteNeighbours(startRun,endRun);
+  WriteOccupancyMap(defaultValues,startRun,endRun);
+  WriteRejectList(defaultValues,startRun,endRun);
 }
+