ATLAS Offline Software
Loading...
Searching...
No Matches
ObjFillerTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12
13#include "ObjFillerTool.h"
15#include "GaudiKernel/System.h"
17#include "GaudiKernel/Incident.h"
18#include "GaudiKernel/IIncidentSvc.h"
19
20
21namespace D3PD {
22
23
31 const std::string& name,
32 const IInterface* parent)
33 : base_class (type, name, parent),
35 m_getter (this),
36 m_blockFillers (this),
37 m_tree (0)
38{
39 declareProperty ("Getter", m_getter,
40 "The IObjGetterTool instance.");
41 declareProperty ("BlockFillers", m_blockFillers,
42 "List of contained block filler tools.");
43 declareProperty ("Prefix", m_prefix = "",
44 "Variable name prefix for the contained blocks.");
45 declareProperty ("BlockName", m_blockName = this->name(),
46 "The name of this block.");
47 declareProperty ("ObjectName", m_objectName = "",
48 "Name of the D3PDObject that created this filler.");
49 declareProperty ("AllowMissing", m_allowMissing = false,
50 "If true, then it is not considered an error for the "
51 "requested input object to be missing.");
52 declareProperty ("SaveMetadata", m_saveMetadata = false,
53 "Set to true to get metadata into the output D3PD "
54 "about the variables created by this tool");
55}
56
57
61StatusCode
63{
64 CHECK( AthAlgTool::initialize() );
65 CHECK( m_getter.retrieve() );
66 CHECK( m_blockFillers.retrieve() );
67
68 // Listen to EndEvent and EndRun incidents:
69 ServiceHandle< IIncidentSvc > p_incSvc( "IncidentSvc", name() );
70 CHECK( p_incSvc.retrieve() );
71 p_incSvc->addListener( this, "EndEvtLoop" );
72
73 return StatusCode::SUCCESS;
74}
75
76
83StatusCode
85{
86 // The type that the getter will provide.
87 const std::type_info& ti = m_getter->typeinfo();
88
90 for (size_t i = 0; i < m_blockFillers.size(); i++)
91 CHECK( m_blockFillers[i]->configureD3PD (this, ti) );
92
93 // Try to cast the received object into an ID3PD one:
94 m_tree = dynamic_cast< ID3PD* >( tree );
95
96 return StatusCode::SUCCESS;
97}
98
99
106{
107 // Be sure aux variables are defined.
108 (void)m_getter->getUntyped (m_allowMissing);
109
110 // Configure the metadata object correctly:
111 m_metadata.setPrefix( m_prefix );
112 m_metadata.setName( m_objectName );
113 m_metadata.setContainer( isContainerFiller() );
114
115 for (size_t i = 0; i < m_blockFillers.size(); i++)
116 CHECK( m_blockFillers[i]->book() );
117
118 return StatusCode::SUCCESS;
119}
120
121
130StatusCode
132{
133 const void* obj = m_getter->getUntyped (m_allowMissing);
134 if (!obj) {
135 if (m_allowMissing)
136 return StatusCode::SUCCESS;
137 REPORT_MESSAGE(MSG::ERROR) << "Can't get input object.";
138 return StatusCode::FAILURE;
139 }
140
141 for (size_t i = 0; i < m_blockFillers.size(); i++)
142 CHECK( m_blockFillers[i]->fillUntyped (obj) );
143
144 m_getter->releaseObjectUntyped (obj);
145
146 return StatusCode::SUCCESS;
147}
148
149
157{
158 return false;
159}
160
161
170void ObjFillerTool::handle( const Incident& inc )
171{
172 if( inc.type() == "EndEvtLoop" ) {
173 if( m_tree && m_metadata.variables().size() && m_saveMetadata ) {
174 const std::string metadata = m_metadata.toString();
175 // safe because this incident handler is only called serially
176 const std::string metadataName ATLAS_THREAD_SAFE = m_metadata.metadataName();
177 if( m_tree->addMetadata( metadataName,
178 &metadata ).isFailure() ) {
179 REPORT_MESSAGE( MSG::ERROR )
180 << "Couldn't add object metadata information to the output!";
181 return;
182 }
183 }
184 }
185
186 return;
187}
188
189
190} // namespace D3PD
191
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
Abstract interface for a D3PD tree.
Object filler tool for a single object.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
StatusCode configureD3PD(IAddVariable *tree)
Configure the parent tree.
AddVariable(const std::string &prefix, const std::string &blockName=s_emptyString)
Constructor.
ObjectMetadata m_metadata
Metadata about the variables created by this object.
Common interface for adding a variable to a tuple.
Define an abstract interface for building a D3PD tree.
Definition ID3PD.h:37
virtual bool isContainerFiller() const
Find out if the filler handles containers or single objects.
virtual StatusCode initialize()
Standard Gaudi initialize method.
ToolHandle< IObjGetterTool > m_getter
Property: The object getter tool.
bool m_allowMissing
Property: If true, the input object is allowed to be missing.
std::string m_blockName
Property: the name of this block.
virtual void handle(const Incident &inc)
Handle end of run incidents to save the metadata at that point.
virtual StatusCode configureD3PD(IAddVariable *tree)
Configure the tool.
std::string m_objectName
Property: the name of the D3PDObject that created this tool.
virtual StatusCode book()
Declare tuple variables.
virtual StatusCode fill()
Fill one object.
std::string m_prefix
Property: Variable prefix for this block.
ID3PD * m_tree
Pointer to the ID3PD object used.
bool m_saveMetadata
Property: If true, the metadata about the variables is saved.
ObjFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
ToolHandleArray< IBlockFillerTool > m_blockFillers
Property: The list of block filler tools.
Block filler tool for noisy FEB information.
TChain * tree