ATLAS Offline Software
TileCondProxyCool.icc
Go to the documentation of this file.
1 //Dear emacs, this is -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // Tile includes
8 #include "TileConditions/TileCondProxyCool.h"
9 #include "TileCalibBlobObjs/TileCalibDrawerFlt.h"
10 #include "TileCalibBlobObjs/TileCalibDrawerBch.h"
11 #include "TileCalibBlobObjs/TileCalibDrawerOfc.h"
12 #include "TileCalibBlobObjs/TileCalibUtils.h"
13 
14 // Athena includes
15 #include "AthenaKernel/errorcheck.h"
16 #include "StoreGate/ReadCondHandle.h"
17 
18 
19 //
20 //____________________________________________________________________
21 template<typename T>
22 TileCondProxyCool<T>::TileCondProxyCool(const std::string& type, const std::string& name,
23  const IInterface* parent)
24  : AthAlgTool(type, name, parent)
25 {
26  declareInterface<ITileCondProxy<T> >(this);
27 }
28 
29 //
30 //____________________________________________________________________
31 template<typename T>
32 StatusCode TileCondProxyCool<T>::initialize() {
33 
34  ATH_MSG_DEBUG( "In initialize() for " << name() );
35 
36  ATH_MSG_INFO( "Creating TileCondProxyCool(" << name()
37  << ") for folder: \"" << m_sourceKey.key() << "\"" );
38 
39  ATH_CHECK( m_sourceKey.initialize() );
40 
41  return StatusCode::SUCCESS;
42 }
43 
44 //
45 //____________________________________________________________________
46 template<typename T>
47 StatusCode TileCondProxyCool<T>::finalize() {
48 
49  ATH_MSG_DEBUG( "finalize called for " << name() );
50  return StatusCode::SUCCESS;
51 
52 }
53 
54 template<typename T>
55 StatusCode TileCondProxyCool<T>::fillCalibData(TileCalibData<T>& calibData,
56  EventIDRange& eventRange) const {
57 
58  ATH_MSG_DEBUG( "createCalibData called for " << name() );
59 
60  SG::ReadCondHandle<CondAttrListCollection> source{m_sourceKey};
61  const CondAttrListCollection* attrListCollection{*source};
62 
63  if (!attrListCollection) {
64  ATH_MSG_ERROR("Failed to retrieve CondAttributeListCollection with key " << m_sourceKey.key());
65  return StatusCode::FAILURE;
66  }
67 
68  //=== Loop over collection by increasing channel number (defaults first!)
69  for (unsigned int drawerIdx = 0; drawerIdx < TileCalibUtils::MAX_DRAWERIDX; ++drawerIdx) {
70 
71  //=== get the BLOB
72  CondAttrListCollection::const_iterator attrListPair = attrListCollection->chanAttrListPair(drawerIdx);
73  const coral::Blob& blob = (attrListPair->second)[0].data<coral::Blob>();
74 
75  if (blob.size()) {
76 
77  //=== Get new TileCalibDrawer instance, interpreting current blob
78  std::unique_ptr<const T> calibDrawer(T::getInstance(blob));
79  calibData.setCalibDrawer(drawerIdx, calibDrawer.release());
80 
81  } else {
82 
83  //=== Default policy
84  if (drawerIdx == 0) {
85  ATH_MSG_ERROR( "No default available!?" );
86  return StatusCode::FAILURE;
87  }
88  //=== Determine default index
89  unsigned int defaultDrawerIdx = TileCalibUtils::getDefaultDrawerIdx(drawerIdx);
90  calibData.setCalibDrawer(drawerIdx, calibData.getCalibDrawer(defaultDrawerIdx));
91 
92  ATH_MSG_VERBOSE( "Using default drawer " << defaultDrawerIdx
93  << " for drawerIdx=" << drawerIdx << endmsg
94  << "... i.e. TileCalibDrawer @ " << calibData.getCalibDrawer(drawerIdx));
95 
96  }
97 
98  } // End drawerIdx
99 
100 
101  // Define validity of the output cond object
102  if(!source.range(eventRange)) {
103  ATH_MSG_ERROR("Failed to retrieve validity range for " << source.key());
104  return StatusCode::FAILURE;
105  }
106 
107 
108  return StatusCode::SUCCESS;
109 }