The Gaudi Framework  v36r1 (3e2fb5a8)
FetchLeavesFromFile.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
12 #include "GaudiAlg/Producer.h"
13 #include "GaudiKernel/DataObject.h"
18 #include "GaudiKernel/IRegistry.h"
19 #include "GaudiKernel/SmartIF.h"
20 
21 namespace Gaudi {
22  namespace Hive {
23  class FetchLeavesFromFile final : public Gaudi::Functional::Producer<IDataStoreLeaves::LeavesList()> {
24  public:
26  : Producer( name, pSvcLocator, KeyValue( "InputFileLeavesLocation", "/Event/InputFileLeaves" ) ) {}
27 
28  StatusCode initialize() override;
29 
31 
32  StatusCode finalize() override {
34  return Algorithm::finalize();
35  }
36 
37  // Scan the data service starting from the node specified as \b Root.
39 
40  // Scan the data service starting from the specified node.
41  template <typename OutputIterator>
42  void i_collectLeaves( const IRegistry& reg, OutputIterator iter ) const;
43 
44  // Return the pointer to the IRegistry object associated to the node
45  // specified as \b Root.
46  const IRegistry& i_getRootNode() const;
47 
48  private:
49  Gaudi::Property<std::string> m_dataSvcName{this, "DataService", "EventDataSvc",
50  "Name of the data service to use"};
51 
52  Gaudi::Property<std::string> m_rootNode{this, "Root", "", "Path to the element from which to start the scan"};
53 
54  // Pointer to the IDataManagerSvc interface of the data service.
56  };
57 
58  // implementation
59 
62  if ( sc ) {
63  m_dataMgrSvc = serviceLocator()->service( m_dataSvcName );
64  if ( !m_dataMgrSvc ) {
65  error() << "Cannot get IDataManagerSvc " << m_dataSvcName << endmsg;
66  return StatusCode::FAILURE;
67  }
68  }
69  return sc;
70  }
71 
73  DataObject* obj = nullptr;
74  StatusCode sc = Gaudi::Algorithm::evtSvc()->retrieveObject( m_rootNode.value(), obj );
75  if ( sc.isFailure() ) {
76  throw GaudiException( "Cannot get " + m_rootNode + " from " + m_dataSvcName, name(), StatusCode::FAILURE );
77  }
78  return *obj->registry();
79  }
80 
84  return all_leaves;
85  }
86 
87  template <typename OutputIterator>
88  void FetchLeavesFromFile::i_collectLeaves( const IRegistry& reg, OutputIterator iter ) const {
89  // create a LeavesList to save all the leaves
90  IOpaqueAddress* addr = reg.address();
91  if ( addr ) { // we consider only objects that are in a file
92  if ( msgLevel( MSG::VERBOSE ) ) verbose() << "::i_collectLeaves added " << reg.identifier() << endmsg;
93  *iter = reg.object(); // add this object
94  // Origin of the current object
95  const std::string& base = addr->par()[0];
96 
97  std::vector<IRegistry*> lfs; // leaves of the current object
98  StatusCode sc = m_dataMgrSvc->objectLeaves( &reg, lfs );
99  if ( sc.isSuccess() ) {
100  for ( const auto& i : lfs ) {
101  // Continue if the leaf has the same database as the parent
102  if ( i->address() && i->address()->par()[0] == base ) {
103  DataObject* obj = nullptr;
104  // append leaves to all leaves
106  ->retrieveObject( const_cast<IRegistry*>( &reg ), i->name(), obj )
107  .andThen( [&] { i_collectLeaves( *i, iter ); } )
108  .orElse( [&] {
109  throw GaudiException( "Cannot get " + i->identifier() + " from " + m_dataSvcName, name(),
111  } )
112  .ignore();
113  }
114  }
115  }
116  }
117  }
118 
119  } // namespace Hive
120 } // namespace Gaudi
121 
Gaudi::Hive::FetchLeavesFromFile::m_dataSvcName
Gaudi::Property< std::string > m_dataSvcName
Definition: FetchLeavesFromFile.cpp:49
IDataStoreLeaves.h
std::string
STL class.
IOpaqueAddress::par
virtual const std::string * par() const =0
Retrieve String parameters.
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:355
IOpaqueAddress
Definition: IOpaqueAddress.h:33
std::vector< DataObject * >
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:96
ISvcLocator
Definition: ISvcLocator.h:46
std::back_inserter
T back_inserter(T... args)
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:178
GaudiException
Definition: GaudiException.h:31
Gaudi::Hive::FetchLeavesFromFile::FetchLeavesFromFile
FetchLeavesFromFile(const std::string &name, ISvcLocator *pSvcLocator)
Definition: FetchLeavesFromFile.cpp:25
IRegistry
Definition: IRegistry.h:32
IDataProviderSvc.h
SmartIF.h
IRegistry::name
virtual const name_type & name() const =0
Name of the directory (or key)
Gaudi::Hive::FetchLeavesFromFile::i_collectLeaves
IDataStoreLeaves::LeavesList i_collectLeaves() const
Definition: FetchLeavesFromFile.cpp:81
TimingHistograms.name
name
Definition: TimingHistograms.py:23
StatusCode
Definition: StatusCode.h:65
Gaudi::Functional::Producer
details::Producer< Signature, Traits_, details::isLegacy< Traits_ > > Producer
Definition: Producer.h:37
IOpaqueAddress.h
Gaudi::Hive::FetchLeavesFromFile::i_getRootNode
const IRegistry & i_getRootNode() const
Definition: FetchLeavesFromFile.cpp:72
Producer.h
Gaudi::Property::value
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:240
Gaudi::Hive::FetchLeavesFromFile::finalize
StatusCode finalize() override
Definition: FetchLeavesFromFile.cpp:32
SmartIF< IDataManagerSvc >
Gaudi::Functional::details::Producer
Definition: Producer.h:22
genconfuser.verbose
verbose
Definition: genconfuser.py:29
Gaudi::Hive::FetchLeavesFromFile
Definition: FetchLeavesFromFile.cpp:23
Gaudi::Hive::FetchLeavesFromFile::m_rootNode
Gaudi::Property< std::string > m_rootNode
Definition: FetchLeavesFromFile.cpp:52
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
IRegistry.h
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Hive::FetchLeavesFromFile::operator()
IDataStoreLeaves::LeavesList operator()() const override
Definition: FetchLeavesFromFile.cpp:30
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:142
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:184
MSG::VERBOSE
@ VERBOSE
Definition: IMessageSvc.h:25
Gaudi::Algorithm::evtSvc
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition: Algorithm.h:248
DataObject.h
GaudiAlgorithm.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
IRegistry::object
virtual DataObject * object() const =0
Retrieve object behind the link.
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
DataObject
Definition: DataObject.h:40
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:82
Gaudi::Hive::FetchLeavesFromFile::initialize
StatusCode initialize() override
Definition: FetchLeavesFromFile.cpp:60
Gaudi::Property< std::string >
IDataManagerSvc.h
Gaudi::Hive::FetchLeavesFromFile::m_dataMgrSvc
SmartIF< IDataManagerSvc > m_dataMgrSvc
Definition: FetchLeavesFromFile.cpp:55