ATLAS Offline Software
DecoratorUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef _DecoratorUtils_H_
5 #define _DecoratorUtils_H_
9 
10 #include <string>
11 #include <vector>
12 #include <stdexcept>
13 #include <sstream>
14 
15 namespace DerivationFramework {
16  // @TODO copied from InnerDetector/InDetValidation/InDetPhysValMonitoring/src/safeDecorator.h, maybe move to a central place ?
17 
18  // convenience method to create several decorators
19  template<class T_Parent, class T_Cont>
20  void createDecoratorKeys(T_Parent &parent,
21  const SG::ReadHandleKey<T_Cont> &container_key,
22  const std::string &prefix,
23  const std::vector<std::string> &decor_names,
24  std::vector<SG::WriteDecorHandleKey<T_Cont> > &decor_out) {
25  decor_out.clear();
26  decor_out.reserve(decor_names.size());
27  for (const std::string &a_decor_name : decor_names) {
28  assert( !a_decor_name.empty() );
29  decor_out.push_back(SG::WriteDecorHandleKey<T_Cont>(container_key.key()+"."+prefix+a_decor_name) );
30  }
31 
32  for (SG::WriteDecorHandleKey<T_Cont> &a_decor_handle_key : decor_out) {
33  // need to declare handles, otherwise the scheduler would not pick up the data dependencies
34  // introduced by the decorations
35  parent.declare(a_decor_handle_key);
36  a_decor_handle_key.setOwner(&parent);
37  if (a_decor_handle_key.initialize().isFailure()) {
38  std::stringstream msg;
39  msg << "Failed to initialize " << a_decor_handle_key.key() << " after initializing: ";
40  for (SG::WriteDecorHandleKey<T_Cont> &b_decor_handle_key : decor_out) {
41  if (&b_decor_handle_key == &a_decor_handle_key) break;
42  msg << " " << b_decor_handle_key.key();
43  }
44  throw std::runtime_error(msg.str());
45  }
46  }
47  }
48 
49  template <class T_Cont, class T>
50  std::vector<SG::WriteDecorHandle<T_Cont,T> >
52  const EventContext &ctx) {
53  std::vector<SG::WriteDecorHandle<T_Cont,T> > out;
54  out.reserve(keys.size());
55  for( const SG::WriteDecorHandleKey<T_Cont> &a_key : keys) {
56  out.push_back(SG::WriteDecorHandle<T_Cont,T>(a_key,ctx));
57  if (not out.back().isValid()) {
58  std::stringstream msg;
59  msg << "Failed to create decorator handdle " << a_key.key();
60  throw std::runtime_error( msg.str() );
61  }
62  }
63  return out;
64  }
65 
66 
67 }
68 #endif
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition: StoreGate/StoreGate/WriteDecorHandleKey.h:89
DerivationFramework::createDecoratorKeys
void createDecoratorKeys(T_Parent &parent, const SG::ReadHandleKey< T_Cont > &container_key, const std::string &prefix, const std::vector< std::string > &decor_names, std::vector< SG::WriteDecorHandleKey< T_Cont > > &decor_out)
Definition: DecoratorUtils.h:20
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::ReadHandleKey< T_Cont >
WriteDecorHandleKey.h
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
test_pyathena.parent
parent
Definition: test_pyathena.py:15
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::createDecorators
std::vector< SG::WriteDecorHandle< T_Cont, T > > createDecorators(const std::vector< SG::WriteDecorHandleKey< T_Cont > > &keys, const EventContext &ctx)
Definition: DecoratorUtils.h:51
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7