The Gaudi Framework
master (ff7c8557)
Toggle main menu visibility
Loading...
Searching...
No Matches
MIWriteAlg.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
// Framework include files
12
#include <
GaudiKernel/MsgStream.h
>
13
#include <
GaudiKernel/RndmGenerators.h
>
14
#include <
GaudiKernel/SmartDataPtr.h
>
15
16
#include <
GaudiKernel/IDataManagerSvc.h
>
17
#include <
GaudiKernel/IDataProviderSvc.h
>
18
#include <
GaudiKernel/IRndmEngine.h
>
19
20
// Example related include files
21
#include "
MIWriteAlg.h
"
22
23
// Event Model related classes
24
#include <
GaudiTestSuite/Event.h
>
25
#include <
GaudiTestSuite/MyTrack.h
>
26
27
using namespace
Gaudi::TestSuite::MultiInput
;
28
29
DECLARE_COMPONENT
(
WriteAlg
)
30
31
//--------------------------------------------------------------------
32
// Initialize
33
//--------------------------------------------------------------------
34
StatusCode
WriteAlg::initialize
() {
35
return
Algorithm::initialize
()
36
.
andThen
( [
this
]() {
37
m_evtnum
= 0;
38
m_runnum
= 999;
39
} )
40
.andThen( [
this
]() {
41
return
m_randomSeeds
.empty() ?
StatusCode::SUCCESS
:
randSvc
()->
engine
()->
setSeeds
(
m_randomSeeds
);
42
} );
43
}
44
45
//--------------------------------------------------------------------
46
// Execute
47
//--------------------------------------------------------------------
48
StatusCode
WriteAlg::execute
() {
49
StatusCode sc;
50
51
Rndm::Numbers rndmflat(
randSvc
(), Rndm::Flat( 0., 1. ) );
52
Rndm::Numbers rndmgauss(
randSvc
(), Rndm::Gauss( 10., 1. ) );
53
54
// Create the Event header and set it as "root" of the event store
55
Event* hdr =
new
Event();
56
hdr->
setEvent
( ++
m_evtnum
);
57
hdr->
setRun
(
m_runnum
);
58
hdr->
setTime
( Gaudi::Time( 1577836800 +
m_evtnum
,
m_evtnum
* 1
e6
) );
59
60
sc =
eventSvc
()->
registerObject
(
"Header"
, hdr );
61
if
( sc.
isFailure
() ) {
62
error
() <<
"Unable to register Event Header"
<<
endmsg
;
63
return
sc;
64
}
65
66
// Create the collection of tracks and register them in the event store
67
int
n
= (int)( rndmflat() * 100. );
68
MyTrackVector
* myTracks =
new
MyTrackVector
();
69
for
(
int
i = 0; i <
n
; ++i ) {
70
// Create new track
71
// (ensure that the order of the generated random numbers is stable)
72
double
c
= rndmgauss();
73
double
b = rndmgauss();
74
double
a = rndmgauss();
75
MyTrack* track =
new
MyTrack(
float
( a ),
float
( b ),
float
( c ) );
76
77
// set Link to header object
78
track->
setEvent
( hdr );
79
80
// And add the stuff to the container
81
myTracks->
insert
( track );
82
}
83
84
sc =
eventSvc
()->
registerObject
(
"Tracks"
, myTracks );
85
if
( sc.
isFailure
() )
return
sc;
86
87
// All done
88
return
StatusCode::SUCCESS
;
89
}
Event.h
e6
HepRndm::Engine< HepJamesRandom > e6
Definition
HepRndmEngines.cpp:210
IDataManagerSvc.h
IDataProviderSvc.h
IRndmEngine.h
MIWriteAlg.h
MsgStream.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
MyTrack.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
RndmGenerators.h
SmartDataPtr.h
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition
CommonMessaging.h:109
Gaudi::Algorithm::eventSvc
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
Definition
Algorithm.cpp:551
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition
Algorithm.h:175
Gaudi::Algorithm::randSvc
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
Definition
Algorithm.cpp:555
Gaudi::TestSuite::Event::setRun
void setRun(int value)
Update run number.
Definition
Event.h:55
Gaudi::TestSuite::Event::setTime
void setTime(const Gaudi::Time &value)
Update reference to event time stamp.
Definition
Event.h:60
Gaudi::TestSuite::Event::setEvent
void setEvent(int value)
Update event number.
Definition
Event.h:50
Gaudi::TestSuite::MultiInput::WriteAlg::m_runnum
int m_runnum
Definition
MIWriteAlg.h:31
Gaudi::TestSuite::MultiInput::WriteAlg::m_evtnum
int m_evtnum
Definition
MIWriteAlg.h:31
Gaudi::TestSuite::MultiInput::WriteAlg::m_randomSeeds
Gaudi::Property< std::vector< long > > m_randomSeeds
Definition
MIWriteAlg.h:32
Gaudi::TestSuite::MyTrack::setEvent
void setEvent(Event *evt)
Access to event object.
Definition
MyTrack.h:101
IDataProviderSvc::registerObject
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
Definition
IDataProviderSvc.h:67
IRndmEngine::setSeeds
virtual StatusCode setSeeds(const std::vector< long > &seeds)=0
Allow to set new seeds.
IRndmGenSvc::engine
virtual IRndmEngine * engine()=0
Retrieve engine.
KeyedContainer::insert
const key_type & insert(const value_type val, const key_type &kval)
Insert entry to the container with a valid key.
Definition
KeyedContainer.h:527
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isFailure
bool isFailure() const
Definition
StatusCode.h:118
StatusCode::andThen
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition
StatusCode.h:151
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
WriteAlg
WriteAlg class for the RootIOExample.
Definition
WriteAlg.h:24
WriteAlg::initialize
StatusCode initialize() override
Initialize.
Definition
WriteAlg.cpp:51
WriteAlg::execute
StatusCode execute() override
Event callback.
Definition
WriteAlg.cpp:78
Gaudi::TestSuite::MultiInput
Definition
DumpAddress.cpp:26
Gaudi::TestSuite::MyTrackVector
KeyedContainer< MyTrack > MyTrackVector
Definition
MyTrack.h:127
cpluginsvc.n
n
Definition
cpluginsvc.py:241
gaudirun.c
c
Definition
gaudirun.py:533
GaudiTestSuite
src
MultiInput
MIWriteAlg.cpp
Generated on
for The Gaudi Framework by
1.17.0