The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SelCreate.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 // ============================================================================
18 // ============================================================================
19 // GaudiAlg
20 // ============================================================================
22 // ============================================================================
23 // Local
24 // ============================================================================
25 #include "GaudiExamples/MyTrack.h"
26 // ============================================================================
27 #ifdef __ICC
28 // disable icc remark #2259: non-pointer conversion from "double" to "float" may lose significant bits
29 # pragma warning( disable : 2259 )
30 #elif defined( WIN32 )
31 // disable warning
32 // C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
33 # pragma warning( disable : 4244 )
34 #endif
35 
36 namespace Gaudi {
37  namespace Examples {
43  class SelCreate : public GaudiAlgorithm {
45  DataObjectWriteHandle<Container> m_output{ this, "Output", this->name(), "TES location of output container" };
46 
47  public:
48  // ======================================================================
51  SelCreate( const std::string& name, ISvcLocator* pSvcLocator ) : GaudiAlgorithm( name, pSvcLocator ) {}
52  // using GaudiAlgorithm::GaudiAlgorithm;
53  // ======================================================================
55  StatusCode execute() override {
56  // some random number generators, just to provide the numbers
57  static Rndm::Numbers gauss( randSvc(), Rndm::Gauss( 0.0, 1.0 ) );
58  static Rndm::Numbers flat( randSvc(), Rndm::Flat( 20.0, 100.0 ) );
59 
60  // create the data
61  auto tracks = std::make_unique<Gaudi::Examples::MyTrack::Container>();
62 
63  for ( int i = 0; i < 100; ++i ) {
64  // create new track
65  auto track = std::make_unique<Gaudi::Examples::MyTrack>();
66 
67  // fill it with some "data"
68  track->setPx( gauss() );
69  track->setPy( gauss() );
70  track->setPz( gauss() + flat() );
71 
72  // insert it into the container
73  tracks->insert( track.release() );
74  }
75 
76  // register the container in TES
77  m_output.put( std::move( tracks ) );
78 
80  if ( !exist<Range>( name() ) ) { err() << "No Range is available at location " << name() << endmsg; }
81 
82  // test "get-or-create":
83 
84  getOrCreate<Range, Gaudi::Examples::MyTrack::Container>( name() + "_1" );
85  getOrCreate<Range, Gaudi::Examples::MyTrack::Selection>( name() + "_2" );
86 
87  getOrCreate<Gaudi::Examples::MyTrack::Container, Gaudi::Examples::MyTrack::Container>( name() + "_3" );
88  getOrCreate<Gaudi::Examples::MyTrack::Selection, Gaudi::Examples::MyTrack::Selection>( name() + "_4" );
89 
90  return StatusCode::SUCCESS;
91  }
92  };
93  // ========================================================================
94  } // namespace Examples
95 } // end of namespace Gaudi
96 // ============================================================================
100 // ============================================================================
101 // The END
102 // ============================================================================
DataObjectWriteHandle
Definition: DataObjectHandle.h:427
std::string
STL class.
RndmGenerators.h
Gaudi::Examples::SelCreate::execute
StatusCode execute() override
the only one essential method
Definition: SelCreate.cpp:55
Gaudi::Algorithm::randSvc
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
Definition: Algorithm.cpp:565
Gaudi::NamedRange_
Definition: NamedRange.h:52
std::move
T move(T... args)
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:528
ISvcLocator
Definition: ISvcLocator.h:46
IRndmGenSvc.h
Gaudi::Examples::MyTrack::Container
KeyedContainer< MyTrack, Containers::HashMap > Container
the actual type of container in TES
Definition: MyTrack.h:69
Gaudi::Examples::SelCreate::m_output
DataObjectWriteHandle< Container > m_output
Definition: SelCreate.cpp:45
Rndm::Flat
Parameters for the flat random number generation within boundaries [minimum, maximum].
Definition: RndmGenerators.h:253
Gaudi::Examples::SelCreate::SelCreate
SelCreate(const std::string &name, ISvcLocator *pSvcLocator)
standard constructor
Definition: SelCreate.cpp:51
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
GaudiAlgorithm
Definition: GaudiAlgorithm.h:104
MyTrack.h
Gaudi::Examples::SelCreate
Definition: SelCreate.cpp:43
HistoUtilsEx.gauss
gauss
Definition: HistoUtilsEx.py:66
KeyedContainer
template class KeyedContainer, KeyedContainer.h
Definition: KeyedContainer.h:74
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
GaudiAlgorithm.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46