ATLAS Offline Software
BPhysMetadataBase.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 //============================================================================
6 // BPhysMetadataBase.cxx
7 //============================================================================
8 //
9 // Author : Wolfgang Walkowiak <Wolfgang.Walkowiak@cern.ch.>
10 // Changes:
11 // - w.w., 2017-01-22: Added use of BPhysMetaDataTool.
12 // - w.w., 2017-05-27: Removed use of BPhysMetaDataTool and
13 // IOVDbMetaDataTool.
14 // - w.w., 2019-12-05: Added long and vector<long> types
15 //
16 // Store JO metadata in the output file.
17 //
18 // It uses a FileMetaData object to store job option information
19 // as metadata in a specific branch whose name needs to prefixed by
20 // the derivation format name.
21 //
22 // This is a base class. Inherit from it to add the job options you want
23 // to store. For a usage example, see
24 // Bmumu_metadata.h / Bmumu_metadata.cxx
25 // and
26 // BPHY8.py .
27 //
28 // Job options provided by the base class:
29 // - DerivationName -- assign the name of the derivation format
30 // - MetadataFolderName -- assign the name of the metadata folder,
31 // should start with the derivation format name,
32 // defaults to DerivationName if not set.
33 //
34 //============================================================================
35 //
36 
40 #include "AthContainers/Accessor.h"
41 
42 namespace DerivationFramework {
43 
44  //--------------------------------------------------------------------------
46  const std::string& n,
47  const IInterface* p)
48  : AthAlgTool(t,n,p),
49  m_outputMetaStore("StoreGateSvc/MetaDataStore", n) {
50 
51  declareInterface<DerivationFramework::IAugmentationTool>(this);
52 
53  // Declare derivation format name
54  declareProperty("DerivationName", m_derivationName = "_NOSUCHFORMAT_");
55 
56  // Declare metadata folder name (should start with derivation name)
57  declareProperty("MetadataFolderName", m_mdFolderName = "_NONE_");
58 
59  // Prefix would typically be the derivation format name
60  declareProperty("Prefix", m_prefix = "");
61 
62  }
63  //--------------------------------------------------------------------------
65 
66  ATH_MSG_DEBUG("BPhysMetaDataBase::initialize() -- begin");
67 
68  // handle general prefix
69  if ( m_prefix == "" ) {
70  if ( m_derivationName == "_NOSUCHFORMAT_" ) {
71  m_prefix = name() +"_";
72  } else {
73  m_prefix = m_derivationName + "_";
74  }
75  }
76 
78 
79  ATH_MSG_DEBUG("BPhysMetaDataBase::initialize() -- end");
80 
81  return StatusCode::SUCCESS;
82  }
83  //--------------------------------------------------------------------------
85 
86  ATH_MSG_DEBUG("BPhysMetaDataBase::finalize()");
87 
88  // everything all right
89  return StatusCode::SUCCESS;
90  }
91  //--------------------------------------------------------------------------
93 
94  // nothing to do here
95  return StatusCode::SUCCESS;
96  }
97  //--------------------------------------------------------------------------
98 #define SET_VALUES_IMP( TYPE, MAP ) \
99  for (auto const &ent : MAP) { \
100  SG::Accessor< TYPE > acc( m_prefix + ent.first ); \
101  acc( *fm ) = ent.second; \
102  }
103 
105 
106  ATH_MSG_DEBUG("BPhysMetaDataBase::saveMetaDataBPhys() -- begin");
107 
108  std::string mdFolderKey = buildFolderName() + "_MetaData";
109  // protection
110  if ( m_outputMetaStore->contains< xAOD::FileMetaData >( mdFolderKey ) ) {
111  ATH_MSG_WARNING("saveMetaDataBPhys2: "
112  "xAOD::FileMetaData already in output: "
113  << mdFolderKey
114  << " -- BPhys metadata will NOT be saved!");
115  } else {
116  // create a FileMetaData object
117  auto fm = std::make_unique< xAOD::FileMetaData >();
118  auto fmAux = std::make_unique< xAOD::FileMetaDataAuxInfo >();
119  fm->setStore( fmAux.get() );
120 
121  // fill it
122  SG::Accessor<std::string> DerivationNameAcc(m_prefix+"DerivationName");
123  DerivationNameAcc(*fm) = m_derivationName;
124 
125  SG::Accessor<std::string> MetaDatafolderNameAcc(m_prefix+"MetaDataFolderName");
126  MetaDatafolderNameAcc(*fm) = m_mdFolderName;
127 
128  // fill it with contents of maps
129  SET_VALUES_IMP( int , m_propInt );
130  SET_VALUES_IMP( long , m_propLong );
131  SET_VALUES_IMP( double , m_propDouble );
132  SET_VALUES_IMP( bool , m_propBool );
133  SET_VALUES_IMP( std::string , m_propString );
134  SET_VALUES_IMP( std::vector<int> , m_propVInt );
135  SET_VALUES_IMP( std::vector<long> , m_propVLong );
136  SET_VALUES_IMP( std::vector<double> , m_propVDouble );
137  SET_VALUES_IMP( std::vector<bool> , m_propVBool );
138  SET_VALUES_IMP( std::vector<std::string>, m_propVString );
139 
140  // record it
141  ATH_CHECK( m_outputMetaStore->record( std::move(fm), mdFolderKey ) );
142  ATH_CHECK( m_outputMetaStore->record( std::move(fmAux),
143  mdFolderKey+"Aux." ) );
144  }
145 
146  return StatusCode::SUCCESS;
147  }
148 #undef SET_VALUES_IMP
149  //--------------------------------------------------------------------------
150  std::string BPhysMetadataBase::buildFolderName(const std::string& fname) const {
151 
152  std::string result = fname;
153  if ( m_mdFolderName != "_NONE_" && m_mdFolderName != "" ) {
155  } else {
156  if ( m_derivationName != "_NOSUCHFORMAT_" && m_derivationName != "" ) {
158  } else {
159  // default to the tool's name
160  result += name();
161  }
162  }
163  return result;
164  }
165  //--------------------------------------------------------------------------
166  void BPhysMetadataBase::recordPropertyI(const std::string& name, int val) {
167  ATH_MSG_INFO("Calling recordProperty(int)");
169  }
170  //--------------------------------------------------------------------------
171  void BPhysMetadataBase::recordPropertyL(const std::string& name, long val) {
172  ATH_MSG_INFO("Calling recordProperty(long)");
174  }
175  //--------------------------------------------------------------------------
176  void BPhysMetadataBase::recordPropertyD(const std::string& name, double val) {
177  ATH_MSG_INFO("Calling recordProperty(double)");
179  }
180  //--------------------------------------------------------------------------
181  void BPhysMetadataBase::recordPropertyB(const std::string& name, bool val) {
182  ATH_MSG_INFO("Calling recordProperty(bool)");
184  }
185  //--------------------------------------------------------------------------
186  void BPhysMetadataBase::recordPropertyS(const std::string& name, const std::string& val) {
187  ATH_MSG_INFO("Calling recordProperty(string)");
189  }
190  //--------------------------------------------------------------------------
191  void BPhysMetadataBase::recordPropertyVI(const std::string& name,
192  const std::vector<int>& val) {
193  ATH_MSG_INFO("Calling recordProperty(vector<int>)");
195  }
196  //--------------------------------------------------------------------------
197  void BPhysMetadataBase::recordPropertyVL(const std::string& name,
198  const std::vector<long>& val) {
199  ATH_MSG_INFO("Calling recordProperty(vector<long>)");
201  }
202  //--------------------------------------------------------------------------
203  void BPhysMetadataBase::recordPropertyVD(const std::string& name,
204  const std::vector<double>& val) {
205  ATH_MSG_INFO("Calling recordProperty(vector<double>)");
207  }
208  //--------------------------------------------------------------------------
209  void BPhysMetadataBase::recordPropertyVB(const std::string& name,
210  const std::vector<bool>& val) {
211  ATH_MSG_INFO("Calling recordProperty(vector<bool>)");
213  }
214  //--------------------------------------------------------------------------
215  void BPhysMetadataBase::recordPropertyVS(const std::string& name,
216  const std::vector<std::string>& val) {
217  ATH_MSG_INFO("Calling recordProperty(vector<string>)");
219  }
220  //--------------------------------------------------------------------------
221  std::string BPhysMetadataBase::vecToString(const std::vector<int>& v) const {
222  std::string str("[");
223  for (unsigned int i=0; i<v.size(); ++i) {
224  str += std::to_string(v[i]);
225  if ( i < v.size()-1 ) str += ",";
226  }
227  str += "]";
228  return str;
229  }
230  //--------------------------------------------------------------------------
231  std::string BPhysMetadataBase::vecToString(const std::vector<long>& v) const {
232  std::string str("[");
233  for (unsigned int i=0; i<v.size(); ++i) {
234  str += std::to_string(v[i]);
235  if ( i < v.size()-1 ) str += ",";
236  }
237  str += "]";
238  return str;
239  }
240  //--------------------------------------------------------------------------
241  std::string BPhysMetadataBase::vecToString(const std::vector<double>& v) const {
242  std::string str("[");
243  for (unsigned int i=0; i<v.size(); ++i) {
244  str += std::to_string(v[i]);
245  if ( i < v.size()-1 ) str += ",";
246  }
247  str += "]";
248  return str;
249  }
250  //--------------------------------------------------------------------------
251  std::string BPhysMetadataBase::vecToString(const std::vector<bool>& v) const {
252  std::string str("[");
253  for (unsigned int i=0; i<v.size(); ++i) {
254  str += std::to_string(v[i]);
255  if ( i < v.size()-1 ) str += ",";
256  }
257  str += "]";
258  return str;
259  }
260  //--------------------------------------------------------------------------
261  std::string BPhysMetadataBase::vecToString(const std::vector<std::string>& v) const {
262  std::string str("[");
263  for (unsigned int i=0; i<v.size(); ++i) {
264  str += "'";
265  str += v[i];
266  str += "'";
267  if ( i < v.size()-1 ) str += ",";
268  }
269  str += "]";
270  return str;
271  }
272  //--------------------------------------------------------------------------
273 }
DerivationFramework::BPhysMetadataBase::recordPropertyD
virtual void recordPropertyD(const std::string &name, double val)
Definition: BPhysMetadataBase.cxx:176
DerivationFramework::BPhysMetadataBase::recordPropertyB
virtual void recordPropertyB(const std::string &name, bool val)
Definition: BPhysMetadataBase.cxx:181
DerivationFramework::BPhysMetadataBase::m_prefix
std::string m_prefix
Definition: BPhysMetadataBase.h:84
get_generator_info.result
result
Definition: get_generator_info.py:21
DerivationFramework::BPhysMetadataBase::saveMetaDataBPhys
virtual StatusCode saveMetaDataBPhys() const
Definition: BPhysMetadataBase.cxx:104
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
DerivationFramework::BPhysMetadataBase::recordPropertyVD
virtual void recordPropertyVD(const std::string &name, const std::vector< double > &val)
Definition: BPhysMetadataBase.cxx:203
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::BPhysMetadataBase::BPhysMetadataBase
BPhysMetadataBase(const std::string &t, const std::string &n, const IInterface *p)
Definition: BPhysMetadataBase.cxx:45
FileMetaDataAuxInfo.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::BPhysMetadataBase::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: BPhysMetadataBase.cxx:92
SET_VALUES_IMP
#define SET_VALUES_IMP(TYPE, MAP)
Definition: BPhysMetadataBase.cxx:98
DerivationFramework::BPhysMetadataBase::initialize
virtual StatusCode initialize()
Definition: BPhysMetadataBase.cxx:64
DerivationFramework::BPhysMetadataBase::m_propVInt
std::map< std::string, std::vector< int > > m_propVInt
Definition: BPhysMetadataBase.h:92
DerivationFramework::BPhysMetadataBase::m_propBool
std::map< std::string, bool > m_propBool
Definition: BPhysMetadataBase.h:90
DerivationFramework::BPhysMetadataBase::vecToString
virtual std::string vecToString(const std::vector< int > &v) const
Definition: BPhysMetadataBase.cxx:221
DerivationFramework::BPhysMetadataBase::buildFolderName
virtual std::string buildFolderName(const std::string &fname="") const
Definition: BPhysMetadataBase.cxx:150
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
DerivationFramework::BPhysMetadataBase::recordPropertyL
virtual void recordPropertyL(const std::string &name, long val)
Definition: BPhysMetadataBase.cxx:171
beamspotman.n
n
Definition: beamspotman.py:731
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::BPhysMetadataBase::recordPropertyVL
virtual void recordPropertyVL(const std::string &name, const std::vector< long > &val)
Definition: BPhysMetadataBase.cxx:197
xAOD::FileMetaData_v1
Class holding file-level metadata about an xAOD file.
Definition: FileMetaData_v1.h:34
DerivationFramework::BPhysMetadataBase::finalize
virtual StatusCode finalize()
Definition: BPhysMetadataBase.cxx:84
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
Accessor.h
Helper class to provide type-safe access to aux data.
DerivationFramework::BPhysMetadataBase::m_outputMetaStore
ServiceHandle< StoreGateSvc > m_outputMetaStore
Object accessing the output metadata store.
Definition: BPhysMetadataBase.h:79
DerivationFramework::BPhysMetadataBase::m_derivationName
std::string m_derivationName
Definition: BPhysMetadataBase.h:82
DerivationFramework::BPhysMetadataBase::m_propInt
std::map< std::string, int > m_propInt
Definition: BPhysMetadataBase.h:87
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
python.PyAthena.v
v
Definition: PyAthena.py:154
DerivationFramework::BPhysMetadataBase::recordPropertyVB
virtual void recordPropertyVB(const std::string &name, const std::vector< bool > &val)
Definition: BPhysMetadataBase.cxx:209
DerivationFramework::BPhysMetadataBase::m_propVBool
std::map< std::string, std::vector< bool > > m_propVBool
Definition: BPhysMetadataBase.h:95
FileMetaData.h
DerivationFramework::BPhysMetadataBase::m_propVLong
std::map< std::string, std::vector< long > > m_propVLong
Definition: BPhysMetadataBase.h:93
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
DerivationFramework::BPhysMetadataBase::m_propString
std::map< std::string, std::string > m_propString
Definition: BPhysMetadataBase.h:91
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
BPhysMetadataBase.h
DerivationFramework::BPhysMetadataBase::recordPropertyS
virtual void recordPropertyS(const std::string &name, const std::string &val)
Definition: BPhysMetadataBase.cxx:186
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DerivationFramework::BPhysMetadataBase::recordPropertyVI
virtual void recordPropertyVI(const std::string &name, const std::vector< int > &val)
Definition: BPhysMetadataBase.cxx:191
DerivationFramework::BPhysMetadataBase::m_propVString
std::map< std::string, std::vector< std::string > > m_propVString
Definition: BPhysMetadataBase.h:96
DerivationFramework::BPhysMetadataBase::m_propDouble
std::map< std::string, double > m_propDouble
Definition: BPhysMetadataBase.h:89
str
Definition: BTagTrackIpAccessor.cxx:11
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::BPhysMetadataBase::m_mdFolderName
std::string m_mdFolderName
Definition: BPhysMetadataBase.h:83
DerivationFramework::BPhysMetadataBase::recordPropertyVS
virtual void recordPropertyVS(const std::string &name, const std::vector< std::string > &val)
Definition: BPhysMetadataBase.cxx:215
DerivationFramework::BPhysMetadataBase::m_propVDouble
std::map< std::string, std::vector< double > > m_propVDouble
Definition: BPhysMetadataBase.h:94
DerivationFramework::BPhysMetadataBase::recordPropertyI
virtual void recordPropertyI(const std::string &name, int val)
Definition: BPhysMetadataBase.cxx:166
DerivationFramework::BPhysMetadataBase::m_propLong
std::map< std::string, long > m_propLong
Definition: BPhysMetadataBase.h:88