ATLAS Offline Software
SGWrite.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "SGWrite.h"
6 
7 #include "MyDataObj.h"
8 #include "LinkObj.h"
9 #include "Tutorial_ClassDEF.h"
10 
11 #include "GaudiKernel/ISvcLocator.h"
12 
13 #include "AthLinks/DataLink.h"
14 #include "AthLinks/ElementLink.h"
15 
16 #include "StoreGate/StoreGateSvc.h"
17 
18 using namespace SGTutorial;
19 
21 // CONSTRUCTOR:
22 
23 SGWrite::SGWrite(const std::string& name, ISvcLocator* pSvcLocator) :
24  AthAlgorithm(name, pSvcLocator), m_DataObjKey("foo")
25 {
26 
27  // Declare the properties
28  // Get key to be given to Data Objects in TDS
29 
30  declareProperty("DataObjKey", m_DataObjKey);
31 
32 }
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
35 
37 {
38 
39  ATH_MSG_INFO ("in initialize()");
40 
41  // Print out the key of the data objects
42 
43  ATH_MSG_INFO ("MyDataObj key: " << m_DataObjKey);
44 
45  StatusCode sc = evtStore().retrieve();
46  if (sc.isFailure())
47  {
48  ATH_MSG_ERROR ("Unable to retrieve pointer to StoreGate Service");
49  return sc;
50  }
51 
52  return StatusCode::SUCCESS;
53 
54 
55 }
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
58 
60 
61  ATH_MSG_INFO ("in execute()");
62 
64  // PART1 Objective:
65  // Create a Data Object "MyDataObj" and record it in the TDS
67 
68  // Register "MyDataObj"
69 
70  // set it as constant so that nobody can modify it anymore.
71  // This will also allow the object to be persistified later on
72 
73 
75  // PART2 Objective:
76  // Create a collection of objects : "MyElement". Note that "MyElement"
77  // does not inherits from ContainedObject. Push MyElement into a
78  // collection: std::vector<MyElement>.
79  // Register the std::vector<MyElement> into the StoreGate:
81 
82 
83 
84  // Register vector of "MyElement"
85 
86  // set it as constant so that nobody can modify it anymore.
87  // This will also allow the object to be persistified later on
88 
90  // PART3 Objective:
91  // Set up DataLinks . Each instance of LinkObj contains a link
92  // to a MyDataObj and one to a MyElement;
93  // Create data links for both and set them in a LinkObj object
94  // using the setObjLink and setContLink methods.
95  // We will use the DataLinks in LinkObj later in SGRead to ensure that it
96  // does return the correct objects they point to.
98 
99  //Instantiate a LinkObj
100 
101  //set the DataLink to a MyDataObj
102 
103  //set the ElementLink to the first element of the collection
104 
105  //Register the LinkObj in TDS:
106 
107 
108  // set it as constant so that nobody can modify it anymore
109  // This will also allow the object to be persistified later on
110 
112  // We are DONE!
114 
115  ATH_MSG_INFO ("registered all data");
116  return StatusCode::SUCCESS;
117 }
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
120 
122 {
123  ATH_MSG_INFO ("in finalize()");
124  return StatusCode::SUCCESS;
125 }
126 
127 
MyDataObj.h
Tutorial_ClassDEF.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SGWrite::initialize
StatusCode initialize()
Definition: SGWrite.cxx:36
SGWrite::finalize
StatusCode finalize()
Definition: SGWrite.cxx:121
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SGWrite::SGWrite
SGWrite(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SGWrite.cxx:23
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SGWrite::m_DataObjKey
std::string m_DataObjKey
Definition: SGWrite.h:36
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
SGWrite::execute
StatusCode execute()
Definition: SGWrite.cxx:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthAlgorithm
Definition: AthAlgorithm.h:47
SGTutorial
Definition: LinkObj.h:18
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LinkObj.h
StoreGateSvc.h
SGWrite.h