]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONCDB.cxx
One more warning fixed
[u/mrichter/AliRoot.git] / MUON / AliMUONCDB.cxx
index def339bb2d39ef211945e1b56da969a3fdd882af..6fcf7bbeb61c13b6b44b8de46bb3185b94572f29 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 "AliMUONTrackerIO.h"
 #include "AliMUONTriggerEfficiencyCells.h"
 #include "AliMUONTriggerLut.h"
 #include "AliMUONVStore.h"
 #include "AliMUONVCalibParam.h"
 #include "AliMUONVCalibParam.h"
+#include "AliMUONGlobalCrateConfig.h"
+#include "AliMUONRegionalTriggerConfig.h"
+
+#include "AliMpCDB.h"
 #include "AliMpConstants.h"
 #include "AliMpDDLStore.h"
 #include "AliMpDEIterator.h"
 #include "AliMpDEManager.h"
 #include "AliMpDetElement.h"
-#include "AliMpManuList.h"
+#include "AliMpFiles.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
 {
-//_____________________________________________________________________________
+  //_____________________________________________________________________________
+AliMUONVStore* Create2DMap()
+{
+  return new AliMUON2DMap(true);
+}
+
+  //_____________________________________________________________________________
 void getBoundaries(const AliMUONVStore& store, Int_t dim,
                    Float_t* xmin, Float_t* xmax)
 {
@@ -147,31 +165,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::LoadDDLStore() ) {
+      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;
 }
 
 //_____________________________________________________________________________
@@ -316,7 +322,7 @@ AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
 {
   /// Create a HV store
   
-  AliMUONHVNamer hvNamer;
+  AliMpHVNamer hvNamer;
   
   TObjArray* aliases = hvNamer.GenerateAliases();
   
@@ -379,10 +385,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);
@@ -392,24 +396,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);
+
+    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;
       
@@ -445,7 +449,15 @@ AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues
   
   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
   
+  return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
 }
 
 //_____________________________________________________________________________
@@ -455,25 +467,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;
+  
+  AliMpManuIterator it;
   
-  while ( ( p = (AliMpIntPair*)next() ) )
+  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);
       
@@ -481,14 +495,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)
       {
@@ -498,22 +509,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);
     }
   }
   
@@ -540,44 +554,41 @@ 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);
     
   const Int_t kSaturation(3000);
   const Double_t kA0Mean(1.2);
-    const Double_t kA0Sigma(0.1);
-    const Double_t kA1Mean(1E-5);
-      const Double_t kA1Sigma(1E-6);
+  const Double_t kA0Sigma(0.1);
+  const Double_t kA1Mean(1E-5);
+  const Double_t kA1Sigma(1E-6);
   const Double_t kQualMean(0xFF);
   const Double_t kQualSigma(0x10);
   const Int_t kThresMean(1600);
-    const Int_t kThresSigma(100);
+  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;
       
@@ -618,10 +629,12 @@ 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)
-  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 )
@@ -640,47 +653,37 @@ AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks) const
 
 //_____________________________________________________________________________
 Int_t
-AliMUONCDB::MakeRegionalTriggerMaskStore(AliMUONVStore& rtm) const
+AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm) const
 {
-  /// Make a regional trigger masks store. All masks are set to 3F
+  /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
   
-  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;
-    }
-    rtm.Add(regionalBoard);
-  }
+  AliCodeTimerAuto("");
   
-  return ngenerated;
+    return rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping());
+      
 }
 
+
 //_____________________________________________________________________________
 Int_t 
-AliMUONCDB::MakeGlobalTriggerMaskStore(AliMUONVCalibParam& gtm) const
+AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm) const
 {
-  /// Make a global trigger masks store. All masks set to FFF
-  
-  Int_t ngenerated(0);
+  /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
   
-  for ( Int_t j = 0; j < 16; ++j )
-  {
-    gtm.SetValueAsInt(j,0,0xFFF);
-    ++ngenerated;
-  }
-  return ngenerated;
+  AliCodeTimerAuto("");
+
+    return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
 }
 
+
 //_____________________________________________________________________________
 AliMUONTriggerLut* 
 AliMUONCDB::MakeTriggerLUT(const char* file) const
 {
   /// Make a triggerlut object, from a file.
   
+  AliCodeTimerAuto("");
+  
   AliMUONTriggerLut* lut = new AliMUONTriggerLut;
   lut->ReadFromFile(file);
   return lut;
@@ -692,9 +695,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, 
@@ -727,25 +750,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);
+  AliCodeTimerAuto("");
   
-  TIter next(ManuList());
-  
-  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);
     
@@ -779,23 +798,22 @@ AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
             
         for ( Int_t i = 0; i < nofPadNeighbours; ++i )
         {
-          AliMpPad* pad = static_cast<AliMpPad*>(tmp.At(i));
+          AliMpPad* p = 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(p->GetLocation().GetFirst(),p->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;
 }
 
@@ -826,37 +844,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);
+  AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
+  Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
   AliInfo(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,16,1,0,0);
+  AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
 
-  Int_t ngenerated = MakeGlobalTriggerMaskStore(*gtm);
+  Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
   AliInfo(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)
@@ -891,7 +911,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)
@@ -931,7 +951,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);
@@ -949,13 +969,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,
@@ -979,8 +1018,8 @@ AliMUONCDB::WriteTrigger(Int_t startRun, Int_t endRun)
 {
   /// Writes all Trigger related calibration to CDB
   WriteLocalTriggerMasks(startRun,endRun);
-  WriteRegionalTriggerMasks(startRun,endRun);
-  WriteGlobalTriggerMasks(startRun,endRun);
+  WriteRegionalTriggerConfig(startRun,endRun);
+  WriteGlobalTriggerConfig(startRun,endRun);
   WriteTriggerLut(startRun,endRun);
   WriteTriggerEfficiency(startRun,endRun);
 }