ATLAS Offline Software
AFP_VertexRecoTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 using namespace std;
8 
10  const std::string &name,
11  const IInterface *parent)
12  : base_class(type, name, parent)
13 {
14  ATH_MSG_DEBUG("in AFP_VertexRecoTool constructor");
15 }
16 
17 
19 {
20  ATH_MSG_DEBUG("in AFP_VertexRecoTool::initialize()");
21 
22  // vertex reconstruction tools
23  if(m_recoToolsList.empty())
24  {
25  ATH_MSG_ERROR("No vertex reconstruction tools set, check settings in AFP_VertexReco/AFP_VertexReco.py. Aborting.");
26  return StatusCode::FAILURE;
27  }
28  else
29  {
30  ATH_MSG_DEBUG("There are these tools in m_recoToolsList: "<<m_recoToolsList<<", will retrieve");
31  CHECK( m_recoToolsList.retrieve() );
32  }
33 
34  // output containers for the vertex reconstruction tools
35  if(m_arrayOfWriteHandleKeys.empty())
36  {
37  ATH_MSG_ERROR("No output vertex containers provided, check settings in AFP_VertexReco/AFP_VertexReco.py. Aborting.");
38  return StatusCode::FAILURE;
39  }
40  else
41  {
42  ATH_MSG_DEBUG("There are these write handle keys in m_arrayOfWriteHandleKeys: "<<m_arrayOfWriteHandleKeys<<", will initialize");
43  CHECK( m_arrayOfWriteHandleKeys.initialize() );
44  }
45 
46 
47  // the code in execute relies on the facts that (a) the keys in WriteHandleKeyArray are unique; (b) all output container names from vertex reco tools are also in WriteHandleKeyArray; and moreover (c) that there are no extra WriteHandleKeys that are not present in any vertex reco tools
48  // case (c) wouldn't necessarily break things but it's not a sign of a good configuration and thus it's forbidden as well
49  // first, get names from write handle keys
50  std::vector<std::string> listOfWHKeys;
51  for(const auto &whk : m_arrayOfWriteHandleKeys)
52  {
53  ATH_MSG_DEBUG("have WHKey "<<whk.key());
54  listOfWHKeys.push_back(whk.key());
55  }
56  unsigned int all_WHkeys=listOfWHKeys.size();
57  // remove duplicities, there shouldn't be any
58  std::sort(listOfWHKeys.begin(), listOfWHKeys.end());
59  listOfWHKeys.erase(std::unique(listOfWHKeys.begin(),listOfWHKeys.end()), listOfWHKeys.end());
60  if(listOfWHKeys.size() != all_WHkeys)
61  {
62  ATH_MSG_ERROR("It seems write handle keys do not have unique values, check settings in AFP_VertexReco/AFP_VertexReco.py. Aborting.");
63  return StatusCode::FAILURE;
64  }
65  // get names from vertex reco tools
66  std::vector<std::string> listOfOutputContainers;
67  for(const auto &recoTool : m_recoToolsList)
68  {
69  ATH_MSG_DEBUG("have ouput container "<<recoTool->outputContainerName());
70  listOfOutputContainers.push_back(recoTool->outputContainerName());
71  }
72  // remove duplicities, they are allowed
73  std::sort(listOfOutputContainers.begin(), listOfOutputContainers.end());
74  listOfOutputContainers.erase(std::unique(listOfOutputContainers.begin(),listOfOutputContainers.end()), listOfOutputContainers.end());
75  // write handle keys and names from vertex reco tools should have the same size
76  if(listOfWHKeys.size() != listOfOutputContainers.size())
77  {
78  ATH_MSG_ERROR("There is different number of unique write handle keys ("<<listOfWHKeys.size()<<") and unique output containers ("<<listOfOutputContainers.size()<<"). Aborting");
79  return StatusCode::FAILURE;
80  }
81  // check they are the same; one of these loops are not strictly neccessary, but they will print outstanding names
82  bool doAbort=false;
83  for(const auto &trkOutCont : listOfOutputContainers)
84  {
85  if(std::find(listOfWHKeys.begin(),listOfWHKeys.end(),trkOutCont) == listOfWHKeys.end())
86  {
87  ATH_MSG_ERROR("Cannot find vertex reconstruction output container "<<trkOutCont<<" in write handle keys. Aborting");
88  doAbort=true;
89  }
90  }
91  for(const auto &whk : listOfWHKeys)
92  {
93  if(std::find(listOfOutputContainers.begin(),listOfOutputContainers.end(),whk) == listOfOutputContainers.end())
94  {
95  ATH_MSG_ERROR("Cannot find write handle key "<<whk<<" in vertex reconstruction output containers. Aborting");
96  doAbort=true;
97  }
98  }
99  if(doAbort) return StatusCode::FAILURE;
100  // Now, we are sure it's setup correctly
101 
102 
103 // monitoring tool to be added soon
104  // monitoring
105 // if (!(m_monTool.name().empty())) {
106 // CHECK( m_monTool.retrieve() );
107 // ATH_MSG_DEBUG("m_monTool name: " << m_monTool);
108 // }
109 
110  return StatusCode::SUCCESS;
111 }
112 
113 StatusCode AFP_VertexRecoTool::execute(const EventContext& ctx) const
114 {
115  ATH_MSG_DEBUG("in AFP_VertexRecoTool::execute()");
116 
117 
118  for(const auto &whk : m_arrayOfWriteHandleKeys)
119  {
120  // reconstruct vertices
121  auto afpVertex=std::make_unique<xAOD::AFPVertexContainer>();
122  auto afpVertexAux=std::make_unique<xAOD::AFPVertexAuxContainer>();
123  afpVertex->setStore(afpVertexAux.get());
124 
125  for(const auto &recoTool : m_recoToolsList)
126  {
127  if(recoTool->outputContainerName() != whk.key()) continue;
128 
129  if( recoTool->doVertexReco(afpVertex, ctx).isFailure() )
130  {
131  ATH_MSG_WARNING ("Failed to reconstruct vertices with algorithm = "<<recoTool->name());
132  }
133  }
134 
135  ATH_MSG_DEBUG("write handle key "<<whk<<", have "<<afpVertex->size()<<" reconstructed vertices");
136 
137 
138  SG::WriteHandle<xAOD::AFPVertexContainer> vertexContainer(whk, ctx);
139  ATH_CHECK( vertexContainer.record(std::move(afpVertex), std::move(afpVertexAux)) );
140  }
141 
142  return StatusCode::SUCCESS;
143 }
144 
AFP_VertexRecoTool::initialize
virtual StatusCode initialize() override
Definition: AFP_VertexRecoTool.cxx:18
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
AFP_VertexRecoTool::AFP_VertexRecoTool
AFP_VertexRecoTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: AFP_VertexRecoTool.cxx:9
AFP_VertexRecoTool.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
std::unique
std::reverse_iterator< DataModel_detail::iterator< DVL > > unique(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, BinaryPredicate pred)
Specialization of unique for DataVector/List.
Definition: DVL_algorithms.h:199
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AFP_VertexRecoTool::m_recoToolsList
ToolHandleArray< IAFP_TimeRecoTool > m_recoToolsList
Vector of tool handles to be used for vertex reconstruction.
Definition: AFP_VertexRecoTool.h:48
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AFP_VertexRecoTool::execute
virtual StatusCode execute(const EventContext &ctx) const override
Run vertex reco tool.
Definition: AFP_VertexRecoTool.cxx:113
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
AFP_VertexRecoTool::m_arrayOfWriteHandleKeys
SG::WriteHandleKeyArray< xAOD::AFPVertexContainer > m_arrayOfWriteHandleKeys
Array of unique write handle keys for vertex output container.
Definition: AFP_VertexRecoTool.h:53
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78