ATLAS Offline Software
Loading...
Searching...
No Matches
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
37#include "BPhysMetadataBase.h"
41
42namespace DerivationFramework {
43
44 //--------------------------------------------------------------------------
46 const std::string& n,
47 const IInterface* p)
48 : base_class(t,n,p),
49 m_outputMetaStore("StoreGateSvc/MetaDataStore", n) {
50
51
52 // Declare derivation format name
53 declareProperty("DerivationName", m_derivationName = "_NOSUCHFORMAT_");
54
55 // Declare metadata folder name (should start with derivation name)
56 declareProperty("MetadataFolderName", m_mdFolderName = "_NONE_");
57
58 // Prefix would typically be the derivation format name
59 declareProperty("Prefix", m_prefix = "");
60
61 }
62 //--------------------------------------------------------------------------
64
65 ATH_MSG_DEBUG("BPhysMetaDataBase::initialize() -- begin");
66
67 // handle general prefix
68 if ( m_prefix == "" ) {
69 if ( m_derivationName == "_NOSUCHFORMAT_" ) {
70 m_prefix = name() +"_";
71 } else {
73 }
74 }
75
77
78 ATH_MSG_DEBUG("BPhysMetaDataBase::initialize() -- end");
79
80 return StatusCode::SUCCESS;
81 }
82 //--------------------------------------------------------------------------
84
85 ATH_MSG_DEBUG("BPhysMetaDataBase::finalize()");
86
87 // everything all right
88 return StatusCode::SUCCESS;
89 }
90 //--------------------------------------------------------------------------
91 StatusCode BPhysMetadataBase::addBranches(const EventContext&) const {
92
93 // nothing to do here
94 return StatusCode::SUCCESS;
95 }
96 //--------------------------------------------------------------------------
97#define SET_VALUES_IMP( TYPE, MAP ) \
98 for (auto const &ent : MAP) { \
99 SG::Accessor< TYPE > acc( m_prefix + ent.first ); \
100 acc( *fm ) = ent.second; \
101 }
102
104
105 ATH_MSG_DEBUG("BPhysMetaDataBase::saveMetaDataBPhys() -- begin");
106
107 std::string mdFolderKey = buildFolderName() + "_MetaData";
108 // protection
109 if ( m_outputMetaStore->contains< xAOD::FileMetaData >( mdFolderKey ) ) {
110 ATH_MSG_WARNING("saveMetaDataBPhys2: "
111 "xAOD::FileMetaData already in output: "
112 << mdFolderKey
113 << " -- BPhys metadata will NOT be saved!");
114 } else {
115 // create a FileMetaData object
116 auto fm = std::make_unique< xAOD::FileMetaData >();
117 auto fmAux = std::make_unique< xAOD::FileMetaDataAuxInfo >();
118 fm->setStore( fmAux.get() );
119
120 // fill it
121 SG::Accessor<std::string> DerivationNameAcc(m_prefix+"DerivationName");
122 DerivationNameAcc(*fm) = m_derivationName;
123
124 SG::Accessor<std::string> MetaDatafolderNameAcc(m_prefix+"MetaDataFolderName");
125 MetaDatafolderNameAcc(*fm) = m_mdFolderName;
126
127 // fill it with contents of maps
128 SET_VALUES_IMP( int , m_propInt );
129 SET_VALUES_IMP( long , m_propLong );
130 SET_VALUES_IMP( double , m_propDouble );
131 SET_VALUES_IMP( bool , m_propBool );
132 SET_VALUES_IMP( std::string , m_propString );
133 SET_VALUES_IMP( std::vector<int> , m_propVInt );
134 SET_VALUES_IMP( std::vector<long> , m_propVLong );
135 SET_VALUES_IMP( std::vector<double> , m_propVDouble );
136 SET_VALUES_IMP( std::vector<bool> , m_propVBool );
137 SET_VALUES_IMP( std::vector<std::string>, m_propVString );
138
139 // record it
140 ATH_CHECK( m_outputMetaStore->record( std::move(fm), mdFolderKey ) );
141 ATH_CHECK( m_outputMetaStore->record( std::move(fmAux),
142 mdFolderKey+"Aux." ) );
143 }
144
145 return StatusCode::SUCCESS;
146 }
147#undef SET_VALUES_IMP
148 //--------------------------------------------------------------------------
149 std::string BPhysMetadataBase::buildFolderName(const std::string& fname) const {
150
151 std::string result = fname;
152 if ( m_mdFolderName != "_NONE_" && m_mdFolderName != "" ) {
154 } else {
155 if ( m_derivationName != "_NOSUCHFORMAT_" && m_derivationName != "" ) {
157 } else {
158 // default to the tool's name
159 result += name();
160 }
161 }
162 return result;
163 }
164 //--------------------------------------------------------------------------
165 void BPhysMetadataBase::recordPropertyI(const std::string& name, int val) {
166 ATH_MSG_INFO("Calling recordProperty(int)");
167 declareProperty(name, m_propInt[name] = val);
168 }
169 //--------------------------------------------------------------------------
170 void BPhysMetadataBase::recordPropertyL(const std::string& name, long val) {
171 ATH_MSG_INFO("Calling recordProperty(long)");
172 declareProperty(name, m_propLong[name] = val);
173 }
174 //--------------------------------------------------------------------------
175 void BPhysMetadataBase::recordPropertyD(const std::string& name, double val) {
176 ATH_MSG_INFO("Calling recordProperty(double)");
177 declareProperty(name, m_propDouble[name] = val);
178 }
179 //--------------------------------------------------------------------------
180 void BPhysMetadataBase::recordPropertyB(const std::string& name, bool val) {
181 ATH_MSG_INFO("Calling recordProperty(bool)");
182 declareProperty(name, m_propBool[name] = val);
183 }
184 //--------------------------------------------------------------------------
185 void BPhysMetadataBase::recordPropertyS(const std::string& name, const std::string& val) {
186 ATH_MSG_INFO("Calling recordProperty(string)");
187 declareProperty(name, m_propString[name] = val);
188 }
189 //--------------------------------------------------------------------------
190 void BPhysMetadataBase::recordPropertyVI(const std::string& name,
191 const std::vector<int>& val) {
192 ATH_MSG_INFO("Calling recordProperty(vector<int>)");
193 declareProperty(name, m_propVInt[name] = val);
194 }
195 //--------------------------------------------------------------------------
196 void BPhysMetadataBase::recordPropertyVL(const std::string& name,
197 const std::vector<long>& val) {
198 ATH_MSG_INFO("Calling recordProperty(vector<long>)");
199 declareProperty(name, m_propVLong[name] = val);
200 }
201 //--------------------------------------------------------------------------
202 void BPhysMetadataBase::recordPropertyVD(const std::string& name,
203 const std::vector<double>& val) {
204 ATH_MSG_INFO("Calling recordProperty(vector<double>)");
205 declareProperty(name, m_propVDouble[name] = val);
206 }
207 //--------------------------------------------------------------------------
208 void BPhysMetadataBase::recordPropertyVB(const std::string& name,
209 const std::vector<bool>& val) {
210 ATH_MSG_INFO("Calling recordProperty(vector<bool>)");
211 declareProperty(name, m_propVBool[name] = val);
212 }
213 //--------------------------------------------------------------------------
214 void BPhysMetadataBase::recordPropertyVS(const std::string& name,
215 const std::vector<std::string>& val) {
216 ATH_MSG_INFO("Calling recordProperty(vector<string>)");
217 declareProperty(name, m_propVString[name] = val);
218 }
219 //--------------------------------------------------------------------------
220 std::string BPhysMetadataBase::vecToString(const std::vector<int>& v) const {
221 std::string str("[");
222 for (unsigned int i=0; i<v.size(); ++i) {
223 str += std::to_string(v[i]);
224 if ( i < v.size()-1 ) str += ",";
225 }
226 str += "]";
227 return str;
228 }
229 //--------------------------------------------------------------------------
230 std::string BPhysMetadataBase::vecToString(const std::vector<long>& v) const {
231 std::string str("[");
232 for (unsigned int i=0; i<v.size(); ++i) {
233 str += std::to_string(v[i]);
234 if ( i < v.size()-1 ) str += ",";
235 }
236 str += "]";
237 return str;
238 }
239 //--------------------------------------------------------------------------
240 std::string BPhysMetadataBase::vecToString(const std::vector<double>& v) const {
241 std::string str("[");
242 for (unsigned int i=0; i<v.size(); ++i) {
243 str += std::to_string(v[i]);
244 if ( i < v.size()-1 ) str += ",";
245 }
246 str += "]";
247 return str;
248 }
249 //--------------------------------------------------------------------------
250 std::string BPhysMetadataBase::vecToString(const std::vector<bool>& v) const {
251 std::string str("[");
252 for (unsigned int i=0; i<v.size(); ++i) {
253 str += std::to_string(v[i]);
254 if ( i < v.size()-1 ) str += ",";
255 }
256 str += "]";
257 return str;
258 }
259 //--------------------------------------------------------------------------
260 std::string BPhysMetadataBase::vecToString(const std::vector<std::string>& v) const {
261 std::string str("[");
262 for (unsigned int i=0; i<v.size(); ++i) {
263 str += "'";
264 str += v[i];
265 str += "'";
266 if ( i < v.size()-1 ) str += ",";
267 }
268 str += "]";
269 return str;
270 }
271 //--------------------------------------------------------------------------
272}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define SET_VALUES_IMP(TYPE, MAP)
Helper class to provide type-safe access to aux data.
#define CHECK(...)
Evaluate an expression and check for errors.
std::map< std::string, std::vector< int > > m_propVInt
ServiceHandle< StoreGateSvc > m_outputMetaStore
Object accessing the output metadata store.
std::map< std::string, double > m_propDouble
virtual void recordPropertyB(const std::string &name, bool val)
std::map< std::string, long > m_propLong
virtual void recordPropertyD(const std::string &name, double val)
virtual void recordPropertyVD(const std::string &name, const std::vector< double > &val)
std::map< std::string, std::vector< long > > m_propVLong
virtual std::string buildFolderName(const std::string &fname="") const
virtual void recordPropertyS(const std::string &name, const std::string &val)
virtual std::string vecToString(const std::vector< int > &v) const
std::map< std::string, std::string > m_propString
virtual void recordPropertyVI(const std::string &name, const std::vector< int > &val)
std::map< std::string, bool > m_propBool
virtual StatusCode addBranches(const EventContext &ctx) const
std::map< std::string, std::vector< std::string > > m_propVString
BPhysMetadataBase(const std::string &t, const std::string &n, const IInterface *p)
virtual void recordPropertyL(const std::string &name, long val)
std::map< std::string, std::vector< double > > m_propVDouble
virtual void recordPropertyVB(const std::string &name, const std::vector< bool > &val)
std::map< std::string, int > m_propInt
virtual void recordPropertyVS(const std::string &name, const std::vector< std::string > &val)
std::map< std::string, std::vector< bool > > m_propVBool
virtual void recordPropertyVL(const std::string &name, const std::vector< long > &val)
virtual void recordPropertyI(const std::string &name, int val)
virtual StatusCode saveMetaDataBPhys() const
Helper class to provide type-safe access to aux data.
THE reconstruction tool.
FileMetaData_v1 FileMetaData
Declare the latest version of the class.