The Gaudi Framework  v36r7 (7f57a304)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AnyDataAlgorithm.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 \***********************************************************************************/
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" };
31 
32 public:
33  AnyDataPutAlgorithm( const std::string& name, ISvcLocator* pSvcLocator ) : GaudiAlgorithm( 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  put( std::move( i ), m_loc + "/One" );
44  put( std::move( j ), m_loc + "/Two" );
45 
46  m_ids.put( std::vector<int>( { 42, 84 } ) );
47 
48  for ( int i = 0; i < 100; ++i ) m_id_vec[i].put( std::move( i ) );
49 
50  return StatusCode::SUCCESS;
51  }
52 };
53 
54 // Declaration of the Algorithm Factory
62 template <class T>
65 
66  DataObjectReadHandle<std::vector<int>> m_ids{ this, "Input", "/Event/Test/Ids" };
67 
68 public:
70 
71  StatusCode execute() override {
72  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
73 
74  auto base = getIfExists<AnyDataWrapperBase>( m_location );
75  if ( base ) { info() << "Got base from " << m_location.value() << endmsg; }
76  const auto i = dynamic_cast<const AnyDataWrapper<T>*>( base );
77  if ( i ) {
78  info() << "Got " << System::typeinfoName( typeid( T ) ) << " from " << m_location.value() << ": " << i->getData()
79  << endmsg;
80  }
81 
82  const auto& ids = m_ids.get();
83  info() << "AnyDataHandler holds:";
84  for ( const auto& i : *ids ) info() << i << " ";
85  info() << endmsg;
86  return StatusCode::SUCCESS;
87  }
88 };
89 
90 // Declaration of the Algorithm Factory
91 DECLARE_COMPONENT_WITH_ID( AnyDataGetAlgorithm<int>, "AnyDataGetAlgorithm_Int" )
92 DECLARE_COMPONENT_WITH_ID( AnyDataGetAlgorithm<std::vector<int>>, "AnyDataGetAlgorithm_VectorInt" )
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
DataObjectWriteHandle
Definition: DataObjectHandle.h:427
AnyDataGetAlgorithm::m_ids
DataObjectReadHandle< std::vector< int > > m_ids
Definition: AnyDataAlgorithm.cpp:66
std::string
STL class.
GaudiAlgorithm::GaudiAlgorithm
GaudiAlgorithm(std::string name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition: GaudiAlgorithm.cpp:45
AnyDataWrapper.h
std::move
T move(T... args)
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:542
std::vector
STL class.
ISvcLocator
Definition: ISvcLocator.h:46
AnyDataPutAlgorithm::m_ids
DataObjectWriteHandle< std::vector< int > > m_ids
Definition: AnyDataAlgorithm.cpp:29
AnyDataPutAlgorithm
Definition: AnyDataAlgorithm.cpp:27
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:308
AnyDataPutAlgorithm::AnyDataPutAlgorithm
AnyDataPutAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: AnyDataAlgorithm.cpp:33
CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:148
DECLARE_COMPONENT_WITH_ID
#define DECLARE_COMPONENT_WITH_ID(type, id)
Definition: PluginServiceV1.h:47
DataObjectHandle::get
T * get() const
Retrieve object from transient data store.
Definition: DataObjectHandle.h:113
StatusCode
Definition: StatusCode.h:65
GaudiAlgorithm::put
void put(IDataProviderSvc *svc, DataObject *object, const std::string &address, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
Definition: GaudiAlgorithm.h:175
GaudiAlgorithm
Definition: GaudiAlgorithm.h:104
DataObjectReadHandle
Definition: DataObjectHandle.h:405
Gaudi::Property::value
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:240
std::to_string
T to_string(T... args)
AnyDataGetAlgorithm::execute
StatusCode execute() override
standard execution method
Definition: AnyDataAlgorithm.cpp:71
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
AnyDataWrapper
Definition: AnyDataWrapper.h:34
Containers::vector
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
Definition: KeyedObjectManager.h:39
std::vector::emplace_back
T emplace_back(T... args)
DataObjectHandle::put
T * put(std::unique_ptr< T > object) const
Register object in transient store.
Definition: DataObjectHandle.h:176
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
GaudiAlgorithm.h
AnyDataPutAlgorithm::m_id_vec
std::vector< DataObjectWriteHandle< int > > m_id_vec
Definition: AnyDataAlgorithm.cpp:30
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
AnyDataPutAlgorithm::execute
StatusCode execute() override
standard execution method
Definition: AnyDataAlgorithm.cpp:37
AnyDataPutAlgorithm::m_loc
Gaudi::Property< std::string > m_loc
Definition: AnyDataAlgorithm.cpp:28
AnyDataGetAlgorithm::m_location
Gaudi::Property< std::string > m_location
Definition: AnyDataAlgorithm.cpp:64
DataObjectHandle.h
Gaudi::Property< std::string >
AnyDataGetAlgorithm
Definition: AnyDataAlgorithm.cpp:63