ATLAS Offline Software
Loading...
Searching...
No Matches
ClusterCreator.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: ClusterCreator.cxx 596346 2014-05-10 13:47:20Z krasznaa $
6
7// Gaudi/Athena include(s):
9
10// EDM include(s):
11#include "CaloEvent/CaloClusterContainer.h"
14
15// Local include(s):
16#include "ClusterCreator.h"
17
18namespace {
19
21 template< class T >
22 std::ostream& operator<< ( std::ostream& out,
23 const std::vector< T >& vec ) {
24
25 out << "[";
26 for( size_t i = 0; i < vec.size(); ++i ) {
27 out << vec[ i ];
28 if( i < ( vec.size() - 1 ) ) {
29 out << ", ";
30 }
31 }
32 out << "]";
33
34 return out;
35 }
36
37} // private namespace
38
39ClusterCreator::ClusterCreator( const std::string& name,
40 ISvcLocator* svcLoc )
41 : AthAlgorithm( name, svcLoc ),
42 m_keySet( false ),
43 m_cnvTool( "xAODMaker::CaloClusterCnvTool/CaloClusterCnvTool", this ) {
44
45 declareProperty( "AODContainerNames", m_aodContainerNames );
46 declareProperty( "xAODContainerNames", m_xaodContainerNames );
47}
48
50
51 ATH_MSG_INFO( "Initializing" );
52
53 // Retrieve the needed tool(s):
54 CHECK( m_cnvTool.retrieve() );
55
56 if( m_xaodContainerNames.empty() ) {
57 // Assume same key in AOD and xAOD if to explicitly set
59 }
60
61 // A sanity check:
62 if( m_aodContainerNames.size() != m_xaodContainerNames.size() ) {
63 REPORT_MESSAGE( MSG::FATAL )
64 << "Job properties 'AODContainerNames' and 'xAODContainerNames' "
65 << "have unequal lenght! ("
66 << m_aodContainerNames.size() << " vs "
67 << m_xaodContainerNames.size() << ")";
68 return StatusCode::FAILURE;
69 }
70
71 // Tell the user what's going to happen:
72 if( ( m_aodContainerNames.empty() ) &&
73 ( m_xaodContainerNames.empty() ) ) {
74 ATH_MSG_INFO( "Will convert all CaloClusterContainers in the event");
75 m_keySet = false;
76 }
77 else {
78 m_keySet = true;
79 const size_t nKeys = m_aodContainerNames.size();
80 for (size_t i=0;i<nKeys;++i) {
81 ATH_MSG_INFO( "Will convert CaloClusterContainer#"
83 << " to xAOD::CaloClusterContainer#"
84 << m_xaodContainerNames[ i ] );
85 }
86 }
87
88 // Return gracefully:
89 return StatusCode::SUCCESS;
90}
91
93
94 //
95 // If no StoreGate keys were set, convert everything:
96 //
97 if( ! m_keySet ) {
98 // Get the keys from StoreGate:
100 false, false );
101
102 // Use same container key for input and output:
104
105 ATH_MSG_DEBUG( "Found the following CaloClusterContainers: "
107 }
108
109 //
110 // Loop over container keys:
111 //
112 const size_t nKeys = m_aodContainerNames.size();
113 for( size_t iKey = 0; iKey < nKeys; ++iKey ) {
114
115 const std::string& aodName = m_aodContainerNames[ iKey ];
116 const std::string& xaodName = m_xaodContainerNames[ iKey ];
117
118 // Check if anything needs to be done:
119 if( ! evtStore()->contains< CaloClusterContainer >( aodName ) ) {
120 ATH_MSG_DEBUG( "AOD cluster container " << aodName
121 << " not found. Ignored." );
122 continue;
123 }
125 ATH_MSG_DEBUG( "xAOD::CaloCluster with key " << xaodName
126 << " exists already. No conversion done" );
127 continue;
128 }
129
130 // Retrieve the AOD clusters:
131 const CaloClusterContainer* aod = nullptr;
132 CHECK( evtStore()->retrieve( aod, aodName ) );
133 ATH_MSG_DEBUG( "Retrieved clusters with key: " << aodName );
134
135 // Create new Cell-Link container:
136 const std::string ccclc_name = xaodName + "_links";
139 CHECK( evtStore()->record( ccclc, ccclc_name ) );
140
141 // Create the xAOD container and its auxiliary store:
143 CHECK( evtStore()->record( xaod, xaodName ) );
144
146 CHECK( evtStore()->record( aux, xaodName + "Aux." ) );
147
148 xaod->setStore( aux );
149 ATH_MSG_DEBUG( "Recorded xAOD clusters with key: " << xaodName );
150
151
152 // Create the xAOD objects:
155 for(unsigned i = 0 ; itr != end; ++itr, ++i ) {
156
157 ATH_MSG_VERBOSE( "Copying cluster #" << i );
158
159 // Create the xAOD object:
160 xAOD::CaloCluster* cluster = new xAOD::CaloCluster();
161 xaod->push_back( cluster );
162
163 // Leave the conversion up to the tool:
164 CHECK( m_cnvTool->convert( *itr, cluster, ccclc ) );
165
166 ATH_MSG_VERBOSE( "Number of dynamic auxiliary variables: "
167 << aux->getDynamicAuxIDs().size() );
168
169 } // end loop over clusters
170
171 } // end loop over cluster containers
172
173 // Return gracefully:
174 return StatusCode::SUCCESS;
175}
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current CaloClusterCellLinkContainer
Definition CaloTPCnv.cxx:95
std::vector< size_t > vec
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ClusterCreator(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
std::vector< std::string > m_xaodContainerNames
The keys for the output xAOD::CaloClusterContainer.
ToolHandle< xAODMaker::ICaloClusterCnvTool > m_cnvTool
Connection to the converter tool.
virtual StatusCode execute()
Function executing the algorithm.
virtual StatusCode initialize()
Function initialising the algorithm.
bool m_keySet
True if keys set by jobO.
std::vector< std::string > m_aodContainerNames
The keys of the input CaloClusterContainer.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
CaloClusterAuxContainer_v2 CaloClusterAuxContainer
Define the latest version of the calorimeter cluster auxiliary container.