ATLAS Offline Software
Loading...
Searching...
No Matches
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
18namespace D3PD {
19
24
29
30 StatusCode RootObjectMetadata::addVariable( const std::string& name,
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( std::move(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( std::move(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
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Internal class keeping track of a single variable.
static const size_t RANDOM_NAME_POSTFIX_LENGTH
Length of the random string appended to the object name.
const std::string & name() const
Get the name of the D3PDObject that this object describes.
std::set< Variable > m_variables
The list of variables created by a D3PDObject.
std::string m_prefix
Prefix used by the D3PDObject.
ObjectMetadata()
Default constructor.
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.
static bool isObjectMetadata(const std::string &name)
Function guessing if an object with a given name is object metadata.
StatusCode checkPrefixes()
Remove possibly overlooked prefixes in the variable names.
RootObjectMetadata()
Default constructor.
Block filler tool for noisy FEB information.
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...