LCOV - code coverage report
Current view: top level - EMCAL/EMCALbase - AliEMCALTriggerDCSConfigDB.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 29 69 42.0 %
Date: 2016-06-14 17:26:59 Functions: 8 17 47.1 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /*
      17             : 
      18             : 
      19             : 
      20             : 
      21             : Adapted from TRD
      22             : Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
      23             : */
      24             : 
      25             : #include <TClonesArray.h>
      26             : #include <TObjArray.h>
      27             : 
      28             : #include "AliCDBManager.h"
      29             : #include "AliCDBEntry.h"
      30             : #include "AliLog.h"
      31             : 
      32             : #include "AliEMCALTriggerDCSConfigDB.h"
      33             : #include "AliEMCALTriggerDCSConfig.h"
      34             : #include "AliEMCALTriggerSTUDCSConfig.h"
      35             : #include "AliEMCALTriggerTRUDCSConfig.h"
      36             : 
      37          42 : ClassImp(AliEMCALTriggerDCSConfigDB)
      38             : 
      39             : AliEMCALTriggerDCSConfigDB* AliEMCALTriggerDCSConfigDB::fgInstance   = 0;
      40             : Bool_t                      AliEMCALTriggerDCSConfigDB::fgTerminated = kFALSE;
      41             : 
      42             : //_____________________________________________________________________________
      43             : AliEMCALTriggerDCSConfigDB* AliEMCALTriggerDCSConfigDB::Instance()
      44             : {
      45             :         //
      46             :         // Singleton implementation
      47             :         // Returns an instance of this class, it is created if neccessary
      48             :         //
      49             :   
      50          16 :         if (fgTerminated != kFALSE) 
      51             :         {
      52           0 :                 return 0;
      53             :         }
      54             : 
      55           8 :         if (fgInstance == 0) 
      56             :         {
      57           6 :                 fgInstance = new AliEMCALTriggerDCSConfigDB();
      58           3 :         }
      59             : 
      60           8 :         return fgInstance;
      61           8 : }
      62             : 
      63             : //_____________________________________________________________________________
      64             : void AliEMCALTriggerDCSConfigDB::Terminate()
      65             : {
      66             :         //
      67             :         // Singleton implementation
      68             :         // Deletes the instance of this class and sets the terminated flag,
      69             :         // instances cannot be requested anymore
      70             :         // This function can be called several times.
      71             :         //
      72             :   
      73           0 :         fgTerminated = kTRUE;
      74             :   
      75           0 :         if (fgInstance != 0) 
      76             :         {
      77           0 :                 delete fgInstance;
      78           0 :                 fgInstance = 0;
      79           0 :         }
      80           0 : }
      81             : 
      82             : //_____________________________________________________________________________
      83           3 : AliEMCALTriggerDCSConfigDB::AliEMCALTriggerDCSConfigDB() : TObject()
      84           3 : ,fRun(-1)
      85          15 : {
      86             :         //
      87             :         // Default constructor
      88             :         //
      89             :         // TODO Default runnumber is set to 0, this should be changed later
      90             :         //      to an invalid value (e.g. -1) to prevent
      91             :         // TODO invalid calibration data to be used.
      92             :         //
      93             : 
      94          12 :         for (Int_t i = 0; i < kCDBCacheSize; ++i) 
      95             :         {
      96           3 :                 fCDBCache[i]   = 0;
      97           3 :                 fCDBEntries[i] = 0;
      98             :         }
      99           6 : }
     100             : 
     101             : //_____________________________________________________________________________
     102           0 : AliEMCALTriggerDCSConfigDB::AliEMCALTriggerDCSConfigDB(const AliEMCALTriggerDCSConfigDB &c) : TObject(c)
     103           0 : ,fRun(-1)
     104           0 : {
     105             :         //
     106             :         // Copy constructor (not that it make any sense for a singleton...)
     107             :         //
     108             : 
     109           0 :         for (Int_t i = 0; i < kCDBCacheSize; ++i) 
     110             :         {
     111           0 :                 fCDBCache[i]   = 0;
     112           0 :                 fCDBEntries[i] = 0;
     113             :         }
     114           0 : }
     115             : 
     116             : //_____________________________________________________________________________
     117             : AliEMCALTriggerDCSConfigDB &AliEMCALTriggerDCSConfigDB::operator=(const AliEMCALTriggerDCSConfigDB &c) 
     118             : {
     119             :         //
     120             :         // Assignment operator (same as above ...)
     121             :         //
     122           0 :         if (this != &c) 
     123             :         {
     124           0 :                 AliFatal("No assignment operator defined");
     125           0 :         }
     126             : 
     127           0 :         return *this;
     128             : }
     129             : 
     130             : //_____________________________________________________________________________
     131             : AliEMCALTriggerDCSConfigDB::~AliEMCALTriggerDCSConfigDB() 
     132           0 : {
     133             :         //
     134             :         // destructor
     135             :         //
     136           0 :         Invalidate();
     137           0 : }
     138             : 
     139             : //_____________________________________________________________________________
     140             : const TObject *AliEMCALTriggerDCSConfigDB::GetCachedCDBObject(Int_t id)
     141             : {
     142             :         //
     143             :         // Retrieves a cdb object with the given id. The objects are cached as
     144             :         // long as the run number is not changed.
     145             :         //
     146           4 :         switch (id) 
     147             :         {
     148             :                 // Parameters defined per pad and chamber
     149             :                 case kIDTriggerConfig : 
     150           2 :                         return CacheCDBEntry(kIDTriggerConfig, "EMCAL/Calib/Trigger"); 
     151             :                         break;
     152             :                 default:                        
     153           0 :                         AliError("Object not found!");
     154             :                         break;
     155             :         }
     156             : 
     157           0 :         return 0x0;
     158           2 : }
     159             : 
     160             : //_____________________________________________________________________________
     161             : AliCDBEntry* AliEMCALTriggerDCSConfigDB::GetCDBEntry(const char *cdbPath)
     162             : {
     163             :         // 
     164             :         // Retrieves an entry with path <cdbPath> from the CDB.
     165             :         //
     166           6 :         AliCDBEntry *entry = AliCDBManager::Instance()->Get(cdbPath,fRun);
     167             :         
     168           2 :         if (!entry) 
     169             :         { 
     170           0 :                 AliError(Form("Failed to get entry: %s",cdbPath));
     171           0 :                 return 0; 
     172             :         }
     173             :   
     174           2 :         return entry;
     175           2 : }
     176             : 
     177             : //_____________________________________________________________________________
     178             : const TObject *AliEMCALTriggerDCSConfigDB::CacheCDBEntry(Int_t id, const char *cdbPath)
     179             : {
     180             :         //
     181             :         // Caches the entry <id> with cdb path <cdbPath>
     182             :         //
     183             :   
     184           4 :         if (!fCDBCache[id]) 
     185             :         {
     186           2 :                 fCDBEntries[id] = GetCDBEntry(cdbPath);
     187             :                 
     188           4 :                 if (fCDBEntries[id]) fCDBCache[id] = fCDBEntries[id]->GetObject();
     189             :         }
     190             : 
     191           2 :         return fCDBCache[id];
     192             : }
     193             : 
     194             : //_____________________________________________________________________________
     195             : void AliEMCALTriggerDCSConfigDB::SetRun(Long64_t run)
     196             : {
     197             :   //
     198             :   // Sets current run number. Calibration data is read from the corresponding file.
     199             :   // When the run number changes the caching is invalidated.
     200             :   //
     201             : 
     202           0 :   if (fRun == run) return;
     203             : 
     204           0 :   fRun = run;
     205             : 
     206           0 :   Invalidate();
     207           0 : }
     208             : 
     209             : //_____________________________________________________________________________
     210             : void AliEMCALTriggerDCSConfigDB::Invalidate()
     211             : {
     212             :         //
     213             :         // Invalidates cache (when run number is changed).
     214             :         //
     215           0 :         for (Int_t i = 0; i < kCDBCacheSize; ++i) 
     216             :         {
     217           0 :                 if (fCDBEntries[i]) 
     218             :                 {
     219           0 :                         if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE) 
     220             :                         {
     221           0 :                                 if ((fCDBEntries[i]->IsOwner() == kFALSE) && (fCDBCache[i])) delete fCDBCache[i];
     222             :                                 
     223           0 :                                 delete fCDBEntries[i];
     224             :                         }
     225             :                         
     226           0 :                         fCDBEntries[i] = 0;
     227           0 :                         fCDBCache[i]   = 0;
     228           0 :                 }
     229             :         }
     230           0 : }
     231             : 
     232             : //_____________________________________________________________________________
     233             : const AliEMCALTriggerDCSConfig* AliEMCALTriggerDCSConfigDB::GetTriggerDCSConfig()
     234             : {
     235             :         //
     236             :         // Get DCS config
     237             :         //
     238           8 :         const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
     239             :         
     240           2 :         if (!dcsConf) 
     241             :         {
     242           0 :                 AliError("Trigger DCS configuration not found!");
     243           0 :                 return 0x0;
     244             :         }
     245             :         else
     246           2 :                 return dcsConf;
     247           2 : }

Generated by: LCOV version 1.11