The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
AnyDataAlgorithm.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 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\***********************************************************************************/
14#include <string>
15#include <vector>
16//-----------------------------------------------------------------------------
17// Implementation file for class : AnyData{Get,Put}Algorithm
18//
19// 2016-05-26 : Roel Aaij
20//-----------------------------------------------------------------------------
28 Gaudi::Property<std::string> m_loc{ this, "Location", "Test" };
29 DataObjectWriteHandle<std::vector<int>> m_ids{ this, "Output", "/Event/Test/Ids" };
30 std::vector<DataObjectWriteHandle<int>> m_id_vec;
31
32public:
33 AnyDataPutAlgorithm( const std::string& name, ISvcLocator* pSvcLocator ) : Algorithm( name, pSvcLocator ) {
34 for ( int i = 0; i < 100; i++ ) { m_id_vec.emplace_back( "/Event/Test/Ids" + std::to_string( i ), this ); }
35 }
36
37 StatusCode execute() override {
38 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
39
40 auto i = std::make_unique<AnyDataWrapper<int>>( 0 );
41 auto j = std::make_unique<AnyDataWrapper<std::vector<int>>>( std::vector<int>{ 0, 1, 2, 3 } );
42
43 eventSvc()
44 ->registerObject( m_loc.value() + "/One", i.release() )
45 .orThrow( "failed to register " + m_loc.value() + "/One" );
46 eventSvc()
47 ->registerObject( m_loc.value() + "/Two", j.release() )
48 .orThrow( "failed to register " + m_loc.value() + "/Two" );
49
50 m_ids.put( std::vector<int>( { 42, 84 } ) );
51
52 for ( int i = 0; i < 100; ++i ) m_id_vec[i].put( std::move( i ) );
53
55 }
56};
57
58// Declaration of the Algorithm Factory
66template <class T>
69
70 DataObjectReadHandle<std::vector<int>> m_ids{ this, "Input", "/Event/Test/Ids" };
71
72public:
74
75 StatusCode execute() override {
76 if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
77
78 DataObject* tmp = nullptr;
80 auto base = dynamic_cast<AnyDataWrapperBase*>( tmp );
81 if ( base ) {
82 info() << "Got base from " << m_location.value() << endmsg;
83 } else {
84 error() << "failed to get base from " << m_location.value() << endmsg;
86 }
87 const auto i = dynamic_cast<const AnyDataWrapper<T>*>( base );
88 if ( i ) {
89 info() << "Got " << System::typeinfoName( typeid( T ) ) << " from " << m_location.value() << ": " << i->getData()
90 << endmsg;
91 }
92
93 const auto& ids = m_ids.get();
94 info() << "AnyDataHandler holds:";
95 for ( const auto& i : *ids ) info() << i << " ";
96 info() << endmsg;
98 }
99};
100
101// Declaration of the Algorithm Factory
102DECLARE_COMPONENT_WITH_ID( AnyDataGetAlgorithm<int>, "AnyDataGetAlgorithm_Int" )
103DECLARE_COMPONENT_WITH_ID( AnyDataGetAlgorithm<std::vector<int>>, "AnyDataGetAlgorithm_VectorInt" )
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT_WITH_ID(type, id)
#define DECLARE_COMPONENT(type)
StatusCode execute() override
Gaudi::Property< std::string > m_location
DataObjectReadHandle< std::vector< int > > m_ids
Gaudi::Property< std::string > m_loc
std::vector< DataObjectWriteHandle< int > > m_id_vec
DataObjectWriteHandle< std::vector< int > > m_ids
StatusCode execute() override
AnyDataPutAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
const std::string & name() const override
The identifying name of the algorithm object.
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
const StatusCode & orThrow(std::string_view message, std::string_view tag) const
Throw a GaudiException in case of failures.
Definition StatusCode.h:206
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
STL class.
@ DEBUG
Definition IMessageSvc.h:22
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition System.cpp:260
STL namespace.