ATLAS Offline Software
RootObjectMetadata.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: RootObjectMetadata.cxx 472095 2011-12-02 10:27:01Z krasznaa $
6 
7 // STL include(s):
8 #include <vector>
9 #include <algorithm>
10 
11 // Gaudi/Athena include(s):
13 
14 // Local include(s):
15 #include "RootObjectMetadata.h"
16 #include "isPrimitive.h"
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( ( m_prefix != "" ) &&
36  ( name.find( m_prefix ) != 0 ) ) {
37  REPORT_MESSAGE_WITH_CONTEXT( MSG::ERROR, "RootObjectMetadata" )
38  << "Specified variable name (" << name << ") doesn't have the "
39  << "expected prefix (" << m_prefix << ")";
40  return StatusCode::RECOVERABLE;
41  }
42 
43  // Create a new variable:
44  Variable var;
45 
46  // Remove the prefix from the variable name:
47  var.setName( name.substr( m_prefix.size(), name.npos ) );
48 
49  // Check if it's already amongst the existing variables:
50  if( m_variables.find( var ) != m_variables.end() ) {
51  return StatusCode::SUCCESS;
52  }
53 
54  // Set the type of the variable:
55  var.setType( type );
56 
57  // Set whether the variable is a primitive:
58  var.setPrimitive( isPrimitive( type ) );
59 
60  // Set the documentation string for the variable:
61  var.setDoc( docstring );
62 
63  // Remember the variable:
64  m_variables.insert( var );
65 
66  return StatusCode::SUCCESS;
67  }
68 
79 
80  // For simplicity's sake I don't modify the original std::set,
81  // but create a new one instead. This is slightly slower, but
82  // much easier. In any case, performance is not a major concern
83  // in this code...
84  std::set< Variable > newVariables;
85 
86  // Loop over the variables:
87  std::set< Variable >::const_iterator itr = m_variables.begin();
88  std::set< Variable >::const_iterator end = m_variables.end();
89  for( ; itr != end; ++itr ) {
90 
91  // Check if the variable name begins with the prefix (it shouldn't):
92  if( ( m_prefix != "" ) &&
93  ( itr->name().find( m_prefix ) == 0 ) ) {
94  // Create a copy of the variable, and remove the prefix from its name:
95  Variable var = *itr;
96  var.setName( var.name().substr( m_prefix.size(), var.name().npos ) );
97  // Insert it into the new container:
98  newVariables.insert( var );
99  } else {
100  // Insert the variable as it is into the new container:
101  newVariables.insert( *itr );
102  }
103  }
104 
105  // Swap the two containers. (This should be a fairly quick operation...)
106  m_variables.swap( newVariables );
107 
108  return StatusCode::SUCCESS;
109  }
110 
118  bool RootObjectMetadata::isObjectMetadata( const std::string& name ) {
119 
120  if( ( name.size() > ( RANDOM_NAME_POSTFIX_LENGTH + 1 ) ) &&
121  ( name[ name.size() - ( RANDOM_NAME_POSTFIX_LENGTH + 1 ) ] == '_' ) ) {
122  return true;
123  } else {
124  return false;
125  }
126  }
127 
128 } // namespace D3PD
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
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:118
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:78
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
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
isPrimitive.h
D3PD
Block filler tool for noisy FEB information.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:21
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:32
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:195
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
D3PD::ObjectMetadata::name
const std::string & name() const
Get the name of the D3PDObject that this object describes.
Definition: ObjectMetadata.cxx:170