ATLAS Offline Software
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 
18 namespace {
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 
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() ) {
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: "
106  << m_aodContainerNames );
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  }
124  if( evtStore()->contains< xAOD::CaloClusterContainer >( xaodName ) ) {
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ClusterCreator::m_aodContainerNames
std::vector< std::string > m_aodContainerNames
The keys of the input CaloClusterContainer.
Definition: ClusterCreator.h:47
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ClusterCreator::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: ClusterCreator.cxx:92
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloClusterContainer
Storable container for CaloCluster.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloClusterContainer.h:37
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
CaloClusterCellLinkContainer
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current Athena::TPCnvVers::Current CaloClusterCellLinkContainer
Definition: CaloTPCnv.cxx:95
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
UploadAMITag.nKeys
nKeys
Definition: UploadAMITag.larcaf.py:183
CaloClusterAuxContainer.h
ClusterCreator::m_cnvTool
ToolHandle< xAODMaker::ICaloClusterCnvTool > m_cnvTool
Connection to the converter tool.
Definition: ClusterCreator.h:55
ClusterCreator::ClusterCreator
ClusterCreator(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: ClusterCreator.cxx:39
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
ClusterCreator::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: ClusterCreator.cxx:49
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
xAOD::AuxContainerBase::getDynamicAuxIDs
virtual const auxid_set_t & getDynamicAuxIDs() const override
Get the types(names) of variables created dynamically.
Definition: AuxContainerBase.cxx:683
xAOD::CaloClusterContainer
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloClusterContainer.h:17
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
CxxUtils::ConcurrentBitset::size
bit_t size() const
Count the number of 1 bits in the set.
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AthAlgorithm
Definition: AthAlgorithm.h:47
xAOD::CaloClusterAuxContainer_v2
Auxiliary container for calorimeter cluster containers.
Definition: CaloClusterAuxContainer_v2.h:30
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
xAOD::CaloClusterAuxContainer
CaloClusterAuxContainer_v2 CaloClusterAuxContainer
Define the latest version of the calorimeter cluster auxiliary container.
Definition: CaloClusterAuxContainer.h:16
operator<<
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
Definition: TestGaudiProperty.cxx:69
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
ClusterCreator::m_xaodContainerNames
std::vector< std::string > m_xaodContainerNames
The keys for the output xAOD::CaloClusterContainer.
Definition: ClusterCreator.h:49
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
ClusterCreator.h
CaloClusterContainer.h
ClusterCreator::m_keySet
bool m_keySet
True if keys set by jobO.
Definition: ClusterCreator.h:52
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.