ATLAS Offline Software
TestRecoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <iostream>
6 #include <fstream>
10 #include "TestRecoAlg.h"
11 
12 
13 
14 namespace HLTTest {
15 
16  TestRecoAlg::TestRecoAlg( const std::string& name,
17  ISvcLocator* pSvcLocator ) :
18  ::AthAlgorithm( name, pSvcLocator )
19  {}
20 
21 
23 
24  void split(const std::string& src, char delim, std::vector<std::string>& result) {
25  std::istringstream i(src);
26  std::string element;
27  while ( getline(i, element, delim) ) {
28  result.push_back(element);
29  }
30  }
31  std::string trim(const std::string& str) {
32  size_t firstNonSpace = str.find_first_not_of(' ');
33  size_t lastNonSpace = str.find_last_not_of(' ');
34  return str.substr( firstNonSpace, lastNonSpace-firstNonSpace+1 );
35  }
36 
38  ATH_MSG_INFO ("Initializing " << name() << " reading input file " << m_fileName);
39 
40 
41  CHECK( m_output.initialize() );
42  CHECK( m_input.initialize( not m_input.key().empty() ) );
43  std::ifstream inputFile( m_fileName );
44  std::string line;
45  typedef std::vector<std::string> Split_t;
46 
47  while ( getline(inputFile, line) ) {
48  if ( line[0] == '#' ) continue;
49  Split_t objects;
50  Event_t event;
51  split( line, ';', objects );
52  for ( const auto& obj: objects ) {
53  Obj_t object;
54  Split_t properties;
55  split( obj, ',', properties );
56  for ( const auto& prop: properties ) {
57  Split_t keyval;
58  split( prop, ':', keyval );
59  if ( keyval.size() != 2 ) {
60  ATH_MSG_ERROR("Pnput format error, property specification invalid, should be a:b " << prop );
61  return StatusCode::FAILURE;
62  }
63  object.push_back( std::make_pair( trim ( keyval[0] ), std::stof(keyval[1]) ) );
64  }
65  if ( object.size() != 0 )
66  event.push_back(object);
67  }
68  m_data.push_back(event);
69  }
70  ATH_MSG_DEBUG( "Loaded " << m_data.size() << " pseudo events" );
71  if ( m_data.size() == 0 ) {
72  ATH_MSG_ERROR( "Can not run with zero pseudo events" );
73  return StatusCode::FAILURE;
74  }
75  return StatusCode::SUCCESS;
76  }
77 
79  ATH_MSG_INFO ("Finalizing " << name() << "...");
80  return StatusCode::SUCCESS;
81  }
82 
84  using namespace TrigCompositeUtils;
85  ATH_MSG_DEBUG ("Executing " << name() << "...");
86 
87  const EventContext& context = Gaudi::Hive::currentContext();
88  const size_t eventNo = context.evt() % m_data.size();
89  auto objects= m_data[eventNo];
90 
91  auto output = std::make_unique<xAOD::TrigCompositeContainer>();
92  auto aux = std::make_unique<xAOD::TrigCompositeAuxContainer>();
93  output->setStore( aux.get() );
94 
95 
96  auto inputHandle = SG::makeHandle(m_input);
97  ATH_MSG_DEBUG("Input " << m_input.key() << " has "<<inputHandle->size() <<" elements, scanning it");
98  for ( auto i: *inputHandle.cptr() ) {
99  auto featureInfo = TrigCompositeUtils::findLink<TrigRoiDescriptorCollection>( i, "initialRoI" );
100  auto roiLink = featureInfo.link;
101  CHECK( roiLink.isValid() );
102  if ( roiLink.isValid() ) {
103  auto roiPtr(roiLink.cptr());
104  ATH_MSG_DEBUG("RoI" << **roiPtr );
105  // create new outpu objects and add the properties
106  if (objects.size() > output->size()) {
107  auto object=objects[output->size()];
108  auto xobj = new xAOD::TrigComposite;
109  output->push_back( xobj );
110  // maintain link to previous collections
111  xobj->setObjectLink( "initialRoI", roiLink );// this is used by the HypoAlg
112 
113  ATH_MSG_DEBUG( "Reconstructed object" );
114  for ( const auto& prop : object ) {
115  xobj->setDetail( prop.first, prop.second );
116  ATH_MSG_DEBUG( " " << prop.first << " : " << prop.second );
117  }
118  }
119  else {
120  ATH_MSG_DEBUG( "No reco object created for this RoI because it's not found in the event");
121  }
122  } else {
123  ATH_MSG_DEBUG("RoI information missing");
124  }
125  }
126 
127 
128  ATH_MSG_DEBUG("Reconstructed "<<output->size() <<" objects");
129 
130  auto handle = SG::makeHandle(m_output);
131  CHECK( handle.record( std::move(output), std::move(aux) ) );
132 
133  return StatusCode::SUCCESS;
134  }
135 
136 } //> end namespace HLTTest
HLTTest::TestRecoAlg::m_data
std::vector< Event_t > m_data
Definition: TestRecoAlg.h:43
checkFileSG.line
line
Definition: checkFileSG.py:75
HLTTest::TestRecoAlg::Event_t
std::vector< Obj_t > Event_t
Definition: TestRecoAlg.h:42
get_generator_info.result
result
Definition: get_generator_info.py:21
HLTTest::TestRecoAlg::~TestRecoAlg
virtual ~TestRecoAlg()
Definition: TestRecoAlg.cxx:22
LArConditions2Ntuple.objects
objects
Definition: LArConditions2Ntuple.py:57
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
python.TestDriveDummies.properties
dictionary properties
Definition: TestDriveDummies.py:14
xAOD::TrigComposite
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:16
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
HLTTest::TestRecoAlg::m_output
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_output
Definition: TestRecoAlg.h:46
TrigCompositeUtils.h
HLTTest::TestRecoAlg::finalize
StatusCode finalize() override
Definition: TestRecoAlg.cxx:78
HLTTest::trim
std::string trim(const std::string &str)
Definition: TestRecoAlg.cxx:31
HLTTest::TestRecoAlg::m_input
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_input
Definition: TestRecoAlg.h:47
HLTTest::TestRecoAlg::TestRecoAlg
TestRecoAlg()
HLTTest::split
void split(const std::string &src, char delim, std::vector< std::string > &result)
Definition: TestRecoAlg.cxx:24
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
lumiFormat.i
int i
Definition: lumiFormat.py: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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
TrigCompositeAuxContainer.h
AthAlgorithm
Definition: AthAlgorithm.h:47
merge.output
output
Definition: merge.py:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
HLTTest::TestRecoAlg::initialize
StatusCode initialize() override
Definition: TestRecoAlg.cxx:37
HLTTest::TestRecoAlg::Obj_t
std::vector< Prop_t > Obj_t
Definition: TestRecoAlg.h:41
TestRecoAlg.h
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
HLTTest
Definition: ITestHypoTool.cxx:9
pickleTool.object
object
Definition: pickleTool.py:30
str
Definition: BTagTrackIpAccessor.cxx:11
python.PyAthena.obj
obj
Definition: PyAthena.py:132
TrigRoiDescriptorCollection.h
HLTTest::TestRecoAlg::execute
StatusCode execute() override
Definition: TestRecoAlg.cxx:83
HLTTest::TestRecoAlg::m_fileName
StringProperty m_fileName
Definition: TestRecoAlg.h:44