ATLAS Offline Software
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 
12 RIO_OnTrackErrorScalingCondAlg::RIO_OnTrackErrorScalingCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
13  : ::AthAlgorithm(name, pSvcLocator)
14 {
15 }
16 
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 ) {
34  }
35 
36  return StatusCode::SUCCESS;
37 }
38 
39 
40 void 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 
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 
74 template <typename T>
76 public:
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 
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());
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);
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 }
RIO_OnTrackErrorScalingKit::nParametres
virtual unsigned int nParametres() const =0
RIO_OnTrackErrorScalingCondAlg::registerAttribute
void registerAttribute(const std::string &name, unsigned int type_idx, unsigned int param_idx)
Definition: RIO_OnTrackErrorScalingCondAlg.cxx:40
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
RIO_OnTrackErrorScalingCondAlg::RIO_OnTrackErrorScalingCondAlg
RIO_OnTrackErrorScalingCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: RIO_OnTrackErrorScalingCondAlg.cxx:12
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
max
#define max(a, b)
Definition: cfImp.cxx:41
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
RIO_OnTrackErrorScalingCondAlg::m_errorScalingType
Gaudi::Property< std::vector< std::string > > m_errorScalingType
Definition: RIO_OnTrackErrorScalingCondAlg.h:37
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
RIO_OnTrackErrorScaling.h
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition: ReadCondHandle.h:224
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
ReweightUtils.message
message
Definition: ReweightUtils.py:15
collListGuids.attr_name
attr_name
Definition: collListGuids.py:72
RIO_OnTrackErrorScalingCondAlg::m_attributIgnoreList
Gaudi::Property< std::vector< std::string > > m_attributIgnoreList
Definition: RIO_OnTrackErrorScalingCondAlg.h:44
RIO_OnTrackErrorScalingKit::paramNames
virtual const char *const * paramNames() const =0
StoreGateSvc::dump
std::string dump() const
dump objects in store.
Definition: StoreGateSvc.cxx:376
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
lumiFormat.i
int i
Definition: lumiFormat.py:85
RIO_OnTrackErrorScalingCondAlg.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
KitManager::instance
static KitManager< T_KitInterface > & instance()
Definition: KitManager.h:50
calibdata.exception
exception
Definition: calibdata.py:496
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
RIO_OnTrackErrorScalingCondAlg::m_readKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
Definition: RIO_OnTrackErrorScalingCondAlg.h:34
RIO_OnTrackErrorScalingCondAlg::m_attributeMap
std::map< std::string, std::pair< unsigned int, unsigned int > > m_attributeMap
Definition: RIO_OnTrackErrorScalingCondAlg.h:53
RIO_OnTrackErrorScalingCondAlg::m_writeKey
SG::WriteCondHandleKeyArray< RIO_OnTrackErrorScaling > m_writeKey
Definition: RIO_OnTrackErrorScalingCondAlg.h:47
RIO_OnTrackErrorScalingKit.h
AthAlgorithm
Definition: AthAlgorithm.h:47
RIO_OnTrackErrorScalingCondAlg::addErrorScaling
StatusCode addErrorScaling(const std::string &type_name)
Definition: RIO_OnTrackErrorScalingCondAlg.cxx:48
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
RIO_OnTrackErrorScalingCondAlg::execute
StatusCode execute() override
Definition: RIO_OnTrackErrorScalingCondAlg.cxx:94
CSAccessCondReadHandleKey::dump
std::string dump() const
Definition: RIO_OnTrackErrorScalingCondAlg.cxx:77
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
RIO_OnTrackErrorScalingKit
Definition: RIO_OnTrackErrorScalingKit.h:12
SG::ReadCondHandleKey
Definition: ReadCondHandleKey.h:20
collListGuids.alist
alist
Definition: collListGuids.py:68
CSAccessCondReadHandleKey::dumpKeys
std::string dumpKeys() const
Definition: RIO_OnTrackErrorScalingCondAlg.cxx:82
PixelRIO_OnTrackErrorScaling.h
RIO_OnTrackErrorScalingCondAlg::finalize
StatusCode finalize() override
Definition: RIO_OnTrackErrorScalingCondAlg.cxx:182
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
SG::CondHandleKey::getCS
StoreGateSvc * getCS() const
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
CSAccessCondReadHandleKey
Definition: RIO_OnTrackErrorScalingCondAlg.cxx:75
SG::ReadCondHandle::key
const std::string & key() const
Definition: ReadCondHandle.h:59
checker_macros.h
Define macros for attributes used to control the static checker.
RIO_OnTrackErrorScalingCondAlg::m_kits
std::vector< const RIO_OnTrackErrorScalingKit * > m_kits
Definition: RIO_OnTrackErrorScalingCondAlg.h:52
RIO_OnTrackErrorScalingCondAlg::initialize
StatusCode initialize() override
Definition: RIO_OnTrackErrorScalingCondAlg.cxx:17
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37