ATLAS Offline Software
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 
14 namespace 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 
36  : m_keyedData(), m_hashedData() {
37 
38  }
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 
76 
77  return ( m_hashedData.find( hash ) != m_hashedData.end() );
78  }
79 
90  const EventFormatElement*
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 
164 
165  return m_keyedData.end();
166  }
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:";
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 
223  void EventFormat_v1::dump() const
224  {
225  std::cout << *this;
226  }
227 
228 } // namespace xAOD
xAOD::EventFormat_v1::end
const_iterator end() const
STL-like function for getting the end of the container.
Definition: EventFormat_v1.cxx:163
xAOD::EventFormat_v1::get
const EventFormatElement * get(const std::string &key, bool quiet=false) const
Get the description of a given branch.
Definition: EventFormat_v1.cxx:91
vtune_athena.format
format
Definition: vtune_athena.py:14
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
xAOD::EventFormat_v1::dump
void dump() const
Dump the contents of this object.
Definition: EventFormat_v1.cxx:223
quiet
bool quiet
Definition: TrigGlobEffCorrValidation.cxx:170
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
xAOD::EventFormat_v1::m_classNames
std::vector< std::string > m_classNames
Names of the transient objects belonging to the branch names.
Definition: EventFormat_v1.h:88
xAOD::EventFormat_v1::clear
void clear()
Clear the object.
Definition: EventFormat_v1.cxx:144
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::EventFormatElement::parentName
const std::string & parentName() const
Get the name of the parent auxiliary object.
Definition: EventFormatElement.cxx:42
xAOD::EventFormatElement
Class describing one branch of the ROOT file.
Definition: EventFormatElement.h:39
xAOD::EventFormat_v1::m_hashedData
HashedData_t m_hashedData
Object associating hash keys with the descriptions.
Definition: EventFormat_v1.h:83
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
atn_test_sgProducerConsumerDataPool_jobOptions.end
end
Definition: atn_test_sgProducerConsumerDataPool_jobOptions.py:25
xAOD::EventFormatElement::branchName
const std::string & branchName() const
Get the branch/key name.
Definition: EventFormatElement.cxx:30
xAOD::EventFormat_v1::m_keyedData
KeyedData_t m_keyedData
Object associating string keys with the descriptions.
Definition: EventFormat_v1.h:81
xAOD::EventFormat_v1::m_branchHashes
std::vector< uint32_t > m_branchHashes
Hashed versions of the branch names.
Definition: EventFormat_v1.h:92
xAOD::EventFormatElement::hash
sgkey_t hash() const
Get the hash belonging to this branch/key.
Definition: EventFormatElement.cxx:48
xAOD::EventFormat_v1::m_parentNames
std::vector< std::string > m_parentNames
Names of the auxiliary parents of the branches.
Definition: EventFormat_v1.h:90
xAOD::EventFormat_v1::begin
const_iterator begin() const
STL-like function for getting the beginning of the container.
Definition: EventFormat_v1.cxx:158
lumiFormat.i
int i
Definition: lumiFormat.py:92
xAOD::EventFormat_v1::toTransient
void toTransient()
Interpret the persistent members of the object.
Definition: EventFormat_v1.cxx:168
xAOD::EventFormatElement::className
const std::string & className() const
Get the class name of this branch/key.
Definition: EventFormatElement.cxx:36
xAOD::EventFormat_v1
Event format metadata for xAOD files.
Definition: EventFormat_v1.h:38
test_pythinning.out
out
Definition: test_pythinning.py:94
xAOD::EventFormat_v1::m_branchNames
std::vector< std::string > m_branchNames
Names of the branches that we are describing.
Definition: EventFormat_v1.h:86
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
xAOD::EventFormat_v1::EventFormat_v1
EventFormat_v1()
Default constructor.
Definition: EventFormat_v1.cxx:35
EventFormat_v1.h
xAOD::EventFormat_v1::const_iterator
KeyedData_t::const_iterator const_iterator
Iterator for looping over the elements of the object.
Definition: EventFormat_v1.h:67
xAOD::EventFormat_v1::add
void add(const EventFormatElement &element, bool updatePersistent=true)
Add the description of a new branch.
Definition: EventFormat_v1.cxx:43
test_pyathena.counter
counter
Definition: test_pyathena.py:15
xAOD::EventFormat_v1::exists
bool exists(const std::string &key) const
Check if a description exists about a given branch.
Definition: EventFormat_v1.cxx:65
xAOD::operator<<
std::ostream & operator<<(std::ostream &out, const std::pair< FIRST, SECOND > &pair)
Helper print operator.
Definition: RDataSource.cxx:53
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37