ATLAS Offline Software
AFP_GlobRecoTool.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_GlobRecoTool constructor");
15 }
16 
17 
19 {
20  ATH_MSG_DEBUG("in AFP_GlobRecoTool::initialize()");
21 
22  // proton reconstruction tools
23  if(m_recoToolsList.empty())
24  {
25  ATH_MSG_ERROR("No proton reconstruction tools set, check settings in AFP_GlobReco/AFP_GlobReco.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 proton reconstruction tools
35  if(m_arrayOfWriteHandleKeys.empty())
36  {
37  ATH_MSG_ERROR("No output proton containers provided, check settings in AFP_GlobReco/AFP_GlobReco.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 proton reco tools are also in WriteHandleKeyArray; and moreover (c) that there are no extra WriteHandleKeys that are not present in any proton 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_GlobReco/AFP_GlobReco.py. Aborting.");
63  return StatusCode::FAILURE;
64  }
65  // get names from proton 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 proton 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 proton 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 proton 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_GlobRecoTool::execute(const EventContext& ctx) const
114 {
115  ATH_MSG_DEBUG("in AFP_GlobRecoTool::execute()");
116 
117 
118  for(const auto &whk : m_arrayOfWriteHandleKeys)
119  {
120  // reconstruct protons
121  auto afpProton=std::make_unique<xAOD::AFPProtonContainer>();
122  auto afpProtonAux=std::make_unique<xAOD::AFPProtonAuxContainer>();
123  afpProton->setStore(afpProtonAux.get());
124 
125  for(const auto &recoTool : m_recoToolsList)
126  {
127  if(recoTool->outputContainerName() != whk.key()) continue;
128 
129  if( recoTool->doProtonReco(afpProton, ctx).isFailure() )
130  {
131  ATH_MSG_WARNING ("Failed to reconstruct protons with algorithm = "<<recoTool->name());
132  }
133  }
134 
135  ATH_MSG_DEBUG("write handle key "<<whk<<", have "<<afpProton->size()<<" reconstructed protons");
136 
137 
138  SG::WriteHandle<xAOD::AFPProtonContainer> protonContainer(whk, ctx);
139  ATH_CHECK( protonContainer.record(std::move(afpProton), std::move(afpProtonAux)) );
140  }
141 
142  return StatusCode::SUCCESS;
143 }
144 
AFP_GlobRecoTool::AFP_GlobRecoTool
AFP_GlobRecoTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: AFP_GlobRecoTool.cxx:9
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
AFP_GlobRecoTool::m_recoToolsList
ToolHandleArray< IAFP_ProtonRecoTool > m_recoToolsList
Vector of tool handles to be used for proton reconstruction.
Definition: AFP_GlobRecoTool.h:48
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AFP_GlobRecoTool::initialize
StatusCode initialize() override
Definition: AFP_GlobRecoTool.cxx:18
AFP_GlobRecoTool::execute
StatusCode execute(const EventContext &ctx) const override
Run proton reco tool.
Definition: AFP_GlobRecoTool.cxx:113
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_GlobRecoTool.h
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:228
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
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
AFP_GlobRecoTool::m_arrayOfWriteHandleKeys
SG::WriteHandleKeyArray< xAOD::AFPProtonContainer > m_arrayOfWriteHandleKeys
Array of unique write handle keys for track output containers.
Definition: AFP_GlobRecoTool.h:53