ATLAS Offline Software
Loading...
Searching...
No Matches
FileMetaData_v1.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// System include(s):
6#include <cmath>
7#include <cstdlib>
8
9// Core include(s):
13
14// Local include(s):
17#include <iostream>
18
19namespace xAOD {
20
23
24
25 bool FileMetaData_v1::compareWith( const FileMetaData_v1& rhs, const std::set<std::string>& ignore ) const
26 {
27 // Get the variable types from both objects:
28 SG::auxid_set_t auxids1 = this->getAuxIDs();
29 SG::auxid_set_t auxids2 = rhs.getAuxIDs();
31 for( const std::string& var : ignore ) {
32 SG::auxid_t varid = reg.findAuxID(var);
33 auxids1.erase(varid);
34 auxids2.erase(varid);
35 }
36
37 // They need to be the same. If the two objects have different variables,
38 // that's bad. Unfortunately there's no equivalency operator for
39 // auxid_set_t, so this check needs to be spelled out. :-(
40 if( auxids1.size() != auxids2.size() ) {
41 return false;
42 }
43 for( SG::auxid_t auxid : auxids1 ) {
44 if( auxids2.find( auxid ) == auxids2.end() ) {
45 return false;
46 }
47 }
48
49 // Now, compare all elements:
50 for( SG::auxid_t auxid : auxids1 ) {
51
52 // Check the type of the variable:
53 const std::type_info* ti = reg.getType( auxid );
54 if( ! ti ) {
55 // This is weird, but there's not much that we can do about it
56 // here...
57 continue;
58 }
59 if( ( *ti != typeid( std::string ) ) &&
60 ( *ti != typeid( uint32_t ) ) &&
61 ( *ti != typeid( float ) ) &&
62 ( *ti != typeid( char ) ) &&
63 ( *ti != typeid( std::vector< uint32_t > ) ) ) {
64 // We just ignore every other type. Still, this is strange, let's
65 // warn the user about it.
66 std::cerr << "xAOD::FileMetaData::operator== WARNING Unsupported "
67 << "variable (\"" << reg.getName( auxid ) << "\"/"
69 << ") encountered" << std::endl;
70 continue;
71 }
72
73 // The variable name:
74 const std::string name = reg.getName( auxid );
75
76 // Treat different types separately:
77 if( *ti == typeid( std::string ) ) {
78
79 // Retrieve the values:
81 const std::string& value1 = acc( *this );
82 const std::string& value2 = acc( rhs );
83 // And simply compare them:
84 if( value1 != value2 ) {
85 return false;
86 }
87
88 } else if( *ti == typeid( uint32_t ) ) {
89
90 // Retrieve the values:
92 const uint32_t& value1 = acc( *this );
93 const uint32_t& value2 = acc( rhs );
94 // And simply compare them:
95 if( value1 != value2 ) {
96 return false;
97 }
98
99 } else if( *ti == typeid( float ) ) {
100
101 // Retrieve the values:
103 const float& value1 = acc( *this );
104 const float& value2 = acc( rhs );
105 // And (not so simply) compare them:
106 if( std::abs( value1 - value2 ) > 0.001 ) {
107 return false;
108 }
109
110 } else if( *ti == typeid( char ) ) {
111
112 // Retrieve the values:
114 const char& value1 = acc( *this );
115 const char& value2 = acc( rhs );
116 // And (not so simply) compare them:
117 if( value1 != value2 ) {
118 return false;
119 }
120 } else if ( *ti == typeid( std::vector<uint32_t> ) ) {
121 // One code to retrieve them
123 const std::vector<uint32_t>& value1 = acc( *this );
124 const std::vector<uint32_t>& value2 = acc( rhs );
125 // and in simplicity compare them
126 if( value1 != value2 ) {
127 return false;
128 }
129 } else {
130 // We should really never end up here unless a coding mistake was
131 // made upstream.
132 std::abort();
133 }
134 }
135
136 /*
137 // Compare the string properties:
138 std::array< MetaDataType, 8 > stringTypes{ { productionRelease, amiTag,
139 AODFixVersion, AODCalibVersion, dataType, geometryVersion,
140 conditionsTag, beamType } };
141 for( MetaDataType type : stringTypes ) {
142 // (Try to) Retrieve the properties:
143 std::string val1, val2;
144 const bool found1 = this->value( type, val1 );
145 const bool found2 = rhs.value( type, val2 );
146 // If both of them failed, then let's continue. If both of them are
147 // missing this variable, that's fine.
148 if( ( ! found1 ) && ( ! found2 ) ) {
149 continue;
150 }
151 // If the variable is only available on one of them, then we already
152 // have a difference. Although this point could be fine-tuned later on.
153 if( ( found1 && ( ! found2 ) ) || ( ( ! found1 ) && found2 ) ) {
154 return false;
155 }
156 // If both values were found, then let's compare them:
157 if( val1 != val2 ) {
158 return false;
159 }
160 }
161
162 // Compare the float propery/properties:
163 std::array< MetaDataType, 1 > floatTypes{ { beamEnergy } };
164 for( MetaDataType type : floatTypes ) {
165 // (Try to) Retrieve the properties:
166 float val1 = 0.0, val2 = 0.0;
167 const bool found1 = this->value( type, val1 );
168 const bool found2 = rhs.value( type, val2 );
169 // If both of them failed, then let's continue. If both of them are
170 // missing this variable, that's fine.
171 if( ( ! found1 ) && ( ! found2 ) ) {
172 continue;
173 }
174 // If the variable is only available on one of them, then we already
175 // have a difference. Although this point could be fine-tuned later on.
176 if( ( found1 && ( ! found2 ) ) || ( ( ! found1 ) && found2 ) ) {
177 return false;
178 }
179 // If both values were found, then let's compare them:
180 if( std::abs( val1 - val2 ) > 0.001 ) {
181 return false;
182 }
183 }
184 */
185
186 // The two objects were found to be equivalent:
187 return true;
188 }
189
191
192 return !( this->operator==( rhs ) );
193 }
194
195 bool FileMetaData_v1::value( MetaDataType type, std::string& val ) const {
196
197 // Get the accessor for this type:
199 if( ! acc ) {
200 return false;
201 }
202
203 // Check if the variable is available:
204 if( ! acc->isAvailable( *this ) ) {
205 return false;
206 }
207
208 // Read the value:
209 val = ( *acc )( *this );
210
211 // We were successful:
212 return true;
213 }
214
215 bool FileMetaData_v1::value( const std::string& type,
216 std::string& val ) const {
217
218 // Create an accessor object:
220
221 // Check if this variable is available:
222 if( ! acc.isAvailable( *this ) ) {
223 return false;
224 }
225
226 // Read the value:
227 val = acc( *this );
228
229 // We were successful:
230 return true;
231 }
232
233 bool FileMetaData_v1::setValue( MetaDataType type, const std::string& val ) {
234
235 // Get the accessor for this type:
237 if( ! acc ) {
238 return false;
239 }
240
241 // Set the value:
242 ( *acc )( *this ) = val;
243
244 // We were successful:
245 return true;
246 }
247
248 bool FileMetaData_v1::setValue( const std::string& type,
249 const std::string& val ) {
250
251 // Create the accessor object:
253
254 // Set the value:
255 acc( *this ) = val;
256
257 // We were successful:
258 return true;
259 }
260
262
263 // Get the accessor for this type:
265 if( ! acc ) {
266 return false;
267 }
268
269 // Check if the variable is available:
270 if( ! acc->isAvailable( *this ) ) {
271 return false;
272 }
273
274 // Read the value:
275 val = ( *acc )( *this );
276
277 // We were successful:
278 return true;
279 }
280
281 bool FileMetaData_v1::value( const std::string& type,
282 uint32_t& val ) const {
283
284 // Create an accessor object:
286
287 // Check if this variable is available:
288 if( ! acc.isAvailable( *this ) ) {
289 return false;
290 }
291
292 // Read the value:
293 val = acc( *this );
294
295 // We were successful:
296 return true;
297 }
298
300
301 // Get the accessor for this type:
303 if( ! acc ) {
304 return false;
305 }
306
307 // Set the value:
308 ( *acc )( *this ) = val;
309
310 // We were successful:
311 return true;
312 }
313
314 bool FileMetaData_v1::setValue( const std::string& type, uint32_t val ) {
315
316 // Create the accessor object:
318
319 // Set the value:
320 acc( *this ) = val;
321
322 // We were successful:
323 return true;
324 }
325
326 bool FileMetaData_v1::value( MetaDataType type, float& val ) const {
327
328 // Get the accessor for this type:
330 if( ! acc ) {
331 return false;
332 }
333
334 // Check if the variable is available:
335 if( ! acc->isAvailable( *this ) ) {
336 return false;
337 }
338
339 // Read the value:
340 val = ( *acc )( *this );
341
342 // We were successful:
343 return true;
344 }
345
346 bool FileMetaData_v1::value( const std::string& type,
347 float& val ) const {
348
349 // Create an accessor object:
350 const Accessor< float > acc( type );
351
352 // Check if this variable is available:
353 if( ! acc.isAvailable( *this ) ) {
354 return false;
355 }
356
357 // Read the value:
358 val = acc( *this );
359
360 // We were successful:
361 return true;
362 }
363
365
366 // Get the accessor for this type:
368 if( ! acc ) {
369 return false;
370 }
371
372 // Set the value:
373 ( *acc )( *this ) = val;
374
375 // We were successful:
376 return true;
377 }
378
379 bool FileMetaData_v1::setValue( const std::string& type, float val ) {
380
381 // Create the accessor object:
382 const Accessor< float > acc( type );
383
384 // Set the value:
385 acc( *this ) = val;
386
387 // We were successful:
388 return true;
389 }
390
391 bool FileMetaData_v1::value( MetaDataType type, bool& val ) const {
392
393 // Get the accessor for this type:
395 if( ! acc ) {
396 return false;
397 }
398
399 // Check if the variable is available:
400 if( ! acc->isAvailable( *this ) ) {
401 return false;
402 }
403
404 // Read the value:
405 val = ( *acc )( *this );
406
407 // We were successful:
408 return true;
409 }
410
411 bool FileMetaData_v1::value( const std::string& type,
412 bool& val ) const {
413
414 // Create an accessor object:
415 const Accessor< char > acc( type );
416
417 // Check if this variable is available:
418 if( ! acc.isAvailable( *this ) ) {
419 return false;
420 }
421
422 // Read the value:
423 val = acc( *this );
424
425 // We were successful:
426 return true;
427 }
428
430
431 // Get the accessor for this type:
433 if( ! acc ) {
434 return false;
435 }
436
437 // Set the value:
438 ( *acc )( *this ) = val;
439
440 // We were successful:
441 return true;
442 }
443
444 bool FileMetaData_v1::setValue( const std::string& type, bool val ) {
445
446 // Create the accessor object:
447 const Accessor< char > acc( type );
448
449 // Set the value:
450 acc( *this ) = val;
451
452 // We were successful:
453 return true;
454 }
455
456 bool FileMetaData_v1::value(const std::string& type,
457 std::vector< uint32_t >& val) const {
458 // Create an accessor object:
460
461 // Check if this variable is available:
462 if (!acc.isAvailable(*this)) {
463 return false;
464 }
465
466 // Read the value:
467 val = acc(*this);
468
469 // We were successful:
470 return true;
471 }
472
473 bool FileMetaData_v1::setValue(const std::string& type,
474 const std::vector< uint32_t >& val) {
475 // Create the accessor object:
477
478 // Set the value:
479 acc(*this) = val;
480
481 // We were successful:
482 return true;
483 }
484
486#define PRINT_TYPE( TYPE ) \
487 case xAOD::FileMetaData_v1::TYPE: \
488 out << "xAOD::FileMetaData::" << #TYPE; \
489 break
490
498std::ostream& operator<< ( std::ostream& out,
500
501 switch( type ) {
502
503 PRINT_TYPE( productionRelease );
504 PRINT_TYPE( amiTag );
505 PRINT_TYPE( AODFixVersion );
506 PRINT_TYPE( AODCalibVersion );
507 PRINT_TYPE( dataType );
508 PRINT_TYPE( geometryVersion );
509 PRINT_TYPE( conditionsTag );
510 PRINT_TYPE( beamEnergy );
511 PRINT_TYPE( beamType );
512 PRINT_TYPE( mcProcID );
513 PRINT_TYPE( simFlavour );
514 PRINT_TYPE( isDataOverlay );
515 PRINT_TYPE( mcCampaign );
516 PRINT_TYPE( generatorsInfo );
517 PRINT_TYPE( dataYear );
518
519 default:
520 out << "UNKNOWN (" << static_cast< int >( type ) << ")";
521 break;
522 }
523
524 // Return the same stream:
525 return out;
526}
527
528
529} // namespace xAOD
Handle mappings between names and auxid_t.
Helper class to provide constant type-safe access to aux data.
#define PRINT_TYPE(TYPE)
Helper macro for printing the incident types as a string.
Definition TIncident.cxx:28
const_iterator end() const
Return an end iterator.
ConcurrentBitset & erase(bit_t bit)
Turn off one bit.
bit_t size() const
Count the number of 1 bits in the set.
const_iterator find(bit_t bit) const
If bit bit is set, return an iterator pointing to it.
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items for this object.
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
AuxElement()
Default constructor.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Helper class to provide constant type-safe access to aux data.
A set of aux data identifiers.
Definition AuxTypes.h:47
bool setValue(MetaDataType type, const std::string &val)
Set a pre-defined string value on the object.
MetaDataType
Pre-defined metadata value types.
bool value(MetaDataType type, std::string &val) const
Get a pre-defined string value out of the object.
bool operator==(const FileMetaData_v1 &rhs) const
Operator testing the equality of two objects.
bool operator!=(const FileMetaData_v1 &rhs) const
Operator testing the inequality of two objects.
FileMetaData_v1()
Default constructor.
bool compareWith(const FileMetaData_v1 &rhs, const std::set< std::string > &ignore) const
Compare this FMD object with another, optionally ignoring some attributes.
Forward declaration.
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
const SG::AuxElement::Accessor< std::string > * metaDataTypeStringAccessorV1(FileMetaData_v1::MetaDataType type)
Helper function for getting an accessor for a pre-defined property.
const SG::AuxElement::Accessor< uint32_t > * metaDataTypeUIntAccessorV1(FileMetaData_v1::MetaDataType type)
Helper function for getting an accessor for a pre-defined property.
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
const SG::AuxElement::Accessor< float > * metaDataTypeFloatAccessorV1(FileMetaData_v1::MetaDataType type)
Helper function for getting an accessor for a pre-defined property.
std::ostream & operator<<(std::ostream &out, const std::pair< FIRST, SECOND > &pair)
Helper print operator.
const SG::AuxElement::Accessor< char > * metaDataTypeCharAccessorV1(FileMetaData_v1::MetaDataType type)
Helper function for getting an accessor for a pre-defined property.
setEventNumber uint32_t
Convert a type_info to a normalized string representation (matching the names used in the root dictio...