The Gaudi Framework
master (6507eef1)
Toggle main menu visibility
Loading...
Searching...
No Matches
EvtCollectionWrite.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
// ====================================================================
12
// EvtCollection.Write.cpp
13
// --------------------------------------------------------------------
14
//
15
// Author : Markus Frank
16
//
17
// ====================================================================
18
#define EVTCOLLECTION_WRITE_CPP
19
20
// Framework include files
21
#include <
GaudiKernel/INTupleSvc.h
>
22
#include <
GaudiKernel/IRegistry.h
>
23
#include <
GaudiKernel/MsgStream.h
>
24
#include <
GaudiKernel/SmartDataPtr.h
>
25
26
// Example related include files
27
#include "
EvtCollectionWrite.h
"
28
#include <
GaudiTestSuite/Event.h
>
29
#include <
GaudiTestSuite/MyTrack.h
>
30
31
#include <cmath>
32
33
using namespace
Gaudi::TestSuite
;
34
35
DECLARE_COMPONENT
(
EvtCollectionWrite
)
36
37
StatusCode
EvtCollectionWrite
::
initialize
() {
38
StatusCode
status =
m_evtTupleSvc
.retrieve();
39
if
( status.
isSuccess
() ) {
40
NTuplePtr nt( m_evtTupleSvc.get(),
"/NTUPLES/EvtColl/Dir1/Dir2/Dir3/Collection"
);
41
if ( !nt ) {
// Check if already booked
42
nt = m_evtTupleSvc->book(
"/NTUPLES/EvtColl/Dir1/Dir2/Dir3/Collection"
, CLID_ColumnWiseTuple,
"Hello World"
);
43
if ( nt ) {
44
// Add an index column
45
status = nt->addItem(
"Ntrack"
, m_ntrkColl, 0, 5000 );
46
status = nt->addItem(
"Energy"
, m_eneColl );
47
status = nt->addItem(
"Track"
, m_trackItem );
48
status = nt->addItem(
"Addr"
, m_evtAddrColl );
49
status = nt->addItem(
"TrkMom"
, m_ntrkColl, m_trkMom );
50
status = nt->addItem(
"TrkMomFix"
, 100, m_trkMomFixed );
51
status = nt->addItem(
"Address"
, m_evtAddrCollEx );
52
} else {
// did not manage to book the N tuple....
53
return StatusCode::FAILURE;
54
}
55
}
else
{
// Just reconnect to existing items
56
status = nt->item(
"Ntrack"
, m_ntrkColl );
57
status = nt->item(
"Energy"
, m_eneColl );
58
status = nt->item(
"TrkMom"
, m_trkMom );
59
status = nt->item(
"Track"
, m_trackItem );
60
status = nt->item(
"TrkMomFix"
, m_trkMomFixed );
61
status = nt->item(
"Addr"
, m_evtAddrColl );
62
status = nt->item(
"Address"
, m_evtAddrCollEx );
63
}
64
}
65
return
status;
66
}
67
68
// Event callback
69
StatusCode
EvtCollectionWrite::execute
() {
70
auto
& log =
msgStream
();
71
SmartDataPtr<DataObject>
evtRoot(
eventSvc
(),
"/Event"
);
72
SmartDataPtr<Event>
evt(
eventSvc
(),
"/Event/Header"
);
73
if
( evt ) {
74
int
evt_num = evt->event();
75
SmartDataPtr<MyTrackVector>
trkCont(
eventSvc
(),
"/Event/MyTracks"
);
76
if
( trkCont != 0 ) {
77
// Force an object update since now the original tracks should be
78
// present and the local pointers can be updated!
79
m_evtAddrCollEx
= evtRoot->registry()->address();
80
m_evtAddrColl
= evtRoot->registry()->address();
81
m_ntrkColl
= trkCont->size();
82
m_eneColl
= 0.f;
83
log <<
MSG::DEBUG
<<
" ->Track:"
;
84
for
(
size_t
j = 0; j < 100; ++j ) {
m_trkMomFixed
[j] = 0; }
85
int
cnt = 0;
86
for
(
const
auto
& i : *trkCont ) {
87
float
p = sqrt( i->px() * i->px() + i->py() * i->py() + i->pz() * i->pz() );
88
if
( cnt < 5000 )
m_trkMom
[cnt] = p;
89
if
( cnt < 5 )
m_trkMomFixed
[cnt] = p;
90
m_eneColl
+= p;
91
++cnt;
92
}
93
m_trackItem
= ( 0 ==
m_ntrkColl
) ? 0 : ( *trkCont->begin() );
94
if
( evt_num < 10 || evt_num % 500 == 0 ) {
95
log <<
endmsg
;
96
log <<
MSG::INFO
<<
"================ EVENT:"
<< evt->event() <<
" RUN:"
<< evt->run()
97
<<
" ====== N(Track)="
<<
m_ntrkColl
;
98
if
(
m_ntrkColl
<
m_nMCcut
.value() ) {
99
log <<
" FAILED selection (<"
<<
m_nMCcut
.value() <<
") ============"
<<
endmsg
;
100
}
else
{
101
log <<
" PASSED selection (>="
<<
m_nMCcut
.value() <<
") ============"
<<
endmsg
;
102
return
m_evtTupleSvc
->writeRecord(
"/NTUPLES/EvtColl/Dir1/Dir2/Dir3/Collection"
);
103
}
104
}
105
return
StatusCode::SUCCESS
;
106
}
107
}
108
error
() <<
"Unable to retrieve Event Header object"
<<
endmsg
;
109
return
StatusCode::FAILURE
;
110
}
Event.h
EvtCollectionWrite.h
INTupleSvc.h
IRegistry.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
SmartDataPtr.h
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition
CommonMessaging.h:109
CommonMessagingBase::msgStream
MsgStream & msgStream() const
Return an uninitialized MsgStream.
Definition
CommonMessaging.h:82
EvtCollectionWrite
User example objects: EvtCollectionWrite.
Definition
EvtCollectionWrite.h:43
EvtCollectionWrite::m_evtTupleSvc
ServiceHandle< INTupleSvc > m_evtTupleSvc
Definition
EvtCollectionWrite.h:54
EvtCollectionWrite::execute
StatusCode execute() override
Event callback.
Definition
EvtCollectionWrite.cpp:69
EvtCollectionWrite::m_evtAddrCollEx
NTuple::Item< IOpaqueAddress * > m_evtAddrCollEx
Definition
EvtCollectionWrite.h:53
EvtCollectionWrite::m_nMCcut
Gaudi::Property< int > m_nMCcut
Definition
EvtCollectionWrite.h:45
EvtCollectionWrite::initialize
StatusCode initialize() override
Initialize.
Definition
EvtCollectionWrite.cpp:37
EvtCollectionWrite::m_ntrkColl
NTuple::Item< int > m_ntrkColl
Definition
EvtCollectionWrite.h:47
EvtCollectionWrite::m_trkMom
NTuple::Array< float > m_trkMom
Definition
EvtCollectionWrite.h:50
EvtCollectionWrite::m_trackItem
NTuple::Item< Gaudi::TestSuite::MyTrack * > m_trackItem
Definition
EvtCollectionWrite.h:49
EvtCollectionWrite::m_evtAddrColl
NTuple::Item< IOpaqueAddress * > m_evtAddrColl
Definition
EvtCollectionWrite.h:52
EvtCollectionWrite::m_trkMomFixed
NTuple::Array< float > m_trkMomFixed
Definition
EvtCollectionWrite.h:51
EvtCollectionWrite::m_eneColl
NTuple::Item< float > m_eneColl
Definition
EvtCollectionWrite.h:48
Gaudi::Algorithm::eventSvc
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
Definition
Algorithm.cpp:551
SmartDataPtr
A small class used to access easily (and efficiently) data items residing in data stores.
Definition
SmartDataPtr.h:44
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isSuccess
bool isSuccess() const
Definition
StatusCode.h:302
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
Gaudi::TestSuite
Definition
ConditionAccessorHolder.h:21
MSG::DEBUG
@ DEBUG
Definition
IMessageSvc.h:22
MSG::INFO
@ INFO
Definition
IMessageSvc.h:22
GaudiTestSuite
src
IO
EvtCollectionWrite.cpp
Generated on
for The Gaudi Framework by
1.17.0