The Gaudi Framework  master (82fdf313)
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
15
19
20// Example related include files
21#include "MIWriteAlg.h"
22
23// Event Model related classes
26
27using namespace Gaudi::TestSuite::MultiInput;
28
30
31//--------------------------------------------------------------------
32// Initialize
33//--------------------------------------------------------------------
36 .andThen( [this]() {
37 m_evtnum = 0;
38 m_runnum = 999;
39 } )
40 .andThen( [this]() {
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
89}
HepRndm::Engine< HepJamesRandom > e6
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition Algorithm.h:175
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
void setRun(int value)
Update run number.
Definition Event.h:55
void setTime(const Gaudi::Time &value)
Update reference to event time stamp.
Definition Event.h:60
void setEvent(int value)
Update event number.
Definition Event.h:50
Gaudi::Property< std::vector< long > > m_randomSeeds
Definition MIWriteAlg.h:32
void setEvent(Event *evt)
Access to event object.
Definition MyTrack.h:101
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
virtual StatusCode setSeeds(const std::vector< long > &seeds)=0
Allow to set new seeds.
virtual IRndmEngine * engine()=0
Retrieve engine.
const key_type & insert(const value_type val, const key_type &kval)
Insert entry to the container with a valid key.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition StatusCode.h:163
constexpr static const auto SUCCESS
Definition StatusCode.h:99
WriteAlg class for the RootIOExample.
Definition WriteAlg.h:24
StatusCode initialize() override
Initialize.
Definition WriteAlg.cpp:51
StatusCode execute() override
Event callback.
Definition WriteAlg.cpp:78
KeyedContainer< MyTrack > MyTrackVector
Definition MyTrack.h:127