ATLAS Offline Software
Loading...
Searching...
No Matches
RIO_OnTrackErrorScalingCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
10#include <limits>
11
12RIO_OnTrackErrorScalingCondAlg::RIO_OnTrackErrorScalingCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
13 : ::AthCondAlgorithm(name, pSvcLocator)
14{
15}
16
18 ATH_CHECK(m_readKey.initialize());
19
20 if (m_errorScalingType.size() != m_writeKey.size()) {
21 ATH_MSG_FATAL("Number of error scaling types and out keys do not match: " << m_errorScalingType.size() << " != " << m_writeKey.size()
22 << " There should be exactly one out key for each error scaling type.");
23 return StatusCode::FAILURE;
24 }
25 ATH_CHECK( m_writeKey.initialize() );
26
27 m_kits.clear();
28 m_kits.reserve(m_errorScalingType.size());
29 for (const std::string &type_name : m_errorScalingType ) {
30 ATH_CHECK( addErrorScaling(type_name) );
31 }
32 for (const std::string &attribut_name : m_attributIgnoreList ) {
33 registerAttribute(attribut_name, std::numeric_limits<unsigned int>::max(),0);
34 }
35
36 return StatusCode::SUCCESS;
37}
38
39
40void RIO_OnTrackErrorScalingCondAlg::registerAttribute(const std::string& name, unsigned int type_idx, unsigned int param_idx) {
41 if (!m_attributeMap.insert( std::make_pair(name, std::make_pair(type_idx,param_idx)) ).second) {
42 std::stringstream message;
43 message << "Failed to add RIO_OnTrackErrorScaling paramter : " << name << ".";
44 throw std::runtime_error(message.str());
45 }
46}
47
48StatusCode RIO_OnTrackErrorScalingCondAlg::addErrorScaling (const std::string &type_name) {
49 const RIO_OnTrackErrorScalingKit *the_kit(nullptr);
50 try {
51 the_kit = &(RIO_OnTrackErrorScalingKitManager::instance().kit( type_name ));
52 }
53 catch (std::runtime_error &err) {
54 std::stringstream types;
56 ATH_MSG_FATAL( "Invalid ErrorScaling type name : " << type_name << ". Registered types:" << types.str() );
57 return StatusCode::FAILURE;
58 }
59 catch (std::exception &err) {
60 std::stringstream types;
62 ATH_MSG_FATAL( "Caught exception: " << err.what() << " Invalid ErrorScaling type name : " << type_name << ". Registered types:" << types.str() );
63 return StatusCode::FAILURE;
64 }
65 m_kits.push_back(the_kit);
66 const char* const* parameters=the_kit->paramNames();
67 for (unsigned int param_i=0; param_i<the_kit->nParametres(); ++param_i) {
68 registerAttribute( std::string(parameters[param_i]), m_kits.size()-1, param_i);
69 }
70
71 return StatusCode::SUCCESS;
72}
73
74template <typename T>
76public:
77 std::string dump() const {
78 return this->getCS()->dump();
79 }
80
81 template <typename T_Obj>
82 std::string dumpKeys() const {
83 std::stringstream out;
84 std::vector<std::string> keys_out;
85 this->getCS()->template keys<T_Obj>(keys_out,true,false);
86 for(const std::string &a_key : keys_out) {
87 out << " " << a_key;
88 }
89 return out.str();
90 }
91};
92
93
94StatusCode RIO_OnTrackErrorScalingCondAlg::execute(const EventContext& ctx) const {
96 if (!readHandle.isValid()) {
97 return StatusCode::FAILURE;
98 }
99 assert( *readHandle );
100 EventIDRange range;
101 if (!readHandle.range(range)) {
102 ATH_MSG_FATAL("Failed to retrieve validity range for " << readHandle.key());
103 return StatusCode::FAILURE;
104 }
105
106 std::vector<SG::WriteCondHandle<RIO_OnTrackErrorScaling> > write_handles(m_writeKey.makeHandles(ctx));
107 assert( write_handles.size() == m_kits.size() );
108 std::vector< std::unique_ptr<RIO_OnTrackErrorScaling> > error_scaling;
109 error_scaling.reserve( m_kits.size());
110
111 unsigned int total_params=0;
112 for (const RIO_OnTrackErrorScalingKit *a_kit: m_kits) {
113 assert( a_kit );
114 error_scaling.push_back( a_kit->create() );
115 total_params += a_kit->nParametres();
116 }
117 assert( write_handles.size() == error_scaling.size());
118
119 try {
120 // now populate output conditions data objects from attribut lists.
121 for (const std::pair<const unsigned int, coral::AttributeList>& channel : **readHandle ) {
122 const coral::AttributeList &alist = channel.second;
123 unsigned int att_i=0;
124 const std::string& attr_name=alist[att_i++].data<std::string>();
125 try {
126 std::pair<unsigned int, unsigned int> idx = m_attributeMap.at(attr_name);
127 if (idx.first != std::numeric_limits<unsigned int>::max()) {
128 assert( idx.first < error_scaling.size());
129 // cppcheck-suppress assertWithSideEffect
130 assert( idx.second < error_scaling[idx.first]->params().size());
131
132 const int nvals=alist[att_i++].data<int>();
133 std::vector<double> &params = error_scaling[idx.first]->params()[idx.second];
134 params.clear();
135 params.reserve(nvals);
136 assert( att_i == 2);
137 for (int i=0;i<nvals;++i, ++att_i){
138 assert( att_i < alist.size() );
139 // ATH_MSG_VERBOSE("Parameter " << i << " = " << alist[att_i].data<double>() );
140 params.push_back(alist[att_i].data<double>());
141 }
142 }
143 --total_params;
144 }
145 catch (std::out_of_range &err) {
146 ATH_MSG_FATAL("Unhandled attribute: " << attr_name);
147 return StatusCode::FAILURE;
148 }
149 catch (std::exception &err) {
150 ATH_MSG_FATAL("Unhandled attribute: " << attr_name << " what:" << err.what());
151 return StatusCode::FAILURE;
152 }
153 }
154 if (total_params!=0) {
155 ATH_MSG_ERROR("Not all parameters of the output conditions data are filled from attribute list. " << total_params << " parameters are not filled.");
156 }
157
158 for (unsigned int key_i=0; key_i<write_handles.size(); ++key_i) {
159 // assert( key_i < m_writeKey.size());
160 assert( key_i < error_scaling.size());
161 if (!error_scaling[key_i]->postProcess()) {
162 ATH_MSG_ERROR("Conditions data for " << write_handles[key_i].key() << " not valid.");
163 return StatusCode::FAILURE;
164 }
165 // CLID impl_clid=error_scaling[key_i]->clid();
166 if (write_handles[key_i].record(range, std::move(error_scaling[key_i])).isFailure()) {
167 ATH_MSG_FATAL("Could not record RIO_OnTrackErrorScaling " << write_handles[key_i].key()
168 << " with EventRange " << range
169 << " into Conditions Store");
170 return StatusCode::FAILURE;
171 }
172 }
173 }
174 catch (coral::Exception& e) {
175 ATH_MSG_ERROR("Problem with AttributeList decoding: " << e.what());
176 return StatusCode::FAILURE;
177 }
178 return StatusCode::SUCCESS;
179}
180
181
183 return StatusCode::SUCCESS;
184}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static const std::vector< std::string > types
Define macros for attributes used to control the static checker.
Base class for conditions algorithms.
void dumpKits(std::ostream &out) const
static KitManager< RIO_OnTrackErrorScalingKit > & instance()
Definition KitManager.h:50
const T_KitInterface & kit(const std::string &name) const
Definition KitManager.h:45
Gaudi::Property< std::vector< std::string > > m_attributIgnoreList
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
StatusCode execute(const EventContext &ctx) const override
std::map< std::string, std::pair< unsigned int, unsigned int > > m_attributeMap
void registerAttribute(const std::string &name, unsigned int type_idx, unsigned int param_idx)
SG::WriteCondHandleKeyArray< RIO_OnTrackErrorScaling > m_writeKey
StatusCode addErrorScaling(const std::string &type_name)
std::vector< const RIO_OnTrackErrorScalingKit * > m_kits
RIO_OnTrackErrorScalingCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::vector< std::string > > m_errorScalingType
virtual unsigned int nParametres() const =0
virtual const char *const * paramNames() const =0
StoreGateSvc * getCS() const
bool range(EventIDRange &r)
const std::string & key() const
std::string dump() const
dump objects in store.