ATLAS Offline Software
Loading...
Searching...
No Matches
MultiReaderAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6// Gaudi/Athena include(s):
8
9// Local include(s):
10#include "MultiReaderAlg.h"
11#include "IReaderD3PD.h"
12
13namespace D3PD {
14
15 MultiReaderAlg::MultiReaderAlg( const std::string& name, ISvcLocator* svcloc )
16 : AthAlgorithm( name, svcloc ),
17 m_d3pdSvc( "D3PD::RootReaderD3PDSvc", name ),
18 m_tools( this ),
19 m_metadataTools( this ),
20 m_d3pds(),
21 m_booked( false ) {
22
23 declareProperty( "D3PDSvc", m_d3pdSvc,
24 "The D3PD creation service." );
25 declareProperty( "Tools", m_tools,
26 "List of IObjFillerTool instances to run." );
27 declareProperty( "MetadataTools", m_metadataTools,
28 "List of IMetadataTool instances to run." );
29 declareProperty( "TuplePath", m_tuplePath = "dummy",
30 "The name of the tuple. The interpretation of this "
31 "depends on the D3PDSvc." );
32
33 declareProperty( "Prefixes", m_prefixes,
34 "Common prefix to the D3PD variable names" );
35 declareProperty( "ClassNames", m_classnames,
36 "Name of the C++ classes to be generated" );
37
38 declareProperty( "Directory", m_dir = "./",
39 "Output directory for the generated sources" );
40 }
41
42 StatusCode MultiReaderAlg::initialize ATLAS_NOT_THREAD_SAFE () {
43
44 CHECK( m_d3pdSvc.retrieve() );
45 CHECK( m_tools.retrieve() );
46
47 // Check if the configuration looks okay:
48 if( ( m_tools.size() != m_prefixes.size() ) ||
49 ( m_tools.size() != m_classnames.size() ) ) {
50 REPORT_MESSAGE( MSG::ERROR ) << "The configuration is inconsistent: "
51 << m_tools.size() << " tools, "
52 << m_prefixes.size() << " prefixes "
53 << m_classnames.size() << " classnames";
54 return StatusCode::FAILURE;
55 }
56
57 // Create a new D3PD for each object filled tool:
58 for( size_t i = 0; i < m_tools.size(); ++i ) {
59
60 // Generate a name for the class if it doesn't have one yet:
61 if( m_classnames[ i ] == "" ) {
62 static int counter = 1;
63 std::ostringstream classname;
64 classname << "D3PDObject" << counter;
65 m_classnames[ i ] = classname.str();
66 ++counter;
67 }
68
69 ID3PD* d3pd = 0;
70 CHECK( m_d3pdSvc->make( m_tuplePath + m_classnames[ i ], d3pd ) );
71
72 ATH_MSG_DEBUG( "Creating D3PD object with name: " << m_tuplePath
73 << m_classnames[ i ] );
74
75 // Check that the service created the correct type of D3PD object:
76 IReaderD3PD* rd3pd = dynamic_cast< IReaderD3PD* >( d3pd );
77 if( ! rd3pd ) {
78 REPORT_MESSAGE( MSG::ERROR ) << "The configured service ("
79 << m_d3pdSvc << ") did not create a "
80 << "D3PD::IReaderD3PD object!";
81 return StatusCode::FAILURE;
82 }
83
84 // Configure the D3PD object:
85 rd3pd->setIsContainer( m_tools[ i ]->isContainerFiller() );
86 rd3pd->setPrefix( m_prefixes[ i ] );
87
88 // Remember this D3PD object:
89 m_d3pds.push_back( rd3pd );
90
91 }
92
93 // Configure each tool.
94 for( size_t i = 0; i < m_tools.size(); ++i ) {
95 if( m_classnames[ i ] == "" ) continue;
96 CHECK( m_tools[ i ]->configureD3PD( m_d3pds[ i ] ) );
97 }
98
99 m_booked = false;
100 return StatusCode::SUCCESS;
101 }
102
104
105 // Let the D3PD generate the source code that can read it back:
106 for( size_t i = 0; i < m_tools.size(); ++i ) {
107 if( m_classnames[ i ] == "" ) continue;
108 CHECK( m_d3pds[ i ]->createReader( m_classnames[ i ], m_dir ) );
109 }
110
111 return StatusCode::SUCCESS;
112 }
113
115
116 // Instruct all the tools to declare their variables to the D3PD object:
117 if( ! m_booked ) {
118 m_booked = true;
119 for( size_t i = 0; i < m_tools.size(); ++i ) {
120 if( m_classnames[ i ] == "" ) continue;
121 CHECK( m_tools[ i ]->book() );
122 }
123 }
124
125 return StatusCode::SUCCESS;
126 }
127
128} // namespace D3PD
#define ATH_MSG_DEBUG(x)
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
virtual void setIsContainer(bool isContainer)=0
Set the "isCollection" parameter of the object.
virtual StatusCode execute()
Standard Gaudi execute method.
ToolHandleArray< IMetadataTool > m_metadataTools
Property: List of metadata tools to run.
std::vector< IReaderD3PD * > m_d3pds
The created tuples. Note: we don't take ownership.
ServiceHandle< ID3PDSvc > m_d3pdSvc
Property: The D3PD creation service.
std::string m_dir
Directory where the sources should be put.
std::vector< std::string > m_prefixes
Variable name prefixes.
ToolHandleArray< IObjFillerTool > m_tools
Property: List of object filler tools to run.
std::vector< std::string > m_classnames
Reader class names.
std::string m_tuplePath
The D3PD base name.
bool m_booked
Flag that we've called book().
MultiReaderAlg(const std::string &name, ISvcLocator *svcloc)
Standard algorithm constructor.
virtual StatusCode finalize()
Standard Gaudi finalize method.
Block filler tool for noisy FEB information.
StatusCode DummyInitAlg::initialize ATLAS_NOT_THREAD_SAFE()
Standard Gaudi initialize method.