ATLAS Offline Software
VectorFillerTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
13 #include "VectorFillerTool.h"
17 #include "GaudiKernel/Incident.h"
18 #include "GaudiKernel/IIncidentSvc.h"
19 
20 
21 namespace D3PD {
22 
23 
31  const std::string& name,
32  const IInterface* parent)
33  : base_class (type, name, parent),
34  m_getter (this),
35  m_tree (0)
36 {
37  declareProperty ("Getter", m_getter,
38  "The ICollectionGetterTool instance.");
39  declareProperty ("ObjectName", m_objectName = "",
40  "Name of the D3PDObject that created this filler.");
41  declareProperty ("AllowMissing", m_allowMissing = false,
42  "If true, then it is not considered an error for the "
43  "requested input object to be missing.");
44  declareProperty ("SaveMetadata", m_saveMetadata = false,
45  "Set to true to get metadata into the output D3PD "
46  "about the variables created by this tool");
47 }
48 
49 
55 {
57 
58  // Make sure the block fillers are initialized before the getter,
59  // so that it's more likely for the DataVector info to be available.
60  CHECK( m_getter.retrieve() );
61 
62  // Listen to the EndEvtLoop incident:
63  ServiceHandle< IIncidentSvc > p_incSvc( "IncidentSvc", name() );
64  CHECK( p_incSvc.retrieve() );
65  p_incSvc->addListener( this, "EndEvtLoop" );
66 
67  return StatusCode::SUCCESS;
68 }
69 
70 
79 {
80  CHECK( doConfigure (tree, *m_getter) );
81 
82  // Try to cast the received object into an ID3PD one:
83  m_tree = dynamic_cast< ID3PD* >( tree );
84 
85  return StatusCode::SUCCESS;
86 }
87 
88 
95 {
96  // Be sure aux variables are defined.
97  CHECK( m_getter->reset (m_allowMissing) );
98 
99  // Configure the metadata object correctly:
100  m_metadata.setName( m_objectName );
101  m_metadata.setPrefix( m_prefix );
102  m_metadata.setContainer( isContainerFiller() );
103 
104  CHECK( doBook() );
105 
106  return StatusCode::SUCCESS;
107 }
108 
109 
120 {
121  CHECK( m_getter->reset (m_allowMissing) );
122  size_t sz = m_getter->sizeHint (m_allowMissing);
123 
124  CHECK( doFill (*m_getter, sz) );
125 
126  return StatusCode::SUCCESS;
127 }
128 
129 
137 {
138  return true;
139 }
140 
141 
150 void VectorFillerTool::handle( const Incident& inc )
151 {
152  if( inc.type() == "EndEvtLoop" ) {
153  if( m_tree && m_metadata.variables().size() && m_saveMetadata ) {
154  const std::string metadata = m_metadata.toString();
155  // safe because this incident handler is only called serially
156  const std::string metadataName ATLAS_THREAD_SAFE = m_metadata.metadataName();
157  if( m_tree->addMetadata( metadataName,
158  &metadata ).isFailure() ) {
159  REPORT_MESSAGE( MSG::ERROR )
160  << "Couldn't add object metadata information to the output!";
161  return;
162  }
163  }
164  }
165 
166  return;
167 }
168 
169 
170 } // namespace D3PD
D3PD::IAddVariable
Common interface for adding a variable to a tuple.
Definition: IAddVariable.h:70
fitman.sz
sz
Definition: fitman.py:527
D3PD::VectorFillerTool::handle
virtual void handle(const Incident &inc)
Handle end of run incidents to save the metadata at that point.
Definition: VectorFillerTool.cxx:150
D3PD::ID3PD::addMetadata
virtual StatusCode addMetadata(const std::string &key, const void *obj, const std::type_info &ti)=0
Add a new piece of metadata to the tuple.
D3PD::ID3PD
Define an abstract interface for building a D3PD tree.
Definition: ID3PD.h:37
tree
TChain * tree
Definition: tile_monitor.h:30
D3PD::VectorFillerTool::configureD3PD
virtual StatusCode configureD3PD(IAddVariable *tree)
Configure the tool.
Definition: VectorFillerTool.cxx:78
D3PD::VectorFillerTool::VectorFillerTool
VectorFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: VectorFillerTool.cxx:30
D3PD::VectorFillerTool::fill
virtual StatusCode fill()
Fill one object.
Definition: VectorFillerTool.cxx:119
python.checkMetadata.metadata
metadata
Definition: checkMetadata.py:175
Monitored::detail::doFill
void doFill(H *hist, W weight, size_t i, const M &m1, const Ms &... m)
Perform (arbitrary dimension) histogram fill with weight.
Definition: HistogramFillerUtils.h:164
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
D3PD::VectorFillerToolBase::initialize
virtual StatusCode initialize()
Standard Gaudi initialize method.
Definition: VectorFillerToolBase.cxx:88
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
VectorFillerTool.h
Object filler tool for a collection of objects, saved as vectors.
D3PD::VectorFillerTool::isContainerFiller
virtual bool isContainerFiller() const
Find out if the filler handles containers or single objects.
Definition: VectorFillerTool.cxx:136
D3PD::VectorFillerTool::m_allowMissing
bool m_allowMissing
Property: If true, the input object is allowed to be missing.
Definition: VectorFillerTool.h:141
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
errorcheck.h
Helpers for checking error return status codes and reporting errors.
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
D3PD::VectorFillerTool::m_objectName
std::string m_objectName
Property: the name of the D3PDObject that created this tool.
Definition: VectorFillerTool.h:138
ID3PD.h
Abstract interface for a D3PD tree.
D3PD::VectorFillerTool::m_tree
ID3PD * m_tree
Pointer to the ID3PD object used.
Definition: VectorFillerTool.h:147
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
D3PD::VectorFillerTool::m_saveMetadata
bool m_saveMetadata
Property: If true, the metadata about the variables is saved.
Definition: VectorFillerTool.h:144
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
D3PD::VectorFillerTool::book
virtual StatusCode book()
Declare tuple variables.
Definition: VectorFillerTool.cxx:94
checker_macros.h
Define macros for attributes used to control the static checker.
D3PD::VectorFillerTool::initialize
virtual StatusCode initialize()
Standard Gaudi initialize method.
Definition: VectorFillerTool.cxx:54
D3PD::VectorFillerTool::m_getter
ToolHandle< ICollectionGetterTool > m_getter
Property: The collection getter tool.
Definition: VectorFillerTool.h:135
ServiceHandle< IIncidentSvc >