The Gaudi Framework  master (37c0b60a)
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>
15 
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 
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 //--------------------------------------------------------------------
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 * 1e6 ) );
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
Gaudi::TestSuite::Event::setRun
void setRun(int value)
Update run number.
Definition: Event.h:55
RndmGenerators.h
Gaudi::TestSuite::Event::setTime
void setTime(const Gaudi::Time &value)
Update reference to event time stamp.
Definition: Event.h:60
Gaudi::Algorithm::randSvc
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
Definition: Algorithm.cpp:563
StatusCode::andThen
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition: StatusCode.h:163
MyTrack.h
Gaudi::Algorithm::eventSvc
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
Definition: Algorithm.cpp:559
Gaudi::TestSuite::MultiInput::WriteAlg
Simple algorithm used to produce dummy data in the transient store.
Definition: MIWriteAlg.h:22
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:178
Gaudi::TestSuite::MyTrack
Definition: MyTrack.h:45
gaudirun.c
c
Definition: gaudirun.py:525
Rndm::Flat
Parameters for the flat random number generation within boundaries [minimum, maximum].
Definition: RndmGenerators.h:253
Gaudi::TestSuite::Event
Definition: Event.h:37
IDataProviderSvc.h
Gaudi::Time
Definition: Time.h:241
Gaudi::TestSuite::MultiInput::WriteAlg::m_evtnum
int m_evtnum
Definition: MIWriteAlg.h:32
IRndmEngine.h
Gaudi::TestSuite::MultiInput::WriteAlg::execute
StatusCode execute() override
Event callback.
Definition: MIWriteAlg.cpp:48
StatusCode
Definition: StatusCode.h:65
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:32
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator.
Definition: RndmGenerators.h:359
SmartDataPtr.h
Gaudi::TestSuite::MultiInput
Definition: DumpAddress.cpp:26
KeyedContainer
template class KeyedContainer, KeyedContainer.h
Definition: KeyedContainer.h:74
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
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:533
Gaudi::TestSuite::MyTrack::setEvent
void setEvent(Event *evt)
Access to event object.
Definition: MyTrack.h:101
cpluginsvc.n
n
Definition: cpluginsvc.py:234
MIWriteAlg.h
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::TestSuite::MyTrackVector
KeyedContainer< MyTrack > MyTrackVector
Definition: MyTrack.h:127
HepRndm::Engine
Definition: HepRndmEngine.h:35
Gaudi::TestSuite::MultiInput::WriteAlg::m_runnum
int m_runnum
Definition: MIWriteAlg.h:32
IDataManagerSvc.h
Gaudi::TestSuite::Event::setEvent
void setEvent(int value)
Update event number.
Definition: Event.h:50
MsgStream.h