The Gaudi Framework
master (37c0b60a)
ExamplesHandleAlgs.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
\***********************************************************************************/
11
#include <
GaudiExamples/Counter.h
>
12
#include <
GaudiExamples/Event.h
>
13
#include <
GaudiExamples/MyTrack.h
>
14
#include <
GaudiKernel/Algorithm.h
>
15
#include <
GaudiKernel/DataObjectHandle.h
>
16
#include <
GaudiKernel/IDataManagerSvc.h
>
17
#include <
GaudiKernel/IDataProviderSvc.h
>
18
#include <
GaudiKernel/ThreadLocalContext.h
>
19
#include <
GaudiTestSuite/Counter.h
>
20
#include <
GaudiTestSuite/Event.h
>
21
#include <
GaudiTestSuite/MyTrack.h
>
22
23
using namespace
Gaudi::Examples
;
24
25
class
ReadHandleAlg
:
public
::Algorithm
{
26
DataObjectReadHandle<Collision>
m_inputHandle{
this
,
"Input"
,
"/Event/MyCollision"
};
27
28
public
:
29
ReadHandleAlg
(
const
std::string
&
n
,
ISvcLocator
*
l
) :
Algorithm
(
n
,
l
) {}
30
31
bool
isClonable
()
const override
{
return
true
; }
32
33
StatusCode
execute
()
override
{
34
35
Collision
*
c
= m_inputHandle.get();
36
37
const
int
evtNum =
Gaudi::Hive::currentContext
().
evt
();
38
39
info() <<
"Event "
<< evtNum <<
" Collision number "
<<
c
->collision() <<
endmsg
;
40
41
return
StatusCode::SUCCESS
;
42
}
43
};
44
DECLARE_COMPONENT
(
ReadHandleAlg
)
45
46
class
WriteHandleAlg
: public ::
Algorithm
{
47
public
:
48
WriteHandleAlg
(
const
std::string
&
n
,
ISvcLocator
*
l
) :
Algorithm
(
n
,
l
) {}
49
50
bool
isClonable
()
const override
{
return
true
; }
51
52
StatusCode
execute
()
override
{
53
info() <<
"Hello, I am executing"
<<
endmsg
;
54
55
// Set collision to the current event number from the context;
56
// if the context doesn't exist, set it to some dummy value
57
// this fallback allows to stay compatible with non-hive infrastructure
58
auto
c
= std::make_unique<Collision>(
Gaudi::Hive::currentContext
().
evt
() );
59
60
if
( m_useHandle ) {
61
m_output_handle.put(
std::move
(
c
) );
62
return
StatusCode::SUCCESS
;
63
}
else
{
64
return
eventSvc()->registerObject(
"/Event"
,
"MyCollision"
,
c
.release() );
65
}
66
}
67
68
private
:
69
Gaudi::Property<bool>
m_useHandle{
this
,
"UseHandle"
,
true
,
"Specify the usage of the handle to write"
};
70
71
DataObjectWriteHandle<Collision>
m_output_handle{
this
,
"Output"
,
"/Event/MyCollision"
};
72
};
73
74
DECLARE_COMPONENT
(
WriteHandleAlg
)
IOTest.evt
evt
Definition:
IOTest.py:107
Event.h
DataObjectWriteHandle< Collision >
std::string
STL class.
Counter.h
std::move
T move(T... args)
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition:
ThreadLocalContext.cpp:30
MyTrack.h
ISvcLocator
Definition:
ISvcLocator.h:46
Algorithm
Alias for backward compatibility.
Definition:
Algorithm.h:58
Algorithm.h
ReadHandleAlg
Definition:
ExamplesHandleAlgs.cpp:25
gaudirun.c
c
Definition:
gaudirun.py:525
class
#define class
Definition:
HistogramPersistencySvc.cpp:54
MyTrack.h
IDataProviderSvc.h
WriteHandleAlg::isClonable
bool isClonable() const override
Definition:
ExamplesHandleAlgs.cpp:50
Gaudi::Examples
Definition:
Collision.h:20
StatusCode
Definition:
StatusCode.h:65
ReadHandleAlg::execute
StatusCode execute() override
Definition:
ExamplesHandleAlgs.cpp:33
DataObjectReadHandle< Collision >
Gaudi::Examples::Collision
Definition:
Collision.h:28
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition:
MsgStream.h:202
Event.h
cpluginsvc.n
n
Definition:
cpluginsvc.py:234
ReadHandleAlg::isClonable
bool isClonable() const override
Definition:
ExamplesHandleAlgs.cpp:31
WriteHandleAlg
Definition:
ExamplesHandleAlgs.cpp:46
WriteHandleAlg::WriteHandleAlg
WriteHandleAlg(const std::string &n, ISvcLocator *l)
Definition:
ExamplesHandleAlgs.cpp:48
ThreadLocalContext.h
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition:
StatusCode.h:100
gaudirun.l
dictionary l
Definition:
gaudirun.py:583
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition:
PluginServiceV1.h:46
ReadHandleAlg::ReadHandleAlg
ReadHandleAlg(const std::string &n, ISvcLocator *l)
Definition:
ExamplesHandleAlgs.cpp:29
WriteHandleAlg::execute
StatusCode execute() override
Definition:
ExamplesHandleAlgs.cpp:52
DataObjectHandle.h
EventContext::evt
ContextEvt_t evt() const
Definition:
EventContext.h:50
Gaudi::Property< bool >
IDataManagerSvc.h
Counter.h
GaudiTestSuite
src
IO
ExamplesHandleAlgs.cpp
Generated on Thu Dec 19 2024 15:35:07 for The Gaudi Framework by
1.8.18