The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
NTupleAlgorithm.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// Include files
12#include "NTupleAlgorithm.h"
13
17
19
20#include <math.h>
21
23
24//------------------------------------------------------------------------------
25NTupleAlgorithm::NTupleAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
26 : Algorithm( name, pSvcLocator )
27//------------------------------------------------------------------------------
28{
29 m_tuple1 = nullptr;
30 m_tuple2 = nullptr;
31}
32
33//------------------------------------------------------------------------------
35//------------------------------------------------------------------------------
36{
37 // Book N-tuple 1
38 NTuplePtr nt1( ntupleSvc(), "MyTuples/1" );
39 if ( nt1 )
40 m_tuple1 = nt1;
41 else {
42 m_tuple1 = ntupleSvc()->book( "MyTuples/1", CLID_RowWiseTuple, "Row-wise N-Tuple example" );
43 if ( m_tuple1 ) {
44 m_tuple1->addItem( "Ntrack", m_ntrk ).ignore();
45 m_tuple1->addItem( "Energy", m_energy ).ignore();
46 } else { // did not manage to book the N tuple....
47 error() << " Cannot book N-tuple:" << long( m_tuple1 ) << endmsg;
49 }
50 }
51
52 // Book N-tuple 2
53 NTuplePtr nt2( ntupleSvc(), "MyTuples/simple/2" );
54 if ( nt2 )
55 m_tuple2 = nt2;
56 else {
57 m_tuple2 = ntupleSvc()->book( "MyTuples/simple/2", CLID_ColumnWiseTuple, "Col-Wise NTuple examples" );
58 if ( m_tuple2 ) {
59 m_tuple2->addItem( "N", m_n, 0, 100 ).ignore();
60 m_tuple2->addItem( "FNumbers", m_n, m_fNumbers ).ignore();
61 m_tuple2->addItem( "INumbers", m_n, m_iNumbers ).ignore();
62 } else { // did not manage to book the N tuple....
63 error() << " Cannot book N-tuple:" << long( m_tuple2 ) << endmsg;
65 }
66 }
67 info() << "Finished booking NTuples" << endmsg;
69}
70
71//------------------------------------------------------------------------------
73//------------------------------------------------------------------------------
74{
75 StatusCode status;
76
77 static int n = 0;
78
79 m_ntrk = long( sin( double( n ) ) * 52. + 50. );
80 m_energy = float( sin( double( n ) ) * 52. + 50. );
81
82 m_n = long( abs( ( 12345 * ( n + 1 ) ) % 100 ) );
83
84 for ( int i = 0; i < m_n; i++ ) {
85 m_fNumbers[i] = float( cos( double( 2 * n ) ) * 52. + 50. );
86 m_iNumbers[i] = long( cos( double( 2 * n ) ) * 52. + 50. );
87 }
88 n++;
89
90 status = m_tuple1->write();
91 if ( status.isFailure() ) {
92 error() << " Cannot fill N-tuple:" << long( m_tuple1 ) << endmsg;
94 }
95 status = m_tuple2->write();
96 if ( status.isFailure() ) {
97 error() << " Cannot fill N-tuple:" << long( m_tuple2 ) << endmsg;
99 }
100
101 return StatusCode::SUCCESS;
102}
103
104//------------------------------------------------------------------------------
106//------------------------------------------------------------------------------
107{
108 info() << "Finalizing..." << endmsg;
109 return StatusCode::SUCCESS;
110}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
SmartDataPtr< NTuple::Tuple > NTuplePtr
Definition NTuple.h:1019
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
const std::string & name() const override
The identifying name of the algorithm object.
SmartIF< INTupleSvc > & ntupleSvc() const
The standard N tuple service.
virtual NTuple::Tuple * book(const std::string &fullPath, const CLID &type, const std::string &title)=0
Book Ntuple and register it with the data store.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
NTuple::Array< float > m_fNumbers
StatusCode finalize() override
NTuple::Array< long > m_iNumbers
NTupleAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
NTuple::Tuple * m_tuple2
StatusCode initialize() override
StatusCode execute() override
NTuple::Tuple * m_tuple1
NTuple::Item< long > m_ntrk
NTuple::Item< long > m_n
NTuple::Item< float > m_energy
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
STL namespace.