ATLAS Offline Software
Loading...
Searching...
No Matches
EventFormat_v1.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: EventFormat_v1.cxx 641134 2015-01-22 19:35:12Z ssnyder $
6
7// STL include(s):
8#include <iostream>
9#include <iomanip>
10
11// Local include(s):
13
14namespace xAOD {
15
17 template< typename T >
18 std::ostream& operator<< ( std::ostream& out,
19 const std::vector< T >& vec ) {
20
21 out << "[";
22 typename std::vector< T >::const_iterator itr = vec.begin();
23 typename std::vector< T >::const_iterator end = vec.end();
24 for( ; itr != end; ++itr ) {
25 out << *itr;
26 if( ++itr != end ) {
27 out << ", ";
28 }
29 --itr;
30 }
31 out << "]";
32 return out;
33 }
34
39
44 bool updatePersistent ) {
45
46 // Set the transient-only variables:
47 m_keyedData[ element.branchName() ] = element;
48 m_hashedData[ element.hash() ] = element;
49
50 // Set the persistent variables:
51 if( updatePersistent ) {
52 m_branchNames.push_back( element.branchName() );
53 m_classNames.push_back( element.className() );
54 m_parentNames.push_back( element.parentName() );
55 m_branchHashes.push_back( element.hash() );
56 }
57 return;
58 }
59
65 bool EventFormat_v1::exists( const std::string& key ) const {
66
67 return ( m_keyedData.find( key ) != m_keyedData.end() );
68 }
69
75 bool EventFormat_v1::exists( uint32_t hash ) const {
76
77 return ( m_hashedData.find( hash ) != m_hashedData.end() );
78 }
79
91 EventFormat_v1::get( const std::string& key, bool quiet ) const {
92
93 KeyedData_t::const_iterator itr = m_keyedData.find( key );
94 if( itr == m_keyedData.end() ) {
95 if (!quiet) {
96 std::cerr << "<xAOD::EventFormat_v1::get>"
97 << " Information requested about unknown branch ("
98 << key << ")" << std::endl;
99 }
100 return nullptr;
101 }
102
103 return &( itr->second );
104 }
105
117
118 HashedData_t::const_iterator itr = m_hashedData.find( hash );
119 if( itr == m_hashedData.end() ) {
120 if (!quiet) {
121 // Get the current state of the stream:
122 const char fillChar = std::cerr.fill();
123 const std::ios_base::fmtflags flags = std::cerr.flags();
124 const std::streamsize width = std::cerr.width();
125
126 // Do the printout:
127 std::cerr << "<xAOD::EventFormat_v1::get>"
128 << " Information requested about unknown hash ("
129 << std::setw( 8 ) << std::hex << std::setfill( '0' )
130 << hash << ")" << std::endl;
131
132 // Restore the original state of the stream:
133 std::cerr.fill( fillChar );
134 std::cerr.flags( flags );
135 std::cerr.width( width );
136 }
137
138 return nullptr;
139 }
140
141 return &( itr->second );
142 }
143
145
146 // Clear the transient variables:
147 m_keyedData.clear();
148 m_hashedData.clear();
149
150 // Clear the persistent variables:
151 m_branchNames.clear();
152 m_classNames.clear();
153 m_parentNames.clear();
154 m_branchHashes.clear();
155 return;
156 }
157
159
160 return m_keyedData.begin();
161 }
162
167
169
170 // Clear the transient variables:
171 m_keyedData.clear();
172 m_hashedData.clear();
173
174 // A little sanity check:
175 if( ( m_branchNames.size() != m_classNames.size() ) ||
176 ( m_branchNames.size() != m_parentNames.size() ) ||
177 ( m_branchNames.size() != m_branchHashes.size() ) ) {
178 std::cerr << "<xAOD::EventFormat_v1::toTransient> "
179 << "Internal inconsistency in the persistent data"
180 << std::endl;
181 std::cerr << " m_branchNames = " << m_branchNames << std::endl;
182 std::cerr << " m_classNames = " << m_classNames << std::endl;
183 std::cerr << " m_parentNames = " << m_parentNames << std::endl;
184 std::cerr << " m_branchHashes = " << m_branchHashes << std::endl;
185 return;
186 }
187
188 // Set up the transient variables:
189 for( size_t i = 0; i < m_branchNames.size(); ++i ) {
191 m_classNames[ i ],
192 m_parentNames[ i ],
193 m_branchHashes[ i ] ),
194 false );
195 }
196
197 return;
198 }
199
208 std::ostream& operator<<( std::ostream& out,
209 const EventFormat_v1& format ) {
210
211 out << "xAOD::EventFormat:";
212 EventFormat_v1::const_iterator itr = format.begin();
213 EventFormat_v1::const_iterator end = format.end();
214 for( int counter = 1; itr != end; ++itr, ++counter ) {
215 out << std::endl << counter << ". element: " << itr->second;
216 }
217
218 return out;
219 }
220
221
224 {
225 std::cout << *this;
226 }
227
228} // namespace xAOD
std::vector< size_t > vec
const double width
Class describing one branch of the ROOT file.
sgkey_t hash() const
Get the hash belonging to this branch/key.
const std::string & branchName() const
Get the branch/key name.
const std::string & parentName() const
Get the name of the parent auxiliary object.
const std::string & className() const
Get the class name of this branch/key.
Event format metadata for xAOD files.
KeyedData_t::const_iterator const_iterator
Iterator for looping over the elements of the object.
EventFormat_v1()
Default constructor.
std::vector< uint32_t > m_branchHashes
Hashed versions of the branch names.
KeyedData_t m_keyedData
Object associating string keys with the descriptions.
void add(const EventFormatElement &element, bool updatePersistent=true)
Add the description of a new branch.
const_iterator end() const
STL-like function for getting the end of the container.
std::vector< std::string > m_parentNames
Names of the auxiliary parents of the branches.
bool exists(const std::string &key) const
Check if a description exists about a given branch.
std::vector< std::string > m_branchNames
Names of the branches that we are describing.
std::vector< std::string > m_classNames
Names of the transient objects belonging to the branch names.
const EventFormatElement * get(const std::string &key, bool quiet=false) const
Get the description of a given branch.
void dump() const
Dump the contents of this object.
void toTransient()
Interpret the persistent members of the object.
void clear()
Clear the object.
const_iterator begin() const
STL-like function for getting the beginning of the container.
HashedData_t m_hashedData
Object associating hash keys with the descriptions.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
std::ostream & operator<<(std::ostream &out, const std::pair< FIRST, SECOND > &pair)
Helper print operator.
setEventNumber uint32_t