Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiCommonTests.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 // GaudiKernel
13 // ============================================================================
14 #include "GaudiKernel/IRegistry.h"
17 
18 // local
19 #include "GaudiCommonTests.h"
20 
21 using namespace Gaudi::Examples;
22 
23 //-----------------------------------------------------------------------------
24 // Implementation file for class : GaudiHistoAlgorithm
25 //
26 // 2005-08-12 : Chris Jones
27 //-----------------------------------------------------------------------------
28 
29 // Declaration of the Algorithm Factory
31 
32 //=============================================================================
33 // Standard constructor, initializes variables
34 //=============================================================================
35 GaudiCommonTests::GaudiCommonTests( const std::string& name, ISvcLocator* pSvcLocator )
36  : GaudiAlgorithm( name, pSvcLocator ) {}
37 //=============================================================================
38 // Destructor
39 //=============================================================================
41 
42 //=============================================================================
43 // Initialization
44 //=============================================================================
46  // must be called first
48  if ( sc.isFailure() ) return sc;
49 
50  return sc;
51 }
52 
53 //=============================================================================
54 // Main execution
55 //=============================================================================
57  info() << "Execute" << endmsg;
58 
59  const std::string loc1 = "/Event/" + name() + "/Tracks1";
60  const std::string loc2 = "/Event/" + name() + "/Tracks2";
61  const std::string loc3 = name() + "/Tracks3";
62  const std::string loc4 = name() + "/Tracks4";
63 
64  const std::string loc5 = "/Event";
65  const std::string loc6 = "";
66 
67  // tests creating data
68  {
69 
70  MyTrackVector* Tracks1 = new MyTrackVector();
71  MyTrackVector* Tracks2 = new MyTrackVector();
72  MyTrackVector* Tracks3 = new MyTrackVector();
73  MyTrackVector* Tracks4 = new MyTrackVector();
74 
75  // With /Event, with RootInTES
76  put( Tracks1, loc1, UseRootInTES );
77  // With /Event, without RootInTES
78  put( Tracks2, loc2, IgnoreRootInTES );
79  // Without /Event, with RootInTES
80  put( Tracks3, loc3, UseRootInTES );
81  // Without /Event, without RootInTES
82  put( Tracks4, loc4, IgnoreRootInTES );
83  }
84 
85  // tests retrieving data
86  {
87 
88  MyTrackVector* Tracks1 = get<MyTrackVector>( loc1, UseRootInTES );
89  MyTrackVector* Tracks2 = get<MyTrackVector>( loc2, IgnoreRootInTES );
90  MyTrackVector* Tracks3 = get<MyTrackVector>( loc3, UseRootInTES );
91  MyTrackVector* Tracks4 = get<MyTrackVector>( loc4, IgnoreRootInTES );
92  DataObject* Root1 = get<DataObject>( loc5, UseRootInTES );
93  DataObject* Root2 = get<DataObject>( loc5, IgnoreRootInTES );
94  DataObject* Root3 = get<DataObject>( loc6, UseRootInTES );
95  DataObject* Root4 = get<DataObject>( loc6, IgnoreRootInTES );
96  // should never happen ... Errors should be caught above
97  if ( !Tracks1 || !Tracks2 || !Tracks3 || !Tracks4 || !Root1 || !Root2 || !Root3 || !Root4 )
98  return Error( "Problem getting data" );
99 
100  info() << "Loaded Objects:" << endmsg;
101  info() << Tracks1->registry()->identifier() << endmsg;
102  info() << Tracks2->registry()->identifier() << endmsg;
103  info() << Tracks3->registry()->identifier() << endmsg;
104  info() << Tracks4->registry()->identifier() << endmsg;
105  info() << Root1->registry()->identifier() << endmsg;
106  info() << Root2->registry()->identifier() << endmsg;
107  info() << Root3->registry()->identifier() << endmsg;
108  info() << Root4->registry()->identifier() << endmsg;
109  }
110 
111  // Test get without checks
112  {
113  MyTrackVector* Tracks = NULL;
114 
115  Tracks = getIfExists<MyTrackVector>( loc1 );
116  if ( !Tracks ) return Error( "Problem getting data" );
117 
118  Tracks = getIfExists<MyTrackVector>( "Nowhere/To/Be/Found" );
119  if ( Tracks ) return Error( "Expected null pointer" );
120  }
121  return StatusCode::SUCCESS;
122 }
123 
124 //=============================================================================
125 // Finalize
126 //=============================================================================
128  // must be called after all other actions
129  return GaudiAlgorithm::finalize();
130 }
131 
132 //=============================================================================
std::string
STL class.
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:65
RndmGenerators.h
Gaudi::Examples::MyTrackVector
KeyedContainer< MyTrack > MyTrackVector
Definition: MyTrack.h:135
ISvcLocator
Definition: ISvcLocator.h:46
IRndmGenSvc.h
GaudiCommonTests::~GaudiCommonTests
~GaudiCommonTests() override
Destructor.
Definition: GaudiCommonTests.cpp:40
GaudiCommonTests::execute
StatusCode execute() override
Algorithm execution.
Definition: GaudiCommonTests.cpp:56
GaudiCommonTests.h
TimingHistograms.name
name
Definition: TimingHistograms.py:25
Gaudi::Examples
Definition: ConditionAccessorHolder.h:21
StatusCode
Definition: StatusCode.h:65
GaudiAlgorithm
Definition: GaudiAlgorithm.h:104
GaudiCommonTests
Definition: GaudiCommonTests.h:30
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:52
GaudiCommonTests::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: GaudiCommonTests.cpp:127
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
IRegistry.h
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
DataObject
Definition: DataObject.h:40
GaudiCommonTests::initialize
StatusCode initialize() override
Algorithm initialization.
Definition: GaudiCommonTests.cpp:45
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:82
Gaudi::Functional::details::put
auto put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
Definition: FunctionalDetails.h:173