]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONCDB.cxx
Initialisation.
[u/mrichter/AliRoot.git] / MUON / AliMUONCDB.cxx
index 608530de8100e7a8d8144df1fdd622d484fc2245..d14074f32eaaeaf18cfa81273ca151f5c13d8cbe 100644 (file)
@@ -15,6 +15,7 @@
 
 /* $Id$ */
 
+//-----------------------------------------------------------------------------
 /// \class AliMUONCDB
 ///
 /// Helper class to experience the OCDB
 /// For more information, please see READMECDB
 ///
 // \author Laurent Aphecetche
+//-----------------------------------------------------------------------------
 
 #include "AliMUONCDB.h"
 
-#include "AliCDBEntry.h"
-#include "AliCDBManager.h"
-#include "AliDCSValue.h"
-#include "AliLog.h"
 #include "AliMUON1DArray.h"
 #include "AliMUON1DMap.h"
 #include "AliMUON2DMap.h"
 #include "AliMUONCalibParamNF.h"
 #include "AliMUONCalibParamNI.h"
 #include "AliMUONConstants.h"
-#include "AliMUONHVNamer.h"
 #include "AliMUONTriggerEfficiencyCells.h"
 #include "AliMUONTriggerLut.h"
 #include "AliMUONVStore.h"
 #include "AliMUONVCalibParam.h"
 #include "AliMUONVCalibParam.h"
+
+#include "AliMpCDB.h"
 #include "AliMpConstants.h"
 #include "AliMpDDLStore.h"
 #include "AliMpDEIterator.h"
 #include "AliMpDEManager.h"
 #include "AliMpDetElement.h"
-#include "AliMpManuList.h"
+#include "AliMpHVNamer.h"
+#include "AliMpManuIterator.h"
 #include "AliMpSegmentation.h"
 #include "AliMpStationType.h"
 #include "AliMpVSegmentation.h"
+
+#include "AliCodeTimer.h"
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
+#include "AliDCSValue.h"
+#include "AliLog.h"
+
 #include <Riostream.h>
 #include <TArrayI.h>
 #include <TClass.h>
 #include <TSystem.h>
 #include <TMath.h>
 
+
 /// \cond CLASSIMP
 ClassImp(AliMUONCDB)
 /// \endcond
 
 namespace
 {
-//_____________________________________________________________________________
-void getBoundaries(const AliMUONVStore& store,
-                   Float_t& x0min, Float_t& x0max,
-                   Float_t& x1min, Float_t& x1max)
+  //_____________________________________________________________________________
+AliMUONVStore* Create2DMap()
+{
+  return new AliMUON2DMap(true);
+}
+
+  //_____________________________________________________________________________
+void getBoundaries(const AliMUONVStore& store, Int_t dim,
+                   Float_t* xmin, Float_t* xmax)
 {
-  x0min=1E30;
-  x0max=-1E30;
-  x1min=1E30;
-  x1max=-1E30;
+  /// Assuming the store contains AliMUONVCalibParam objects, compute the
+  /// limits of the value contained in the VCalibParam, for each of its dimensions
+  /// xmin and xmax must be of dimension dim
+  
+  for ( Int_t i = 0; i < dim; ++i ) 
+  {
+    xmin[i]=1E30;
+    xmax[i]=-1E30;
+  }
   
   TIter next(store.CreateIterator());
   AliMUONVCalibParam* value;
@@ -99,18 +117,24 @@ void getBoundaries(const AliMUONVStore& store,
       AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
       if (!pad.IsValid()) continue;
       
-      Float_t x0 = value->ValueAsFloat(manuChannel,0);
-      
-      x0min = TMath::Min(x0min,x0);
-      x0max = TMath::Max(x0max,x0);
-      if ( value->Dimension()>1 )
+      for ( Int_t i = 0; i < dim; ++i ) 
       {
-        Float_t x1 = value->ValueAsFloat(manuChannel,1);
-        x1min = TMath::Min(x1min,x1);
-        x1max = TMath::Max(x1max,x1);
+        Float_t x0 = value->ValueAsFloat(manuChannel,i);
+      
+        xmin[i] = TMath::Min(xmin[i],x0);
+        xmax[i] = TMath::Max(xmax[i],x0);
       }
     }
-  }  
+  }
+
+  for ( Int_t i = 0; i < dim; ++i ) 
+  {
+    if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 ) 
+    {
+      xmin[i] -= 1;
+      xmax[i] += 1;
+    }
+  }
 }
 
 //_____________________________________________________________________________
