ATLAS Offline Software
RIO_OnTrackErrorScalingDbOverrideCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
11  : ::AthAlgorithm(name, pSvcLocator)
12  , m_condSvc{"CondSvc", name}
13 {
14 }
15 
17  ATH_CHECK(m_condSvc.retrieve());
18  if (m_writeKey.key().empty()) {
19  ATH_MSG_FATAL("No conditions data write key specified.");
20  }
23  unsigned int n_parameters_total=0;
24  unsigned int n_parameter_sets = m_errorScalingDataKit->nParametres();
25  if (n_parameter_sets>0) {
26  if (!m_nParameterPerSet.empty()) {
27  if (m_nParameterPerSet.size() != n_parameter_sets) {
28  ATH_MSG_FATAL("PrametersPerSet must either be empty or match the number of parameters of the error scaling class " << m_errorScalingTypeName);
29  return StatusCode::FAILURE;
30  }
31 
32  for (unsigned int n_parameters : m_nParameterPerSet) {
33  n_parameters_total += n_parameters;
34  }
35 
37  }
38  else {
39  unsigned int n_parameters_per_set=m_errorScalingParameters.size()/n_parameter_sets;
40  n_parameters_total = n_parameter_sets * n_parameters_per_set;
41  m_useNParametersPerSet.clear();
42  m_useNParametersPerSet.reserve(n_parameter_sets);
43  for (unsigned int param_set_i=0; param_set_i<n_parameter_sets; ++param_set_i ) {
44  m_useNParametersPerSet.push_back( n_parameters_per_set);
45  }
46  ATH_MSG_VERBOSE("init n_parameters_total=" << n_parameters_total << " =?= " << m_errorScalingParameters.size()
47  << " n_parameters_per_set=" << n_parameters_per_set );
48  }
49  if (n_parameters_total != m_errorScalingParameters.size()) {
50  ATH_MSG_FATAL("Number of parameters in ErorScalingParameters does not match expectation. Estimated " << n_parameters_total
51  << " parameters in total for the " << n_parameter_sets << " parameter sets of " << m_errorScalingTypeName
52  << " but got " << m_errorScalingParameters.size());
53  return StatusCode::FAILURE;
54  }
55  }
56  if(msgLvl(MSG::VERBOSE)) {
57  for(unsigned int param_i=0; param_i<m_errorScalingDataKit->nParametres(); ++param_i) {
58  ATH_MSG_VERBOSE("No error scaling parameters for " << m_writeKey.key() << " " << m_errorScalingDataKit->paramNames()[param_i]
59  << " n-params="
60  << m_useNParametersPerSet[param_i]);
61  }
62  }
63  if (n_parameters_total==0 && !m_errorScalingParameters.empty()) {
64  ATH_MSG_FATAL("ErorScalingParameters expected to be empty for " << m_errorScalingTypeName) ;
65  return StatusCode::FAILURE;
66  }
67 
68  return StatusCode::SUCCESS;
69 }
70 
71 namespace {
72  EventIDBase timestamp (int t)
73  {
74  return {EventIDBase::UNDEFNUM, // run
75  EventIDBase::UNDEFEVT, // event
76  static_cast<EventIDBase::number_type>(t)};
77  }
78 
79  EventIDBase infiniteIOVEend() {
80  return timestamp(std::numeric_limits<int>::max() - 1);
81  }
82 
83  template <typename T>
84  std::ostream &operator<<(std::ostream &out, const std::vector<T> &a) {
85  for (const T &elm : a) {
86  out << " " << elm;
87  }
88  return out;
89  }
90 }
91 
92 
95  if (!write_handle.isValid()) {
96  EventIDRange range(timestamp(0),infiniteIOVEend());
97  std::unique_ptr<RIO_OnTrackErrorScaling> error_scaling( m_errorScalingDataKit->create() );
98  std::vector<float>::const_iterator param_iter = m_errorScalingParameters.begin();
99  unsigned int set_i=0;
100  for (unsigned int n_params : m_useNParametersPerSet ) {
101  // cppcheck-suppress assertWithSideEffect
102  assert( set_i < error_scaling->params().size() );
103  error_scaling->params()[set_i].clear();
104  error_scaling->params()[set_i].reserve(n_params);
105  for(unsigned int param_i=0; param_i<n_params; ++param_i, ++param_iter) {
106  assert( param_iter != m_errorScalingParameters.end() );
107  error_scaling->params()[set_i].push_back( *param_iter );
108  }
109  ++set_i;
110  }
111 
112  // dump error scaling parameters
113  if(msgLvl(MSG::VERBOSE)) {
114  for(unsigned int param_i=0; param_i<m_errorScalingDataKit->nParametres(); ++param_i) {
115  if (param_i>= error_scaling->params().size()) {
116  ATH_MSG_FATAL("No error scaling parameters for " << write_handle.key() << " " << m_errorScalingDataKit->paramNames()[param_i] << ".");
117  return StatusCode::FAILURE;
118  }
119 
120  ATH_MSG_VERBOSE("Parameters for " << write_handle.key() << " " << m_errorScalingDataKit->paramNames()[param_i] << error_scaling->params()[param_i] );
121 
122  }
123  }
124 
125  if (!error_scaling->postProcess()) {
126  ATH_MSG_ERROR("Conditions data for " << write_handle.key() << " not valid.");
127  return StatusCode::FAILURE;
128  }
129  if (write_handle.record(range, std::move(error_scaling)).isFailure()) {
130  ATH_MSG_FATAL("Could not record RIO_OnTrackErrorScaling " << write_handle.key()
131  << " with EventRange " << range
132  << " into Conditions Store");
133  return StatusCode::FAILURE;
134  }
135  }
136  return StatusCode::SUCCESS;
137 }
138 
139 
141  return StatusCode::SUCCESS;
142 }
RIO_OnTrackErrorScalingKit::nParametres
virtual unsigned int nParametres() const =0
RIO_OnTrackErrorScalingDbOverrideCondAlg::m_errorScalingTypeName
Gaudi::Property< std::string > m_errorScalingTypeName
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.h:38
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
max
#define max(a, b)
Definition: cfImp.cxx:41
RIO_OnTrackErrorScaling::postProcess
virtual bool postProcess()
Definition: RIO_OnTrackErrorScaling.h:32
RIO_OnTrackErrorScalingDbOverrideCondAlg::m_errorScalingDataKit
const RIO_OnTrackErrorScalingKit * m_errorScalingDataKit
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.h:44
RIO_OnTrackErrorScalingDbOverrideCondAlg::m_nParameterPerSet
Gaudi::Property< std::vector< unsigned int > > m_nParameterPerSet
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.h:32
RIO_OnTrackErrorScalingDbOverrideCondAlg::initialize
StatusCode initialize() override
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.cxx:16
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
AtlasMcWeight::number_type
unsigned int number_type
Definition: AtlasMcWeight.h:20
RIO_OnTrackErrorScaling.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
RIO_OnTrackErrorScalingKit::create
virtual std::unique_ptr< RIO_OnTrackErrorScaling > create() const =0
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:157
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
RIO_OnTrackErrorScalingDbOverrideCondAlg::m_useNParametersPerSet
std::vector< unsigned int > m_useNParametersPerSet
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.h:45
RIO_OnTrackErrorScalingKit::paramNames
virtual const char *const * paramNames() const =0
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
RIO_OnTrackErrorScalingDbOverrideCondAlg::m_writeKey
SG::WriteCondHandleKey< RIO_OnTrackErrorScaling > m_writeKey
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.h:41
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
RIO_OnTrackErrorScalingDbOverrideCondAlg::m_condSvc
ServiceHandle< ICondSvc > m_condSvc
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.h:43
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
RIO_OnTrackErrorScalingKit.h
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:40
operator<<
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
Definition: TestGaudiProperty.cxx:69
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
a
TList * a
Definition: liststreamerinfos.cxx:10
RIO_OnTrackErrorScalingDbOverrideCondAlg::execute
StatusCode execute() override
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.cxx:93
RIO_OnTrackErrorScalingDbOverrideCondAlg::m_errorScalingParameters
Gaudi::Property< std::vector< float > > m_errorScalingParameters
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.h:35
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
RIO_OnTrackErrorScalingDbOverrideCondAlg::RIO_OnTrackErrorScalingDbOverrideCondAlg
RIO_OnTrackErrorScalingDbOverrideCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.cxx:10
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
RIO_OnTrackErrorScalingDbOverrideCondAlg::finalize
StatusCode finalize() override
Definition: RIO_OnTrackErrorScalingDbOverrideCondAlg.cxx:140
RIO_OnTrackErrorScaling::params
std::vector< std::vector< double > > & params()
Definition: RIO_OnTrackErrorScaling.h:29
checker_macros.h
Define macros for attributes used to control the static checker.
RIO_OnTrackErrorScalingDbOverrideCondAlg.h
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35