ATLAS Offline Software
Loading...
Searching...
No Matches
ReaderAlg.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
6// Gaudi/Athena include(s):
8
9// Local include(s):
10#include "ReaderAlg.h"
11#include "IReaderD3PD.h"
12
13namespace D3PD {
14
15 ReaderAlg::ReaderAlg( const std::string& name, ISvcLocator* svcloc )
16 : AthAlgorithm( name, svcloc ),
17 m_d3pdSvc( "D3PD::RootReaderD3PDSvc", name ),
18 m_tools( this ),
19 m_d3pd( 0 ),
20 m_booked( false ) {
21
22 declareProperty( "D3PDSvc", m_d3pdSvc,
23 "The D3PD creation service." );
24 declareProperty( "Tools", m_tools,
25 "List of IObjFillerTool instances to run." );
26 declareProperty( "TuplePath", m_tuplePath = "dummy",
27 "The name of the tuple. The interpretation of this "
28 "depends on the D3PDSvc." );
29
30 declareProperty( "Prefix", m_prefix = "",
31 "Common prefix to the D3PD variable names" );
32
33 declareProperty( "Directory", m_dir = "./",
34 "Output directory for the generated sources" );
35 declareProperty( "ClassName", m_classname = "Dummy",
36 "Name of the C++ class to be generated" );
37 }
38
39 StatusCode ReaderAlg::initialize() {
40
41 CHECK( m_d3pdSvc.retrieve() );
42 CHECK( m_tools.retrieve() );
43
44 // Create a new D3PD:
45 ID3PD* d3pd = 0;
46 CHECK( m_d3pdSvc->make( m_tuplePath, d3pd ) );
47
48 // Check that the service created the correct type of D3PD object:
49 m_d3pd = dynamic_cast< IReaderD3PD* >( d3pd );
50 if( ! m_d3pd ) {
51 REPORT_MESSAGE( MSG::ERROR ) << "The configured service ("
52 << m_d3pdSvc << ") did not create a "
53 << "D3PD::IReaderD3PD object!";
54 return StatusCode::FAILURE;
55 }
56
57 // Configure the object:
58 m_d3pd->setPrefix( m_prefix );
59
60 // Configure each tool.
61 for( size_t i = 0; i < m_tools.size(); ++i ) {
62 CHECK( m_tools[ i ]->configureD3PD( m_d3pd ) );
63 }
64
65 m_booked = false;
66 return StatusCode::SUCCESS;
67 }
68
69 StatusCode ReaderAlg::finalize() {
70
71 // Let the D3PD generate the source code that can read it back:
72 CHECK( m_d3pd->createReader( m_classname, m_dir ) );
73
74 return StatusCode::SUCCESS;
75 }
76
77 StatusCode ReaderAlg::execute() {
78
79 // Instruct all the tools to declare their variables to the D3PD object:
80 if( ! m_booked ) {
81 m_booked = true;
82 for( size_t i = 0; i < m_tools.size(); ++i ) {
83 CHECK( m_tools[ i ]->book() );
84 }
85 }
86
87 return StatusCode::SUCCESS;
88 }
89
90} // namespace D3PD
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Define an abstract interface for building a D3PD tree.
Definition ID3PD.h:37
Common interface for the code generator D3PD classes.
Definition IReaderD3PD.h:29
ServiceHandle< ID3PDSvc > m_d3pdSvc
Property: The D3PD creation service.
Definition ReaderAlg.h:59
virtual StatusCode finalize()
Standard Gaudi finalize method.
Definition ReaderAlg.cxx:69
std::string m_dir
Directory where the sources should be put.
Definition ReaderAlg.h:68
IReaderD3PD * m_d3pd
The created tuple. Note: we don't take ownership.
Definition ReaderAlg.h:72
std::string m_classname
Name of the generated class.
Definition ReaderAlg.h:69
std::string m_prefix
Common variable name prefix.
Definition ReaderAlg.h:66
ToolHandleArray< IObjFillerTool > m_tools
Property: List of object filler tools to run.
Definition ReaderAlg.h:61
virtual StatusCode execute()
Standard Gaudi execute method.
Definition ReaderAlg.cxx:77
virtual StatusCode initialize()
Standard Gaudi initialize method.
Definition ReaderAlg.cxx:39
ReaderAlg(const std::string &name, ISvcLocator *svcloc)
Standard algorithm constructor.
Definition ReaderAlg.cxx:15
std::string m_tuplePath
Property: The tuple name.
Definition ReaderAlg.h:64
bool m_booked
Flag that we've called book().
Definition ReaderAlg.h:74
Block filler tool for noisy FEB information.