ATLAS Offline Software
RootObjectMetadata.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: RootObjectMetadata.cxx 472095 2011-12-02 10:27:01Z krasznaa $
6 
7 
8 
9 // Gaudi/Athena include(s):
11 
12 // Local include(s):
13 #include "RootObjectMetadata.h"
14 #include "isPrimitive.h"
15 // STL include(s):
16 #include <set>
17 
18 namespace D3PD {
19 
21  : ObjectMetadata() {
22 
23  }
24 
26  : ObjectMetadata( parent ) {
27 
28  }
29 
31  const std::string& type,
32  const std::string& docstring ) {
33 
34  // Check that the variable has the correct prefix:
35  if( ( not m_prefix.empty() ) && ( not name.starts_with( m_prefix )) ) {
36  REPORT_MESSAGE_WITH_CONTEXT( MSG::ERROR, "RootObjectMetadata" )
37  << "Specified variable name (" << name << ") doesn't have the "
38  << "expected prefix (" << m_prefix << ")";
39  return StatusCode::RECOVERABLE;
40  }
41 
42  // Create a new variable:
43  Variable var;
44 
45  // Remove the prefix from the variable name:
46  var.setName( name.substr( m_prefix.size(), name.npos ) );
47 
48  // Check if it's already amongst the existing variables:
49  if( m_variables.find( var ) != m_variables.end() ) {
50  return StatusCode::SUCCESS;
51  }
52 
53  // Set the type of the variable:
54  var.setType( type );
55 
56  // Set whether the variable is a primitive:
57  var.setPrimitive( isPrimitive( type ) );
58 
59  // Set the documentation string for the variable:
60  var.setDoc( docstring );
61 
62  // Remember the variable:
63  m_variables.insert( var );
64 
65  return StatusCode::SUCCESS;
66  }
67 
78 
79  // For simplicity's sake I don't modify the original std::set,
80  // but create a new one instead. This is slightly slower, but
81  // much easier. In any case, performance is not a major concern
82  // in this code...
83  std::set< Variable > newVariables;
84 
85  // Loop over the variables:
86  std::set< Variable >::const_iterator itr = m_variables.begin();
87  std::set< Variable >::const_iterator end = m_variables.end();
88  for( ; itr != end; ++itr ) {
89 
90  // Check if the variable name begins with the prefix (it shouldn't):
91  if( ( not m_prefix.empty() ) &&
92  ( itr->name().starts_with( m_prefix )) ) {
93  // Create a copy of the variable, and remove the prefix from its name:
94  Variable var = *itr;
95  var.setName( var.name().substr( m_prefix.size(), var.name().npos ) );
96  // Insert it into the new container:
97  newVariables.insert( var );
98  } else {
99  // Insert the variable as it is into the new container:
100  newVariables.insert( *itr );
101  }
102  }
103 
104  // Swap the two containers. (This should be a fairly quick operation...)
105  m_variables.swap( newVariables );
106 
107  return StatusCode::SUCCESS;
108  }
109 
117  bool RootObjectMetadata::isObjectMetadata( const std::string& name ) {
118 
119  if( ( name.size() > ( RANDOM_NAME_POSTFIX_LENGTH + 1 ) ) &&
120  ( name[ name.size() - ( RANDOM_NAME_POSTFIX_LENGTH + 1 ) ] == '_' ) ) {
121  return true;
122  } else {
123  return false;
124  }
125  }
126 
127 } // namespace D3PD
beamspotnt.var
var
Definition: bin/beamspotnt.py:1393
D3PD::RootObjectMetadata::isObjectMetadata
static bool isObjectMetadata(const std::string &name)
Function guessing if an object with a given name is object metadata.
Definition: RootObjectMetadata.cxx:117
D3PD::ObjectMetadata::m_variables
std::set< Variable > m_variables
The list of variables created by a D3PDObject.
Definition: ObjectMetadata.h:172
D3PD::RootObjectMetadata::checkPrefixes
StatusCode checkPrefixes()
Remove possibly overlooked prefixes in the variable names.
Definition: RootObjectMetadata.cxx:77
D3PD::ObjectMetadata::m_prefix
std::string m_prefix
Prefix used by the D3PDObject.
Definition: ObjectMetadata.h:174
RootObjectMetadata.h
D3PD::isPrimitive
bool isPrimitive(const std::string &type)
This function is used in the code generator to determine from a type name if it's a primitive type or...
Definition: isPrimitive.cxx:24
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
isPrimitive.h
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
test_pyathena.parent
parent
Definition: test_pyathena.py:15
D3PD::RootObjectMetadata::addVariable
StatusCode addVariable(const std::string &name, const std::string &type, const std::string &docstring)
Function adding a variable, when the exact type_info is not available.
Definition: RootObjectMetadata.cxx:30
D3PD::RootObjectMetadata::RootObjectMetadata
RootObjectMetadata()
Default constructor.
Definition: RootObjectMetadata.cxx:20
D3PD::RootObjectMetadata
Extension of the ObjectMetadata class for reading D3PD files.
Definition: RootObjectMetadata.h:33
REPORT_MESSAGE_WITH_CONTEXT
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:345
D3PD::ObjectMetadata
D3PD variable metadata handling class.
Definition: ObjectMetadata.h:36
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
errorcheck.h
Helpers for checking error return status codes and reporting errors.
D3PD::ObjectMetadata::Variable
Internal class keeping track of a single variable.
Definition: ObjectMetadata.h:131
D3PD::ObjectMetadata::RANDOM_NAME_POSTFIX_LENGTH
static const size_t RANDOM_NAME_POSTFIX_LENGTH
Length of the random string appended to the object name.
Definition: ObjectMetadata.h:109
D3PD::ObjectMetadata::name
const std::string & name() const
Get the name of the D3PDObject that this object describes.
Definition: ObjectMetadata.cxx:170