ATLAS Offline Software
CaloClusterRetriever.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "CaloClusterRetriever.h"
6 
7 #include "AthenaKernel/Units.h"
8 
10 
11 namespace JiveXML {
12 
19  CaloClusterRetriever::CaloClusterRetriever(const std::string& type,const std::string& name,const IInterface* parent):
21  m_sgKeyFavourite ("LArClusterEM")
22  {
23  //Only declare the interface
24  declareInterface<IDataRetriever>(this);
25 
26  declareProperty("FavouriteClusterCollection" ,m_sgKeyFavourite,
27  "Collection to be first in output, shown in Atlantis without switching");
28  declareProperty("OtherClusterCollections" ,m_otherKeys,
29  "Other collections to be retrieved. If list left empty, all available retrieved");
30  declareProperty("DoWriteHLT", m_doWriteHLT = false,"Ignore HLTAutokey object by default."); // ignore HLTAutoKey objects
31  }
32 
34  {
35 
36  ATH_MSG_DEBUG("Initialising Tool");
37 
39 
40  return StatusCode::SUCCESS;
41  }
42 
48  StatusCode CaloClusterRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
49 
50  ATH_MSG_DEBUG( "in retrieveAll()" );
51 
52  //obtain the default collection first
53  ATH_MSG_DEBUG( "Trying to retrieve " << dataTypeName() << " (" << m_sgKeyFavourite.key() << ")" );
54 
56  if (ccc_primary.isValid()) {
57  DataMap data = getData(&(*ccc_primary));
58  if (FormatTool->AddToEvent(dataTypeName(), m_sgKeyFavourite.key() + "_ESD", &data).isFailure()) {
59  ATH_MSG_WARNING("Failed to retrieve favourite Collection " << m_sgKeyFavourite.key() );
60  }
61  else {
62  ATH_MSG_DEBUG(dataTypeName() << " (" << m_sgKeyFavourite.key() << ") CaloCluster retrieved");
63  }
64  }
65  else{
66  ATH_MSG_WARNING("Favourite Collection " << m_sgKeyFavourite.key() << " not found in SG ");
67  }
68 
69  if ( m_otherKeys.empty() ) {
70  //obtain all other collections from StoreGate
71  std::vector<std::string> allkeys;
72  evtStore()->keys(static_cast<CLID>( ClassID_traits<xAOD::CaloClusterContainer>::ID() ), allkeys);
73  for (const auto& key : allkeys) {
74  if (key!=m_sgKeyFavourite.key()) {
75  ATH_MSG_DEBUG( "Trying to retrieve all " << dataTypeName() << " (" << key << ")" );
77  if (!containerRH.isValid()) {
78  ATH_MSG_DEBUG( "Unable to retrieve CaloCluster collection " << key );
79  } else {
80  std::string::size_type position = key.find("HLTAutoKey",0);
81  if ( m_doWriteHLT ){ position = 99; } // override SG key find
82  if ( position != 0 ){ // SG key doesn't contain HLTAutoKey
83  DataMap data = getData(&*containerRH);
84  if ( FormatTool->AddToEvent(dataTypeName(), containerRH.key()+"_ESD", &data).isFailure()){
85  ATH_MSG_WARNING( "Collection " << containerRH.key() << " not found in SG " );
86  }else{
87  ATH_MSG_DEBUG( dataTypeName() << " (" << containerRH.key() << ") CaloCluster retrieved" );
88  }
89  }
90  }
91  }
92  }
93  }else {
94  //obtain all collections with keys provided by user: m_otherKeys
95  for (const auto& key : m_otherKeys) {
96  if (key!=m_sgKeyFavourite.key()) {
97  ATH_MSG_DEBUG( "Trying to retrieve selected " << dataTypeName() << " (" << key << ")" );
99  if (!containerRH.isValid()) {
100  ATH_MSG_DEBUG( "Unable to retrieve CaloCluster collection " << key );
101  } else {
102  DataMap data = getData(&*containerRH);
103  if ( FormatTool->AddToEvent(dataTypeName(), containerRH.key()+"_ESD", &data).isFailure()){
104  ATH_MSG_WARNING( "Collection " << containerRH.key() << " not found in SG " );
105  }else{
106  ATH_MSG_DEBUG( dataTypeName() << " (" << containerRH.key() << ") retrieved" );
107  }
108  }
109  }
110  }
111  }
112  //All collections retrieved okay
113  return StatusCode::SUCCESS;
114  }
115 
116 
124 
125  ATH_MSG_DEBUG( "getData()" );
126 
128 
129  DataVect phi; phi.reserve(ccc->size());
130  DataVect eta; eta.reserve(ccc->size());
131  DataVect et; et.reserve(ccc->size());
132  DataVect idVec; idVec.reserve(ccc->size());
133  DataVect numCellsVec; numCellsVec.reserve(ccc->size());
134  DataVect cells; cells.reserve( ccc->size() );
135 
136  int noClu = ccc->size();
137  int noCells = 0;
138 
139  int id = 0;
140  for (const auto cluster : *ccc) {
141  phi.emplace_back(cluster->phi());
142  eta.emplace_back(cluster->eta());
143  et.emplace_back(cluster->et()*(1./GeV));
144  idVec.emplace_back( ++id );
145 
146  int numCells = cluster->size();
147  numCellsVec.emplace_back( numCells );
148  noCells += numCells;
149 
150  for (const auto cell : *cluster) {
151  cells.push_back(cell->ID().get_compact());
152  }
153  }
154 
155  std::string tagCells;
156  if(noClu){
157  tagCells = "cells multiple=\"" +DataType(noCells/(noClu*1.0)).toString()+"\"";
158  }else{
159  tagCells = "cells multiple=\"1.0\"";
160  }
161 
162  // Start with mandatory entries
163  const auto nEntries = phi.size();
164  DataMap["phi"] = std::move(phi);
165  DataMap["eta"] = std::move(eta);
166  DataMap["et"] = std::move(et);
167  DataMap[tagCells] = std::move(cells);
168  DataMap["numCells"] = std::move(numCellsVec);
169  DataMap["id"] = std::move(idVec);
170 
171  //Be verbose
172  ATH_MSG_DEBUG( dataTypeName() << " , collection: " << dataTypeName()
173  << " retrieved with " << nEntries << " entries" );
174 
175  //All collections retrieved okay
176  return DataMap;
177 
178  } // retrieve
179 
180  //--------------------------------------------------------------------------
181 
182 } // JiveXML namespace
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
et
Extra patterns decribing particle interation process.
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
JiveXML::CaloClusterRetriever::m_otherKeys
std::vector< std::string > m_otherKeys
Definition: CaloClusterRetriever.h:55
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
xAOD::et
et
Definition: TrigEMCluster_v1.cxx:25
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
JiveXML::CaloClusterRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: CaloClusterRetriever.cxx:48
JiveXML::CaloClusterRetriever::CaloClusterRetriever
CaloClusterRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: CaloClusterRetriever.cxx:19
JiveXML::CaloClusterRetriever::getData
const DataMap getData(const xAOD::CaloClusterContainer *)
Retrieve basic parameters, mainly four-vectors.
Definition: CaloClusterRetriever.cxx:123
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
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
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
CaloClusterRetriever.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:22
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Units.h
Wrapper to avoid constant divisions when using units.
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
xAOD::TauJetParameters::numCells
@ numCells
Definition: TauDefs.h:171
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
JiveXML::CaloClusterRetriever::m_doWriteHLT
bool m_doWriteHLT
Definition: CaloClusterRetriever.h:56
JiveXML::CaloClusterRetriever::initialize
StatusCode initialize()
Default AthAlgTool methods.
Definition: CaloClusterRetriever.cxx:33
JiveXML::CaloClusterRetriever::m_sgKeyFavourite
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_sgKeyFavourite
Definition: CaloClusterRetriever.h:54
AthAlgTool
Definition: AthAlgTool.h:26
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
JiveXML::CaloClusterRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: CaloClusterRetriever.h:48
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37