Single entry point to access pedestals and gains from the
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 31 Jan 2006 16:38:23 +0000 (16:38 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 31 Jan 2006 16:38:23 +0000 (16:38 +0000)
(de)calibrator or any class needing the calibration data.
(Laurent)

MUON/AliMUONCalibrationData.cxx [new file with mode: 0644]
MUON/AliMUONCalibrationData.h [new file with mode: 0644]

diff --git a/MUON/AliMUONCalibrationData.cxx b/MUON/AliMUONCalibrationData.cxx
new file mode 100644 (file)
index 0000000..38d1c71
--- /dev/null
@@ -0,0 +1,174 @@
+/**************************************************************************
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+*                                                                        *
+* Author: The ALICE Off-line Project.                                    *
+* Contributors are mentioned in the code where appropriate.              *
+*                                                                        *
+* Permission to use, copy, modify and distribute this software and its   *
+* documentation strictly for non-commercial purposes is hereby granted   *
+* without fee, provided that the above copyright notice appears in all   *
+* copies and that both the copyright notice and this permission notice   *
+* appear in the supporting documentation. The authors make no claims     *
+* about the suitability of this software for any purpose. It is          *
+* provided "as is" without express or implied warranty.                  *
+**************************************************************************/
+
+// $Id$
+
+#include "AliMUONCalibrationData.h"
+
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliMUONCalibParam.h"
+#include "AliLog.h"
+#include "AliMUONV3DStore.h"
+#include "Riostream.h"
+
+ClassImp(AliMUONCalibrationData)
+
+//_____________________________________________________________________________
+AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber, 
+                                               Bool_t deferredInitialization) 
+: TObject(), 
+fIsValid(kTRUE),
+fRunNumber(runNumber), 
+fGains(0x0), 
+fPedestals(0x0)
+{
+  if ( deferredInitialization == kFALSE )
+  {
+    Gains();
+    Pedestals();
+  }
+}
+
+
+//_____________________________________________________________________________
+AliMUONCalibrationData::~AliMUONCalibrationData()
+{
+  delete fPedestals;
+  delete fGains;
+}
+
+//_____________________________________________________________________________
+AliCDBEntry*
+AliMUONCalibrationData::GetEntry(const char* path) const
+{
+  AliInfo(Form("Fetching %s from Condition DataBase for run %d",path,fRunNumber));
+  
+  AliCDBManager* man = AliCDBManager::Instance();
+  if (!man->IsDefaultStorageSet())
+  {
+    AliError("No default CDB storage set !");
+    fIsValid = kFALSE;
+    return 0;
+  }
+  
+  AliCDBStorage* storage = man->GetDefaultStorage();
+  
+  AliCDBEntry* entry = storage->Get(path,fRunNumber);
+  return entry;
+}
+
+//_____________________________________________________________________________
+AliMUONCalibParam*
+AliMUONCalibrationData::Gain(Int_t detElemId, 
+                             Int_t manuId, Int_t manuChannel) const
+{
+  AliMUONCalibParam* gain = 
+  static_cast<AliMUONCalibParam*>(Gains()->Get(detElemId,manuId,manuChannel));
+  if (!gain)
+  {
+    AliError(Form("Could not get gain for detElemId=%d manuId=%d "
+                  "manuChannel=%d",detElemId,manuId,manuChannel));
+  }
+  return gain;
+}
+
+//_____________________________________________________________________________
+AliMUONV3DStore*
+AliMUONCalibrationData::Gains() const
+{
+  if (!fGains)
+  {
+    AliCDBEntry* entry = GetEntry("MUON/Calib/Gains");
+    if (entry)
+    {
+      fGains = dynamic_cast<AliMUONV3DStore*>(entry->GetObject());
+      if (!fGains)
+      {
+        AliError("Gains not of the expected type !!!");
+      }
+    }
+    else
+    {
+      AliError("Could not get gains !");
+    }
+  }
+  return fGains;
+}
+
+//_____________________________________________________________________________
+Bool_t
+AliMUONCalibrationData::IsValid() const
+{
+  return fIsValid;
+}
+
+//_____________________________________________________________________________
+AliMUONV3DStore*
+AliMUONCalibrationData::Pedestals() const
+{
+  if (!fPedestals)
+  {
+    AliCDBEntry* entry = GetEntry("MUON/Calib/Pedestals");
+    if (entry)
+    {
+      fPedestals = dynamic_cast<AliMUONV3DStore*>(entry->GetObject());
+      if (!fPedestals)
+      {
+        AliError("fPedestals not of the expected type !!!");
+      }
+    }
+    else
+    {
+      AliError("Could not get pedestals !");
+    }
+  }
+  return fPedestals;
+}
+
+//_____________________________________________________________________________
+void
+AliMUONCalibrationData::Print(Option_t*) const
+{
+  cout << "RunNumber " << RunNumber()
+    << " fGains=" << fGains
+  << " fPedestals=" << fPedestals
+  << endl;
+}
+
+//_____________________________________________________________________________
+Int_t
+AliMUONCalibrationData::RunNumber() const
+{
+  return fRunNumber;
+}
+
+//_____________________________________________________________________________
+AliMUONCalibParam*
+AliMUONCalibrationData::Pedestal(Int_t detElemId, 
+                                 Int_t manuId, Int_t manuChannel) const
+{
+  AliMUONCalibParam* ped = 
+    static_cast<AliMUONCalibParam*>(Pedestals()->Get(detElemId,manuId,manuChannel));
+  if (!ped)
+  {
+    AliError(Form("Could not get pedestal for detElemId=%d manuId=%d "
+                  "manuChannel=%d",detElemId,manuId,manuChannel));
+  }
+  return ped;
+}
+
+
diff --git a/MUON/AliMUONCalibrationData.h b/MUON/AliMUONCalibrationData.h
new file mode 100644 (file)
index 0000000..87f8286
--- /dev/null
@@ -0,0 +1,54 @@
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+* See cxx source for full Copyright notice                               */
+
+// $Id$
+
+/// \ingroup base
+/// \class AliMUONCalibrationData
+/// \brief Single entry point to access pedestals and gains from the
+/// (de)calibrator or any class needing the calibration data
+/// 
+/// \author Laurent Aphecetche
+
+#ifndef ALIMUONCALIBRATIONDATA_H
+#define ALIMUONCALIBRATIONDATA_H
+
+#ifndef ROOT_TObject
+#include "TObject.h"
+#endif
+
+class AliCDBEntry;
+class AliMUONCalibParam;
+class AliMUONV3DStore;
+
+class AliMUONCalibrationData : public TObject
+{
+public:
+  AliMUONCalibrationData(Int_t runNumber=-1, Bool_t deferredInitialization=kTRUE);
+  virtual ~AliMUONCalibrationData();
+  
+  AliMUONCalibParam* Gain(Int_t detElemId, Int_t manuId, Int_t manuChannel) const;
+  
+  Bool_t IsValid() const;
+  
+  AliMUONCalibParam* Pedestal(Int_t detElemId, Int_t manuId, Int_t manuChannel) const;
+  
+  virtual void Print(Option_t* opt="") const;
+  
+  Int_t RunNumber() const;  
+  
+private:
+  AliCDBEntry* GetEntry(const char* path) const;
+  AliMUONV3DStore* Gains() const;
+  AliMUONV3DStore* Pedestals() const;
+
+private:  
+  mutable Bool_t fIsValid;
+  Int_t fRunNumber;
+  mutable AliMUONV3DStore* fGains; //!
+  mutable AliMUONV3DStore* fPedestals; //!
+  
+  ClassDef(AliMUONCalibrationData,1) // Storage for all MUON calibration data.
+};
+
+#endif