@@ -137,30 +161,19 @@ Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
 AliMUONCDB::AliMUONCDB(const char* cdbpath)
 : TObject(),
   fCDBPath(cdbpath),
-  fManuList(0x0)
+  fMaxNofChannelsToGenerate(-1)
 {
-    /// ctor
+  /// ctor
+    // Load mapping
+    if ( ! AliMpCDB::LoadMpSegmentation() ) {
+      AliFatal("Could not access mapping from OCDB !");
+    }
 }
 
 //_____________________________________________________________________________
 AliMUONCDB::~AliMUONCDB()
 {
   /// dtor
-  delete fManuList;
-}
-
-//_____________________________________________________________________________
-TList*
-AliMUONCDB::ManuList()
-{
-  /// return (and create if necessary) the list of (de,manu) pairs
-  if (!fManuList) 
-  {
-    AliInfo("Generating ManuList...");
-    fManuList = AliMpManuList::ManuList();
-    AliInfo("Manu List generated.");
-  }
-  return fManuList;
 }
 
 //_____________________________________________________________________________
@@ -171,14 +184,16 @@ AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
   /// creates a store which contains store1-store2
   /// if opt="abs" the difference is absolute one,
   /// if opt="rel" then what is stored is (store1-store2)/store1
+  /// if opt="percent" then what is stored is rel*100
+  ///
   /// WARNING Works only for stores which holds AliMUONVCalibParam objects
   
   TString sopt(opt);
   sopt.ToUpper();
   
-  if ( !sopt.Contains("ABS") && !sopt.Contains("REL") )
+  if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
   {
-    AliErrorClass(Form("opt %s not supported. Only ABS or REL are",opt));
+    AliErrorClass(Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
     return 0x0;
   }
   
@@ -211,7 +226,7 @@ AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
         {
           value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
         }
-        else if ( sopt.Contains("REL") )
+        else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
         {
           if ( param->ValueAsFloat(i,j) ) 
           {
@@ -221,6 +236,7 @@ AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
           {
             continue;
           }
+          if ( sopt.Contains("PERCENT") ) value *= 100.0;
         }
         param->SetValueAsFloat(i,j,value);
       }      
@@ -233,89 +249,67 @@ AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
 void 
 AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
 {
-  /// Make a plot of the first 1 or 2 dimensions of the AliMUONVCalibParam
+  /// Make histograms of each dimension of the AliMUONVCalibParam
   /// contained inside store.
   /// It produces histograms named name_0, name_1, etc...
   
-  Float_t x0min, x0max, x1min, x1max;
-  
-  getBoundaries(store,x0min,x0max,x1min,x1max);
-  
-  if ( x0min > x0max ) 
-  {
-    cerr << Form("Something is wrong with boundaries : x0(min,max)=%e,%e",
-                 x0min,x0max) << endl;
-    return;
-  }
-
-  if ( TMath::Abs(x0min-x0max) < 1E-3 ) 
-  {
-    x0min -= 1;
-    x0max += 1;
-  }
-  
-  TH1* h0 = new TH1F(Form("%s_0",name),Form("%s_0",name),
-                    nbins,x0min,x0max);
-  
-  TH1* h1(0);
-  
-  if ( x1max > x1min )
-  {
-    h1 = new TH1F(Form("%s_1",name),Form("%s_1",name),
-                  nbins,x1min,x1max);
-  }
-  
-  TIter next(ManuList());
-  AliMpIntPair* p;
+  TIter next(store.CreateIterator());
+  AliMUONVCalibParam* param;
   Int_t n(0);
-  Int_t nPerStation[7];
+  const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
+  Int_t* nPerStation = new Int_t[kNStations];
+  TH1** h(0x0);
   
-  for ( Int_t i = 0; i < 7; ++i ) nPerStation[i]=0;
+  for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
   
-  while ( ( p = (AliMpIntPair*)next() ) )
+  while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
   {
-    Int_t detElemId = p->GetFirst();
-    Int_t manuId = p->GetSecond();
-    Int_t station = AliMpDEManager::GetChamberId(detElemId);
+    if (!h)
+    {
+      Int_t dim = param->Dimension();
+      h = new TH1*[dim];
+      Float_t* xmin = new Float_t[dim];
+      Float_t* xmax = new Float_t[dim];
+      getBoundaries(store,dim,xmin,xmax);
+      
+      for ( Int_t i = 0; i < dim; ++i ) 
+      {
+        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()));
+      }
+    }
+    
+    Int_t detElemId = param->ID0();
+    Int_t manuId = param->ID1();
+    Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
     
     const AliMpVSegmentation* seg = 
       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
     
-    AliMUONVCalibParam* value = 
-      dynamic_cast<AliMUONVCalibParam*>(store.FindObject(detElemId,manuId));
-    
-    if (value)
+    for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
     {
-      for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
-      {
-        AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
-        if (!pad.IsValid()) continue;
+      AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
+      if (!pad.IsValid()) continue;
 
-        ++n;
-        ++nPerStation[station];
-        Float_t x = value->ValueAsFloat(manuChannel,0);
-        if ( x>1E4 ) 
-        {
-          AliInfo(Form("DE %d Manu %d Ch %d x=%e",detElemId,manuId,manuChannel,x));
-        }
-        h0->Fill(x);
-        if (h1)
-        {
-          h1->Fill(value->ValueAsFloat(manuChannel,1));
-        }
+      ++n;
+      ++nPerStation[station];
+      
+      for ( Int_t dim = 0; dim < param->Dimension(); ++dim ) 
+      {
+        h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
       }
     }
-    else
-    {
-      AliWarning(Form("Got a null value for DE=%d manuId=%d",detElemId,manuId));
-    }
-  }
+  } 
   
