The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
FetchLeavesFromFile.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2023 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\***********************************************************************************/
18#include <GaudiKernel/SmartIF.h>
19#include <fmt/format.h>
20
21namespace Gaudi {
22 namespace Hive {
23 class FetchLeavesFromFile final : public Gaudi::Functional::Producer<IDataStoreLeaves::LeavesList()> {
24 public:
25 FetchLeavesFromFile( const std::string& name, ISvcLocator* pSvcLocator )
26 : Producer( name, pSvcLocator, KeyValue( "InputFileLeavesLocation", "/Event/InputFileLeaves" ) ) {}
27
28 StatusCode initialize() override;
29
31
32 StatusCode finalize() override {
33 m_dataMgrSvc.reset();
34 return Producer::finalize();
35 }
36
37 // Scan the data service starting from the node specified as \b Root.
39
40 private:
41 Gaudi::Property<std::string> m_dataSvcName{ this, "DataService", "EventDataSvc",
42 "Name of the data service to use" };
43
44 Gaudi::Property<std::string> m_rootNode{ this, "Root", "", "Path to the element from which to start the scan" };
45
46 // Pointer to the IDataManagerSvc interface of the data service.
48 };
49
50 // implementation
51
53 return Producer::initialize().andThen( [&]() {
54 m_dataMgrSvc = serviceLocator()->service( m_dataSvcName );
55 if ( !m_dataMgrSvc ) {
56 error() << "Cannot get IDataManagerSvc " << m_dataSvcName << endmsg;
58 }
60 } );
61 }
62
64 // we have to make sure that the node we start the traversal from is loaded
65 {
66 DataObject* obj = nullptr;
67 evtSvc()
68 ->retrieveObject( m_rootNode, obj )
69 .orThrow( fmt::format( "failed to retrieve {} from {}", m_rootNode.value(), m_dataSvcName.value() ),
70 name() );
71 }
72 // result
74 // used to test for nodes with same origin
75 std::string origin;
76 // we do not get info from exceptions in the data store agent, so we record the exception message, if any
77 std::string failure_msg;
79 ->traverseSubTree( m_rootNode,
80 [&]( IRegistry* reg, int ) {
81 if ( reg->address() && reg->dataSvc() ) { // we consider only objects that come from a
82 // file
83 if ( origin.empty() ) {
84 // this is the first node we encounter, so we record where it comes from
85 origin = reg->address()->par()[0];
86 }
87 // if the current object comes from the same file as the first entry...
88 if ( origin == reg->address()->par()[0] ) {
89 // ... make sure the object has been loaded...
90 DataObject* obj = reg->object();
91 if ( !obj )
92 reg->dataSvc()
93 ->retrieveObject( reg->identifier(), obj )
94 .orElse( [&]() {
95 failure_msg = fmt::format( "failed to retrieve {} from {}",
96 reg->identifier(), m_dataSvcName.value() );
97 // we do not really care about the exception we throw because traverseSubTree
98 // will just use it to abort the traversal
99 throw GaudiException( failure_msg, name(), StatusCode::FAILURE );
100 } )
101 .ignore();
102 // ... and add it to the list
103 all_leaves.push_back( obj );
104 if ( msgLevel( MSG::VERBOSE ) )
105 verbose() << "::i_collectLeaves added " << reg->identifier() << endmsg;
106 return true; // we can continue the recursion
107 }
108 }
109 // if we reach this point the object was not interesting, so no need to recurse further
110 return false;
111 } )
112 .orThrow( failure_msg, name() );
113 return all_leaves;
114 }
115
116 } // namespace Hive
117} // namespace Gaudi
118
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
SmartIF< IDataManagerSvc > m_dataMgrSvc
IDataStoreLeaves::LeavesList i_collectLeaves() const
Gaudi::Property< std::string > m_dataSvcName
Gaudi::Property< std::string > m_rootNode
FetchLeavesFromFile(const std::string &name, ISvcLocator *pSvcLocator)
IDataStoreLeaves::LeavesList operator()() const override
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
Define general base for Gaudi exception.
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
std::vector< DataObject * > LeavesList
Returned type.
virtual const std::string * par() const =0
Retrieve String parameters.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition IRegistry.h:29
virtual const id_type & identifier() const =0
Full identifier (or key)
virtual DataObject * object() const =0
Retrieve object behind the link.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
StatusCode orElse(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a failure result.
Definition StatusCode.h:185
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition StatusCode.h:163
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
details::Producer< Signature, Traits_, details::isLegacy< Traits_ > > Producer
Definition Producer.h:37
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
@ VERBOSE
Definition IMessageSvc.h:22