The Gaudi Framework  v38r0 (2143aa4c)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
EvtColAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 // Include files
13 // ============================================================================
14 // GaudiKernel
15 // ============================================================================
16 #include "GaudiKernel/DataObject.h"
17 #include "GaudiKernel/INTupleSvc.h"
19 #include "GaudiKernel/IRegistry.h"
22 // ============================================================================
23 // GaudiAlg
24 // ============================================================================
25 #include "GaudiAlg/GaudiTupleAlg.h"
26 #include "GaudiAlg/Tuple.h"
27 #include "GaudiAlg/TupleID.h"
28 #include "GaudiAlg/Tuples.h"
29 // ============================================================================
38 // ============================================================================
39 namespace Gaudi {
40  namespace Examples {
48  // ========================================================================
49  class EvtColAlg : public GaudiTupleAlg {
50  public:
51  StatusCode initialize() override {
53  if ( sc.isFailure() ) { return sc; }
54  // check for random numbers service
55  Assert( randSvc() != 0, "Random Service is not available!" );
56  //
57  return StatusCode::SUCCESS;
58  };
60  StatusCode execute() override;
65  EvtColAlg( const std::string& name, ISvcLocator* pSvc ) : GaudiTupleAlg( name, pSvc ) {
67  setProperty( "NTupleProduce", false ).ignore();
68  setProperty( "NTuplePrint", false ).ignore();
69  setProperty( "HistogramProduce", false ).ignore();
70  setProperty( "HistogramPrint", false ).ignore();
71  setProperty( "PropertiesPrint", true ).ignore();
72  setProperty( "TypePrint", false ).ignore();
73  setProperty( "EvtColsProduce", true ).ignore();
74  setProperty( "EvtColsPrint", true ).ignore();
75  }
76 
77  private:
78  // default constructor is private
80  // copy constructor is disabled
81  EvtColAlg( const EvtColAlg& );
82  // assignement operator is disabled
84  };
85  // ========================================================================
86  } // namespace Examples
87 } // end of namespace Gaudi
88 // ============================================================================
90 // ============================================================================
92  static int s_nEvt = 0;
93  static int s_nRun = 0;
94 
95  if ( 1 == ++s_nEvt % 50 ) { ++s_nRun; }
96 
97  DataObject* event = get<DataObject>( "/Event" );
98  if ( 0 == event ) { return StatusCode::FAILURE; }
99  IRegistry* registry = event->registry();
100  if ( 0 == registry ) { return Error( "IRegistry* point to NULL!" ); }
101  IOpaqueAddress* address = registry->address();
102  if ( 0 == address ) { return Error( "Address points to NULL!" ); }
103 
104  Rndm::Numbers gauss( randSvc(), Rndm::Gauss( 0.0, 1.0 ) );
105  Rndm::Numbers flat( randSvc(), Rndm::Flat( -10.0, 10.0 ) );
106  Rndm::Numbers expo( randSvc(), Rndm::Exponential( 1.0 ) );
107  Rndm::Numbers breit( randSvc(), Rndm::BreitWigner( 0.0, 1.0 ) );
108  Rndm::Numbers poisson( randSvc(), Rndm::Poisson( 2.0 ) );
109  Rndm::Numbers binom( randSvc(), Rndm::Binomial( 8, 0.25 ) );
110 
111  // get the event tag collection
112  Tuple tuple = evtCol( TupleID( "COL1" ), "The most trivial Event Tag Collection" );
113 
114  // event address (the most important information)
115  tuple->column( "Address", address ).ignore();
116  // put 'event' and 'run' number
117  tuple->column( "evtNum", s_nEvt ).ignore();
118  tuple->column( "runNum", s_nRun ).ignore();
119  // put some 'data'
120  tuple->column( "gauss", gauss() ).ignore();
121  tuple->column( "flat", flat() ).ignore();
122  tuple->column( "expo", expo() ).ignore();
123  tuple->column( "breit", breit() ).ignore();
124  tuple->column( "poisson", (int)poisson() ).ignore();
125  tuple->column( "binom", (int)binom() ).ignore();
126  tuple->column( "flag", 0 > gauss() ).ignore(); // boolean
127 
128  // The action of is restored again!
129  return tuple->write();
130 }
131 // ============================================================================
134 // ============================================================================
135 // The END
136 // ============================================================================
TupleID.h
Tuple.h
std::string
STL class.
Tuples.h
RndmGenerators.h
Gaudi::Algorithm::randSvc
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
Definition: Algorithm.cpp:565
Gaudi::Examples::EvtColAlg
Definition: EvtColAlg.cpp:49
Tuples::TupleObj::column
StatusCode column(std::string_view name, float value)
Set the value for selected tuple column.
Definition: TupleObj.cpp:267
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:528
GaudiCommon< Algorithm >::Assert
void Assert(const bool ok, std::string_view message="", const StatusCode sc=StatusCode::FAILURE) const
Assertion - throw exception if the given condition is not fulfilled.
Definition: GaudiCommonImp.h:175
IOpaqueAddress
Definition: IOpaqueAddress.h:33
GaudiTuples< GaudiHistoAlg >::TupleID
GaudiAlg::TupleID TupleID
the actual type of N-tuple ID
Definition: GaudiTuples.h:61
PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >::setProperty
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
Set the property from a property.
Definition: IProperty.h:39
ISvcLocator
Definition: ISvcLocator.h:46
IRndmGenSvc.h
GaudiTupleAlg
Definition: GaudiTupleAlg.h:51
IRegistry
Definition: IRegistry.h:32
Rndm::Flat
Parameters for the flat random number generation within boundaries [minimum, maximum].
Definition: RndmGenerators.h:253
GaudiPluginService.cpluginsvc.registry
def registry()
Definition: cpluginsvc.py:83
GaudiTupleAlg.h
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
Gaudi::Examples::EvtColAlg::EvtColAlg
EvtColAlg(const EvtColAlg &)
IOpaqueAddress.h
Rndm::BreitWigner
Parameters for the BreitWigner distributed random number generation.
Definition: RndmGenerators.h:94
Tuples::Tuple
A simple wrapper class over standard Gaudi NTuple::Tuple facility.
Definition: Tuple.h:126
Gaudi::Examples::EvtColAlg::EvtColAlg
EvtColAlg()
GaudiTuples< GaudiHistoAlg >::evtCol
Tuple evtCol(const std::string &title, const CLID &clid=CLID_ColumnWiseTuple) const
Access an Event Tag Collection object (book on-demand) with unique identifier.
Definition: GaudiTuples.icpp:134
IRegistry.h
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Examples::EvtColAlg::EvtColAlg
EvtColAlg(const std::string &name, ISvcLocator *pSvc)
standard construtor
Definition: EvtColAlg.cpp:65
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
Gaudi::Units::gauss
constexpr double gauss
Definition: SystemOfUnits.h:252
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DataObject.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
DataObject
Definition: DataObject.h:40
Tuples::TupleObj::write
StatusCode write()
write a record to NTuple
Definition: TupleObj.cpp:245
Rndm::Exponential
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:56
Gaudi::Examples::EvtColAlg::execute
StatusCode execute() override
the only one essential methos
Definition: EvtColAlg.cpp:91
Rndm::Poisson
Parameters for the Poisson distributed random number generation with a given mean.
Definition: RndmGenerators.h:209
GaudiTuples< GaudiHistoAlg >::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiTuples.icpp:47
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::Examples::EvtColAlg::initialize
StatusCode initialize() override
Definition: EvtColAlg.cpp:51
Gaudi::Examples::EvtColAlg::operator=
EvtColAlg & operator=(const EvtColAlg &)
Rndm::Binomial
Parameters for the Binomial distributed random number generation.
Definition: RndmGenerators.h:230
GaudiCommon< Algorithm >::Error
StatusCode Error(std::string_view msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the error message and return with the given StatusCode.
Definition: GaudiCommon.icpp:256
INTupleSvc.h