-  AliInfo(Form("Number of channels = %d",n));
-  for ( Int_t i = 0; i < 7; ++i )
+  for ( Int_t i = 0; i < kNStations; ++i )
   {
     AliInfo(Form("Station %d %d ",(i+1),nPerStation[i]));
   }
+
+  AliInfo(Form("Number of channels = %d",n));
+  
+  delete[] nPerStation;
 }
 
 //_____________________________________________________________________________
@@ -324,7 +318,7 @@ AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
 {
   /// Create a HV store
   
-  AliMUONHVNamer hvNamer;
+  AliMpHVNamer hvNamer;
   
   TObjArray* aliases = hvNamer.GenerateAliases();
   
@@ -387,10 +381,8 @@ AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues
   /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
   /// otherwise mean and sigma are from a gaussian (with parameters
   /// defined below by the kPedestal* constants)
-  
-  TIter next(ManuList());
-  
-  AliMpIntPair* p;
+
+  AliCodeTimerAuto("");
   
   Int_t nchannels(0);
   Int_t nmanus(0);
@@ -400,23 +392,24 @@ AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues
   const Float_t kPedestalMeanSigma(10);
   const Float_t kPedestalSigmaMean(1.0);
   const Float_t kPedestalSigmaSigma(0.2);
+
+  Int_t detElemId;
+  Int_t manuId;
+    
+  AliMpManuIterator it;
   
-  while ( ( p = (AliMpIntPair*)next() ) )
+  while ( it.Next(detElemId,manuId) )
   {
     ++nmanus;
 
-    Int_t detElemId = p->GetFirst();    
-    Int_t manuId = p->GetSecond();
-    
-    AliMUONVCalibParam* ped = new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
-    
-    const AliMpVSegmentation* seg = 
-      AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
+    AliMUONVCalibParam* ped = 
+      new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
+
+    AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
     
     for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
     {
-      AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
-      if (!pad.IsValid()) continue;
+      if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
       
       ++nchannels;
       
@@ -431,7 +424,11 @@ AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues
       else
       {
         Bool_t positive(kTRUE);
-        meanPedestal = GetRandom(kPedestalMeanMean,kPedestalMeanSigma,positive);
+        meanPedestal = 0.0;
+        while ( meanPedestal == 0.0 ) // avoid strict zero 
+        {
+          meanPedestal = GetRandom(kPedestalMeanMean,kPedestalMeanSigma,positive);
+        }
         sigmaPedestal = GetRandom(kPedestalSigmaMean,kPedestalSigmaSigma,positive);
       }
       ped->SetValueAsFloat(manuChannel,0,meanPedestal);
@@ -443,11 +440,65 @@ AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues
     {
       AliError(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));
   return nchannels;
+}
+
+//_____________________________________________________________________________
+Int_t
+AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
+{
+  /// Read the capacitance values from file and append them to the capaStore
+  
+  AliCodeTimerAuto(Form("file=%s",file));
+  
+  ifstream in(gSystem->ExpandPathName(file));
+  if (in.bad()) return 0;
+  
+  Int_t ngenerated(0);
+  
+  char line[1024];
+  Int_t serialNumber(-1);
+  AliMUONVCalibParam* param(0x0);
+  
+  while ( in.getline(line,1024,'\n') )
+  {
+    if ( isdigit(line[0]) ) 
+    {
+      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;
+    }
+    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 ngenerated;
 }
 
 //_____________________________________________________________________________
@@ -457,25 +508,27 @@ AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
   /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
   /// otherwise they are from a gaussian with parameters defined in the
   /// kCapa* constants below.
-  
-  TIter next(ManuList());
-  
-  AliMpIntPair* p;
+
+  AliCodeTimerAuto("");
   
   Int_t nchannels(0);
   Int_t nmanus(0);
   Int_t nmanusOK(0); // manus for which we got the serial number
     
-  const Float_t kCapaMean(1.0);
-  const Float_t kCapaSigma(0.5);
+  const Float_t kCapaMean(0.3);
+  const Float_t kCapaSigma(0.1);
+  const Float_t kInjectionGainMean(3);
+  const Float_t kInjectionGainSigma(1);
+
+  Int_t detElemId;
+  Int_t manuId;
   
-  while ( ( p = (AliMpIntPair*)next() ) )
+  AliMpManuIterator it;
+  
+  while ( it.Next(detElemId,manuId) )
   {
     ++nmanus;
     
-    Int_t detElemId = p->GetFirst();
-    Int_t manuId = p->GetSecond();
-    
     AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId); 
     Int_t serialNumber = de->GetManuSerialFromId(manuId);
       
@@ -483,14 +536,11 @@ AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
     
     ++nmanusOK;
     
-    const AliMpVSegmentation* seg = 
-      AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
-
     AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
     
     if (!capa)
     {
-      capa = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
+      capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
       Bool_t ok = capaStore.Add(capa);
       if (!ok)
       {
@@ -500,22 +550,25 @@ AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
     
     for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
     {
-      AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
-      if (!pad.IsValid()) continue;
+      if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
       
       ++nchannels;
       
       Float_t capaValue;
+      Float_t injectionGain;
       
       if ( defaultValues ) 
       {
         capaValue = 1.0;
+        injectionGain = 1.0;
       }
       else
       {
         capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
+        injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
       }
       capa->SetValueAsFloat(manuChannel,0,capaValue);
+      capa->SetValueAsFloat(manuChannel,1,injectionGain);
     }
   }
   
@@ -542,9 +595,7 @@ AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
   /// otherwise parameters are taken from gaussians with parameters 
   /// defined in the k* constants below.
   
-  TIter next(ManuList());
-  
-  AliMpIntPair* p;
+  AliCodeTimerAuto("");
   
   Int_t nchannels(0);
   Int_t nmanus(0);
@@ -559,27 +610,26 @@ AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
   const Int_t kThresMean(1600);
   const Int_t kThresSigma(100);
   
-  while ( ( p = (AliMpIntPair*)next() ) )
+  Int_t detElemId;
+  Int_t manuId;
+  
+  AliMpManuIterator it;
+  
+  while ( it.Next(detElemId,manuId) )
   {
     ++nmanus;
 
-    Int_t detElemId = p->GetFirst();
-    Int_t manuId = p->GetSecond();
-
     AliMUONVCalibParam* gain = 
       new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
                               detElemId,
                               manuId,
                               AliMUONVCalibParam::InvalidFloatValue());
 
-
-    const AliMpVSegmentation* seg = 
-      AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
+    AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
 
     for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
     {
-      AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
-      if (!pad.IsValid()) continue;
+      if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
       
       ++nchannels;
       
@@ -607,6 +657,7 @@ AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
     {
       AliError(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));
@@ -619,6 +670,8 @@ AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks) const
 {
   /// Generate local trigger masks store. All masks are set to FFFF
   
+  AliCodeTimerAuto("");
+  
   Int_t ngenerated(0);
   // Generate fake mask values for 234 localboards and put that into
   // one single container (localBoardMasks)
@@ -643,17 +696,18 @@ AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks) const
 Int_t
 AliMUONCDB::MakeRegionalTriggerMaskStore(AliMUONVStore& rtm) const
 {
-  /// Make a regional trigger masks store. All masks are set to 3F
+  /// Make a regional trigger masks store. Mask is set to FFFF for each local board (Ch.F.)
+  
+  AliCodeTimerAuto("");
   
   Int_t ngenerated(0);
   for ( Int_t i = 0; i < 16; ++i )
   {
-    AliMUONVCalibParam* regionalBoard = new AliMUONCalibParamNI(1,16,i,0,0);
-    for ( Int_t j = 0; j < 16; ++j )
-    {
-      regionalBoard->SetValueAsInt(j,0,0x3F);
-      ++ngenerated;
-    }
+    AliMUONVCalibParam* regionalBoard = new AliMUONCalibParamNI(1,1,i,0,0);
+
+    regionalBoard->SetValueAsInt(0,0,0xFFFF);
+    ++ngenerated;
+      
     rtm.Add(regionalBoard);
   }
   
@@ -664,13 +718,15 @@ AliMUONCDB::MakeRegionalTriggerMaskStore(AliMUONVStore& rtm) const
 Int_t 
 AliMUONCDB::MakeGlobalTriggerMaskStore(AliMUONVCalibParam& gtm) const
 {
-  /// Make a global trigger masks store. All masks set to FFF
+  /// Make a global trigger masks store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
+  
+  AliCodeTimerAuto("");
   
   Int_t ngenerated(0);
   
-  for ( Int_t j = 0; j < 16; ++j )
+  for ( Int_t j = 0; j < 2; ++j )
   {
-    gtm.SetValueAsInt(j,0,0xFFF);
+    gtm.SetValueAsInt(j,0,0x00);
     ++ngenerated;
   }
   return ngenerated;
@@ -682,6 +738,8 @@ AliMUONCDB::MakeTriggerLUT(const char* file) const
 {
   /// Make a triggerlut object, from a file.
   
+  AliCodeTimerAuto("");
+  
   AliMUONTriggerLut* lut = new AliMUONTriggerLut;
   lut->ReadFromFile(file);
   return lut;
@@ -693,9 +751,29 @@ AliMUONCDB::MakeTriggerEfficiency(const char* file) const
 {
   /// Make a trigger efficiency object from a file.
   
+  AliCodeTimerAuto("");
+  
   return new AliMUONTriggerEfficiencyCells(file);
 }
 
+//_____________________________________________________________________________
+void 
+AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object, 
+                       Int_t startRun, Int_t endRun, 
+                       const char* filename)
+{
+  /// 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);
+}
+
 //_____________________________________________________________________________
 void 
 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object, 
@@ -728,25 +806,21 @@ AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
   /// Fill the neighbours store with, for each channel, a TObjArray of its
   /// neighbouring pads (including itself)
   
-  AliInfo("Generating NeighbourStore. This will take a while. Please be patient.");
-  
-  TStopwatch timer;
-  
-  timer.Start(kTRUE);
-  
-  TIter next(ManuList());
+  AliCodeTimerAuto("");
   
-  AliMpIntPair* p;
+  AliInfo("Generating NeighbourStore. This will take a while. Please be patient.");
   
   Int_t nchannels(0);
   
   TObjArray tmp;
+
+  Int_t detElemId;
+  Int_t manuId;
+  
+  AliMpManuIterator it;
   
-  while ( ( p = (AliMpIntPair*)next() ) )
+  while ( it.Next(detElemId,manuId) )
   {
-    Int_t detElemId = p->GetFirst();
-    Int_t manuId = p->GetSecond();
-    
     const AliMpVSegmentation* seg = 
       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
     
@@ -780,26 +854,34 @@ AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
             
         for ( Int_t i = 0; i < nofPadNeighbours; ++i )
         {
-          AliMpPad* pad = static_cast<AliMpPad*>(tmp.At(i));
+          AliMpPad* pad = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
           Int_t x;
-          Bool_t ok = calibParam->PackValues(pad->GetLocation().GetFirst(),pad->GetLocation().GetSecond(),x);
-          if (!ok)
-          {
-            AliError("Could not pack value. Something is seriously wrong. Please check");
-            StdoutToAliError(pad->Print(););
-            return -1;
-          }
+//          Bool_t ok =
+          calibParam->PackValues(pad->GetLocation().GetFirst(),pad->GetLocation().GetSecond(),x);
+//          if (!ok)
+//          {
+//            AliError("Could not pack value. Something is seriously wrong. Please check");
+//            StdoutToAliError(pad->Print(););
+//            return -1;
+//          }
           calibParam->SetValueAsInt(manuChannel,i,x);
         }
       }
     }
     }
   
-  timer.Print();
-  
   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)
@@ -838,7 +920,7 @@ AliMUONCDB::WriteGlobalTriggerMasks(Int_t startRun, Int_t endRun)
 {  
   /// Write global trigger masks to OCDB
   
-  AliMUONVCalibParam* gtm = new AliMUONCalibParamNI(1,16,1,0,0);
+  AliMUONVCalibParam* gtm = new AliMUONCalibParamNI(1,2,1,0,0);
 
   Int_t ngenerated = MakeGlobalTriggerMaskStore(*gtm);
   AliInfo(Form("Ngenerated = %d",ngenerated));
@@ -883,7 +965,7 @@ AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
 {
   /// Write neighbours to OCDB
   
-  AliMUONVStore* neighbours = new AliMUON2DMap(kTRUE);
+  AliMUONVStore* neighbours = Create2DMap();
   Int_t ngenerated = MakeNeighbourStore(*neighbours);
   AliInfo(Form("Ngenerated = %d",ngenerated));
   if (ngenerated>0)
@@ -923,7 +1005,7 @@ AliMUONCDB::WritePedestals(Bool_t defaultValues,
   /// store them into CDB located at cdbpath, with a validity period
   /// ranging from startRun to endRun
   
-  AliMUONVStore* pedestalStore = new AliMUON2DMap(true);
+  AliMUONVStore* pedestalStore = Create2DMap();
   Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
   AliInfo(Form("Ngenerated = %d",ngenerated));
   WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
@@ -941,13 +1023,32 @@ AliMUONCDB::WriteGains(Bool_t defaultValues,
   /// store them into CDB located at cdbpath, with a validity period
   /// ranging from startRun to endRun
   
-  AliMUONVStore* gainStore = new AliMUON2DMap(true);
+  AliMUONVStore* gainStore = Create2DMap();
   Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
   AliInfo(Form("Ngenerated = %d",ngenerated));  
   WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
   delete gainStore;
 }
 
+//_____________________________________________________________________________
+void 
+AliMUONCDB::WriteCapacitances(const char* filename,
+                              Int_t startRun, Int_t endRun)
+{
+  /// read manu capacitance and injection gain values from file 
+  /// and store them into CDB located at cdbpath, with a validity period
+  /// ranging from startRun to endRun
+  
+  AliMUONVStore* capaStore = new AliMUON1DMap(16828);
+  Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
+  AliInfo(Form("Ngenerated = %d",ngenerated));
+  if ( ngenerated > 0 ) 
+  {
+    WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
+  }
+  delete capaStore;
+}
+
 //_____________________________________________________________________________
 void 
 AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
@@ -988,4 +1089,3 @@ AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
   WriteCapacitances(defaultValues,startRun,endRun);
   WriteNeighbours(startRun,endRun);
 }
-