ATLAS Offline Software
TileHid2RESrcIDCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Tile includes
8 
9 // Athena includes
10 
11 #include "StoreGate/ReadHandle.h"
14 
16 
17  ATH_MSG_DEBUG( "In initialize()" );
18 
19  // Retrieve TileHWID helper from det store
22 
23  m_initFromDB = !m_rodStatusProxy.empty();
24  ATH_CHECK( m_rodStatusProxy.retrieve(EnableTool{m_initFromDB}) );
25 
26  // Initilize from event if length of ROD2ROBmap is and odd value
27  m_initFromEvent = (!m_initFromDB && (m_ROD2ROBmap.value().size() % 2 == 1));
28  if (m_initFromEvent) {
29  ATH_CHECK(m_robSvc.retrieve());
30  }
31 
32  return StatusCode::SUCCESS;
33 }
34 
35 
36 StatusCode TileHid2RESrcIDCondAlg::execute(const EventContext& ctx) const {
37 
39 
40  if (hid2ReSrcId.isValid()) {
41  ATH_MSG_DEBUG("Found valid TileHid2RESrcID: " << hid2ReSrcId.key());
42  return StatusCode::SUCCESS;
43  }
44 
45  const uint32_t run = ctx.eventID().run_number();
46 
47  EventIDRange eventRange;
48  std::unique_ptr<TileHid2RESrcID> hid2re;
49 
50  if (m_initFromDB) {
51  hid2re = std::make_unique<TileHid2RESrcID>(m_tileHWID, run);
52 
53  auto calibData = std::make_unique<TileCalibData<TileCalibDrawerInt>>();
54  ATH_CHECK( m_rodStatusProxy->fillCalibData(*calibData, eventRange) );
55 
56  std::vector<std::vector<uint32_t>> allMap;
58 
59  for (unsigned int drawerIdx = 0; drawerIdx < TileCalibUtils::MAX_DRAWERIDX; ++drawerIdx) {
60  const TileCalibDrawerInt* calibDrawer = calibData->getCalibDrawer(drawerIdx);
61  unsigned int nGains = calibDrawer->getNGains();
62  unsigned int nChannels = calibDrawer->getNChans();
63  unsigned int nValues = calibDrawer->getObjSizeUint32();
64  for (unsigned int channel = 0; channel < nChannels; ++channel) {
65  for (unsigned int adc = 0; adc < nGains; ++adc) {
66  std::vector<uint32_t> fragMap;
67  fragMap.reserve(nValues);
68  for (unsigned int i = 0; i < nValues; ++i) {
69  fragMap.push_back( calibDrawer->getData(channel, adc, i) );
70  }
71  allMap.emplace_back(std::move(fragMap));
72  }
73  }
74  }
75 
76  hid2re->initialize(allMap);
77 
78  } else if (m_forHLT) {
79  hid2re = std::make_unique<TileHid2RESrcID>(m_tileHWID, run);
80  } else {
81 
82  unsigned int fullMode = (m_fullTileRODs > 0) ? m_fullTileRODs.value() : run;
83  hid2re = std::make_unique<TileHid2RESrcID>(m_tileHWID, fullMode);
84 
85  // Check whether we want to overwrite default ROB IDs
86  if (m_initFromEvent) {
87  ATH_MSG_DEBUG( "Length of ROD2ROBmap is and odd value, "
88  << " means that we'll scan event for all fragments to create proper map" );
89 
90  bool of2Default{true};
91  const eformat::FullEventFragment<const uint32_t*> * event = m_robSvc->getEvent(ctx);
92  try {
93  event->check_tree();
94  hid2re->setROD2ROBmap(event, of2Default, msg());
95  } catch (...) {
96  ATH_MSG_DEBUG( "Bad event, mapping might be incomplete! " );
97  // Bad event, but process anyhow (well, till next bug report )
98  hid2re->setROD2ROBmap(event, of2Default, msg());
99  }
100  } else if (m_ROD2ROBmap.empty()) {
101  ATH_MSG_DEBUG( "Length of ROD2ROBmap vector is zero, "
102  << " means that predefined mapping for run " << fullMode << " will be used " );
103  } else {
104  ATH_MSG_DEBUG( "Apply additional remapping for " << m_ROD2ROBmap.value().size()/2 << " fragments from jobOptions ");
105  hid2re->setROD2ROBmap(m_ROD2ROBmap.value(), msg());
106  }
107 
108  }
109 
110  if (!m_initFromDB) {
111  // Set validity of TileHid2RESrcID for current run
112  eventRange = EventIDRange(EventIDBase{run, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM, 0},
113  EventIDBase{run + 1, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM, 0});
114  }
115 
116  hid2re->printSpecial(msg());
117 
118  ATH_CHECK( hid2ReSrcId.record(eventRange, std::move(hid2re)) );
119 
120  ATH_MSG_VERBOSE("Recorded TileHid2RESrcID object with "
121  << hid2ReSrcId.key()
122  << " with EventRange " << eventRange
123  << " into Conditions Store");
124 
125  return StatusCode::SUCCESS;
126 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileHid2RESrcID::initialize
void initialize(uint32_t runnum)
Definition: TileHid2RESrcID.cxx:60
RPDUtils::nChannels
unsigned constexpr int nChannels
Definition: RPDUtils.h:23
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TileHid2RESrcIDCondAlg::initialize
virtual StatusCode initialize() override
Definition: TileHid2RESrcIDCondAlg.cxx:15
TileCalibUtils::MAX_DRAWERIDX
static const unsigned int MAX_DRAWERIDX
Maximal drawer index
Definition: TileCalibUtils.h:143
TileHid2RESrcID::setROD2ROBmap
void setROD2ROBmap(const std::vector< std::string > &ROD2ROB, MsgStream &log)
Definition: TileHid2RESrcID.cxx:172
TileHid2RESrcIDCondAlg::m_initFromEvent
bool m_initFromEvent
Definition: TileHid2RESrcIDCondAlg.h:64
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
ROBDataProviderSvc.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TileHid2RESrcID::printSpecial
void printSpecial(MsgStream &log)
Definition: TileHid2RESrcID.cxx:600
TileCalibDrawerInt
Class for storing a 32 bit array of words for each ADC.
Definition: TileCalibDrawerInt.h:23
TileHid2RESrcIDCondAlg.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TileHWID.h
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
lumiFormat.i
int i
Definition: lumiFormat.py:85
TileHid2RESrcIDCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TileHid2RESrcIDCondAlg.cxx:36
TileHid2RESrcIDCondAlg::m_fullTileRODs
Gaudi::Property< unsigned int > m_fullTileRODs
Definition: TileHid2RESrcIDCondAlg.h:45
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
WriteCondHandle.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
run
Definition: run.py:1
TileHid2RESrcIDCondAlg::m_rodStatusProxy
ToolHandle< ITileCondProxy< TileCalibDrawerInt > > m_rodStatusProxy
Tool to get Tile ROD status (e.g.
Definition: TileHid2RESrcIDCondAlg.h:60
TileHid2RESrcIDCondAlg::m_tileHWID
const TileHWID * m_tileHWID
Definition: TileHid2RESrcIDCondAlg.h:63
TileHid2RESrcIDCondAlg::m_ROD2ROBmap
Gaudi::Property< std::vector< std::string > > m_ROD2ROBmap
Definition: TileHid2RESrcIDCondAlg.h:48
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
BchCleanup.calibDrawer
calibDrawer
Definition: BchCleanup.py:217
TileHid2RESrcIDCondAlg::m_robSvc
ServiceHandle< IROBDataProviderSvc > m_robSvc
Name of ROB data provider service.
Definition: TileHid2RESrcIDCondAlg.h:54
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
TileHid2RESrcIDCondAlg::m_hid2ReSrcIdKey
SG::WriteCondHandleKey< TileHid2RESrcID > m_hid2ReSrcIdKey
Name of output TileHid2RESrcID.
Definition: TileHid2RESrcIDCondAlg.h:42
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
TileHid2RESrcIDCondAlg::m_initFromDB
bool m_initFromDB
Definition: TileHid2RESrcIDCondAlg.h:65
TileHid2RESrcIDCondAlg::m_forHLT
Gaudi::Property< bool > m_forHLT
Definition: TileHid2RESrcIDCondAlg.h:37
ReadHandle.h
Handle class for reading from StoreGate.
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
TileCalibUtils::MAX_DRAWR0
static const unsigned int MAX_DRAWR0
Number of drawers in ROS 0
Definition: TileCalibUtils.h:140