| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

WriteAlg.cpp
Go to the documentation of this file.
1 // Framework include files
2 #include "GaudiKernel/SmartDataPtr.h"
3 #include "GaudiKernel/MsgStream.h"
4 #include "GaudiKernel/RndmGenerators.h"
5
6 #include "GaudiKernel/IDataProviderSvc.h"
7 #include "GaudiKernel/IDataManagerSvc.h"
8
9 // Example related include files
10 #include "WriteAlg.h"
11
12 // Event Model related classes
13 #include "Event.h"
14 #include "MyTrack.h"
15 #include "MyVertex.h"
16
17 DECLARE_COMPONENT(WriteAlg)
18
19 //--------------------------------------------------------------------
20 // Initialize
21 //--------------------------------------------------------------------
22 StatusCode WriteAlg::initialize() {
23 return StatusCode::SUCCESS;
24 }
25
26 //--------------------------------------------------------------------
27 // Execute
28 //--------------------------------------------------------------------
29 StatusCode WriteAlg::execute() {
30 StatusCode sc;
31
32 static int evtnum = 0;
33 static int runnum = 999;
34
35 Rndm::Numbers rndmflat(randSvc(), Rndm::Flat(0.,1.));
36 Rndm::Numbers rndmgauss(randSvc(), Rndm::Gauss(10.,1.));
37
38 // Create the Event header and set it as "root" of the event store
39 Event* event = new Event();
40 event->setEvent(++evtnum);
41 event->setRun(runnum);
42 event->setTime(Gaudi::Time());
43
44 auto evtmgr = eventSvc().as<IDataManagerSvc>();
45 sc = evtmgr->setRoot("/Event", event);
46 if( sc.isFailure() ) {
47 error() << "Unable to register /Event object" << endmsg;
48 return sc;
49 }
50 // Create containers
51 MyTrackVector* myTracks = new MyTrackVector();
52 MyVertexVector* myVertices = new MyVertexVector();
53 // Create the primary trackm and vector
54 MyTrack* ptrack = new MyTrack((float)rndmgauss(),(float)rndmgauss(),(float)rndmgauss());
55 MyVertex* dvertex = new MyVertex(0,0,0);
56 ptrack->setDecayVertex(dvertex);
57 ptrack->setEvent(event);
58 dvertex->setMotherTrack(ptrack);
59 myTracks->add( ptrack );
60 myVertices->add ( dvertex );
61 // loop over first decays...
62 int n = (int)(rndmflat() * 100.);
63 for( int i = 0; i < n; i++ ) {
64 // Create new track
65 MyTrack* t = new MyTrack((float)rndmgauss(),(float)rndmgauss(),(float)rndmgauss());
66 myTracks->add ( t );
67 t->setEvent(event);
68 dvertex->addDaughterTrack(t);
69 if( rndmflat() > 0.5 ) {
70 MyVertex* dv = new MyVertex(rndmflat(),rndmflat(),rndmflat()*10.);
71 myVertices->add ( dv );
72 dv->setMotherTrack(t);
73 int m = (int)(rndmflat() * 10.);
74 for( int j = 0; j < m; j++ ) {
75 MyTrack* dt = new MyTrack(t->px()/m,t->py()/m,t->pz()/m);
76 myTracks->add ( dt );
77 dt->setEvent(event);
78 dv->addDaughterTrack(dt);
79 }
80 }
81 }
82
83 sc = eventSvc()->registerObject("/Event","MyTracks",myTracks);
84 if( sc.isFailure() ) {
85 error() << "Unable to register MyTracks" << endmsg;
86 return sc;
87 }
88 sc = eventSvc()->registerObject("/Event","MyVertices",myVertices);
89 if( sc.isFailure() ) {
90 error() << "Unable to register MyVertices" << endmsg;
91 return sc;
92 }
93
94 // All done
95 info() << "Generated event " << evtnum << endmsg;
96 return StatusCode::SUCCESS;
97 }
98
99 //--------------------------------------------------------------------
100 // Finalize
101 //--------------------------------------------------------------------
102 StatusCode WriteAlg::finalize() {
103 return StatusCode::SUCCESS;
104 }
WriteAlg::finalize
virtual StatusCode finalize()
Finalize.
Definition: WriteAlg.cpp:102
AnalysisTest.initialize
def initialize()
Definition: AnalysisTest.py:12
Event
Essential information of the event used in examples It can be identified by "/Event".
Definition: Event.h:23
MsgStream.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
KeyedContainer::add
virtual long add(ContainedObject *pObject)
ObjectContainerBase overload: Add an object to the container.
Definition: KeyedContainer.h:605
MyTrack::setDecayVertex
void setDecayVertex(MyVertex *decay)
Access to event object.
Definition: MyTrack.h:89
MyVertex::setMotherTrack
void setMotherTrack(MyTrack *value)
Update pointer to mother particle (by a C++ pointer or a smart reference)
Definition: MyVertex.h:60
KeyedContainer< MyTrack >
MyTrack::py
float py() const
Accessors: Retrieve y-component of the track momentum.
Definition: MyTrack.h:49
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:21
MyTrack::setEvent
void setEvent(Event *evt)
Access to event object.
Definition: MyTrack.h:64
merge_files.sc
int sc
Definition: merge_files.py:167
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
MyTrack.h
WriteAlg::execute
virtual StatusCode execute()
Event callback.
Definition: WriteAlg.cpp:29
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator...
Definition: RndmGenerators.h:370
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:110
MyTrack
Definition: MyTrack.h:26
IDataManagerSvc.h
IDataProviderSvc.h
SmartDataPtr.h
MyVertexVector
KeyedContainer< MyVertex > MyVertexVector
Definition: MyVertex.h:95
Gaudi::Time
Based on seal::Time.
Definition: Time.h:213
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
WriteAlg.h
MyTrack::px
float px() const
Accessors: Retrieve x-component of the track momentum.
Definition: MyTrack.h:47
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:93
Rndm::Flat
Parameters for the flat random number generation within boundaries [minimum, maximum].
Definition: RndmGenerators.h:254
WriteAlg
WriteAlg class for the RootIOExample.
Definition: WriteAlg.h:14
MyVertex::addDaughterTrack
void addDaughterTrack(MyTrack *value)
Retrieve pointer to vector of daughter particles (const or non-const)
Definition: MyVertex.h:72
Event.h
MyTrack::pz
float pz() const
Accessors: Retrieve z-component of the track momentum.
Definition: MyTrack.h:51
Algorithm::randSvc
SmartIF< IRndmGenSvc > & randSvc() const
AIDA-based NTuple service Returns a pointer to the AIDATuple service if present.
RndmGenerators.h
MyVertex
Simple class that represents a vertex for testing purposes.
Definition: MyVertex.h:23
Algorithm::eventSvc
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
MyVertex.h
IDataManagerSvc
Definition: IDataManagerSvc.h:45
MyTrackVector
KeyedContainer< MyTrack > MyTrackVector
Definition: MyTrack.h:94
IDataProviderSvc::registerObject
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)=0
Register object with the data store.
ana.i
list i
Definition: ana.py:128
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244