ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
Athena::RootOutputStreamTool Class Reference

This is the AthenaRoot version of AthenaServices/AthenaOutputStreamTool. More...

#include <RootOutputStreamTool.h>

Inheritance diagram for Athena::RootOutputStreamTool:
Collaboration diagram for Athena::RootOutputStreamTool:

Public Member Functions

 RootOutputStreamTool (const std::string &type, const std::string &name, const IInterface *parent)
 Standard AlgTool Constructor. More...
 
virtual ~RootOutputStreamTool ()
 Destructor. More...
 
virtual StatusCode initialize () override
 Gaudi AlgTool Interface method implementations: More...
 
virtual StatusCode finalize () override
 
virtual StatusCode connectServices (const std::string &dataStore, const std::string &cnvSvc, bool extendProvenenceRecord) override
 Specify which data store and conversion service to use and whether to extend provenence Only use if one wants to override jobOptions. More...
 
virtual StatusCode connectOutput (const std::string &outputName) override
 Connect to the output stream Must connectOutput BEFORE streaming Only specify "outputName" if one wants to override jobOptions. More...
 
virtual StatusCode commitOutput (bool doCommit=false) override
 Commit the output stream after having streamed out objects Must commitOutput AFTER streaming. More...
 
virtual StatusCode finalizeOutput () override
 Finalize the output stream after the last commit, e.g. More...
 
virtual StatusCode streamObjects (const IAthenaOutputStreamTool::TypeKeyPairs &typeKeys, const std::string &outputName="") override
 Stream out objects. More...
 
virtual StatusCode streamObjects (const IAthenaOutputStreamTool::DataObjectVec &dataObjects, const std::string &outputName="") override
 Stream out a vector of objects Must convert to DataObject, e.g. More...
 
virtual StatusCode getInputItemList (SG::IFolder *m_p2BWrittenFromTool) override
 

Private Attributes

ServiceHandle< ::StoreGateSvcm_storeSvc
 ServiceHandle to the data store service. More...
 
ServiceHandle< ::IConversionSvc > m_conversionSvc
 ServiceHandle to the data conversion service. More...
 
ServiceHandle< ::IClassIDSvc > m_clidSvc
 ServiceHandle to clid service. More...
 
std::string m_outputName
 Name of the output file. More...
 
std::string m_treeName
 Name of the output tuple. More...
 

Detailed Description

This is the AthenaRoot version of AthenaServices/AthenaOutputStreamTool.

Definition at line 33 of file RootOutputStreamTool.h.

Constructor & Destructor Documentation

◆ RootOutputStreamTool()

Athena::RootOutputStreamTool::RootOutputStreamTool ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Standard AlgTool Constructor.

Definition at line 33 of file RootOutputStreamTool.cxx.

33  :
34  base_class(type, name, parent),
35  m_storeSvc("StoreGateSvc", name),
36  m_conversionSvc("Athena::RootCnvSvc/AthenaRootCnvSvc", name),
37  m_clidSvc("ClassIDSvc", name) {
38  // Properties
39  declareProperty("Store", m_storeSvc, "Store from which to stream out event data");
40  declareProperty("TreeName", m_treeName = "CollectionTree", "Name of the output event tree");
41  declareProperty("OutputFile", m_outputName, "Name of the output file");
42 }

◆ ~RootOutputStreamTool()

Athena::RootOutputStreamTool::~RootOutputStreamTool ( )
virtual

Destructor.

Definition at line 44 of file RootOutputStreamTool.cxx.

44  {
45 }

Member Function Documentation

◆ commitOutput()

StatusCode Athena::RootOutputStreamTool::commitOutput ( bool  doCommit = false)
overridevirtual

Commit the output stream after having streamed out objects Must commitOutput AFTER streaming.

Definition at line 107 of file RootOutputStreamTool.cxx.

107  {
108  ATH_MSG_VERBOSE("commitOutput");
109  if (m_outputName.empty()) {
110  ATH_MSG_ERROR("Unable to commit, no output connected.");
111  return StatusCode::FAILURE;
112  }
113  // Connect the output file to the service
114  if (!m_conversionSvc->commitOutput(m_outputName, false).isSuccess()) {
115  ATH_MSG_ERROR("Unable to commit output " << m_outputName);
116  return StatusCode::FAILURE;
117  } else {
118  ATH_MSG_DEBUG("Committed: " << m_outputName);
119  }
120  m_outputName.clear();
121  return StatusCode::SUCCESS;
122 }

◆ connectOutput()

StatusCode Athena::RootOutputStreamTool::connectOutput ( const std::string &  outputName)
overridevirtual

Connect to the output stream Must connectOutput BEFORE streaming Only specify "outputName" if one wants to override jobOptions.

Definition at line 89 of file RootOutputStreamTool.cxx.

89  {
90  ATH_MSG_VERBOSE("connectOutput outputName = [" << outputName <<"]");
91  // Set output file name property
92  if (!outputName.empty()) {
94  } else {
95  return StatusCode::FAILURE;
96  }
97  // Connect the output file to the service
98  if (!m_conversionSvc->connectOutput(m_outputName + "(" + m_treeName + ")", "recreate").isSuccess()) {
99  ATH_MSG_ERROR("Unable to connect output " << m_outputName);
100  return StatusCode::FAILURE;
101  } else {
102  ATH_MSG_DEBUG("Connected to " << m_outputName);
103  }
104  return StatusCode::SUCCESS;
105 }

◆ connectServices()

StatusCode Athena::RootOutputStreamTool::connectServices ( const std::string &  dataStore,
const std::string &  cnvSvc,
bool  extendProvenenceRecord 
)
overridevirtual

Specify which data store and conversion service to use and whether to extend provenence Only use if one wants to override jobOptions.

Definition at line 75 of file RootOutputStreamTool.cxx.

75  {
76  ATH_MSG_VERBOSE("connectServices dataStore = " << dataStore << ", cnvSvc = " << cnvSvc << ", extendProv = " << extendProvenenceRecord);
77  // Release the old data store service
78  if (m_storeSvc != 0) {
79  if (!m_storeSvc.release().isSuccess()) {
80  ATH_MSG_WARNING("Could not release " << m_storeSvc.type() << " store.");
81  }
82  }
83  m_storeSvc = ServiceHandle<StoreGateSvc>(dataStore, this->name());
84  // Get the data store service
85  ATH_CHECK(m_storeSvc.retrieve());
86  return StatusCode::SUCCESS;
87 }

◆ finalize()

StatusCode Athena::RootOutputStreamTool::finalize ( )
overridevirtual

Definition at line 57 of file RootOutputStreamTool.cxx.

57  {
58  // Release the data store service
59  if (m_storeSvc != 0) {
60  if (!m_storeSvc.release().isSuccess()) {
61  ATH_MSG_WARNING("Could not release " << m_storeSvc.type() << " store.");
62  }
63  }
64  // Release the conversion service
65  if (!m_conversionSvc.release().isSuccess()) {
66  ATH_MSG_WARNING("Cannot release conversion service.");
67  }
68  // Release the ClassID service
69  if (!m_clidSvc.release().isSuccess()) {
70  ATH_MSG_WARNING("Cannot release ClassID service.");
71  }
72  return StatusCode::SUCCESS;
73 }

◆ finalizeOutput()

StatusCode Athena::RootOutputStreamTool::finalizeOutput ( )
overridevirtual

Finalize the output stream after the last commit, e.g.

in finalize

Definition at line 124 of file RootOutputStreamTool.cxx.

124  {
125  ATH_MSG_VERBOSE("finalizeOutput");
126  return StatusCode::SUCCESS;
127 }

◆ getInputItemList()

StatusCode Athena::RootOutputStreamTool::getInputItemList ( SG::IFolder m_p2BWrittenFromTool)
overridevirtual

Definition at line 218 of file RootOutputStreamTool.cxx.

218  {
219  ATH_MSG_VERBOSE("getInputItemList");
220  return StatusCode::SUCCESS;
221 }

◆ initialize()

StatusCode Athena::RootOutputStreamTool::initialize ( )
overridevirtual

Gaudi AlgTool Interface method implementations:

Definition at line 47 of file RootOutputStreamTool.cxx.

47  {
48  ATH_MSG_INFO("Initializing " << name());
49 
50  // Get the ClassID service
51  ATH_CHECK(m_clidSvc.retrieve());
52  // Get the conversion service
53  ATH_CHECK(m_conversionSvc.retrieve());
54  return StatusCode::SUCCESS;
55 }

◆ streamObjects() [1/2]

virtual StatusCode Athena::RootOutputStreamTool::streamObjects ( const IAthenaOutputStreamTool::DataObjectVec dataObjects,
const std::string &  outputName = "" 
)
overridevirtual

Stream out a vector of objects Must convert to DataObject, e.g.

#include "AthenaKernel/StorableConversions.h" T* obj = xxx; DataObject* dataObject = SG::asStorable(obj);

◆ streamObjects() [2/2]

StatusCode Athena::RootOutputStreamTool::streamObjects ( const IAthenaOutputStreamTool::TypeKeyPairs typeKeys,
const std::string &  outputName = "" 
)
overridevirtual

Stream out objects.

Provide vector of typeName/key pairs. If key is empty, assumes only one object and this will fail if there is more than one

Definition at line 129 of file RootOutputStreamTool.cxx.

129  {
130  ATH_MSG_VERBOSE("streamObjects(type/keys)...");
131  // Now iterate over the type/key pairs and stream out each object
132  std::vector<DataObject*> dataObjects;
133  dataObjects.reserve(typeKeys.size());
134  for (IAthenaOutputStreamTool::TypeKeyPairs::const_iterator first = typeKeys.begin(), last = typeKeys.end();
135  first != last; ++first) {
136  const std::string& type = (*first).first;
137  const std::string& key = (*first).second;
138  // Find the clid for type name from the classIDSvc
139  CLID clid = 0;
140  if (!m_clidSvc->getIDOfTypeName(type, clid).isSuccess()) {
141  ATH_MSG_ERROR("Could not get clid for typeName " << type);
142  return StatusCode::FAILURE;
143  }
144  DataObject* dObj = 0;
145  // Two options: no key or explicit key
146  if (key.empty()) {
147  ATH_MSG_DEBUG("Get data object with no key");
148  // Get DataObject without key
149  dObj = m_storeSvc->accessData(clid);
150  } else {
151  ATH_MSG_DEBUG("Get data object with key");
152  // Get DataObjects with key
153  dObj = m_storeSvc->accessData(clid, key);
154  }
155  if (dObj == 0) {
156  // No object - print warning and continue with next object
157  ATH_MSG_WARNING("No object found for type " << type << " key " << key);
158  continue;
159  } else {
160  ATH_MSG_DEBUG("Found object for type " << type << " key " << key);
161  }
162  // Save the dObj
163  dataObjects.push_back(dObj);
164  }
165  return this->streamObjects(dataObjects, outputName);
166 }

Member Data Documentation

◆ m_clidSvc

ServiceHandle< ::IClassIDSvc> Athena::RootOutputStreamTool::m_clidSvc
private

ServiceHandle to clid service.

Definition at line 83 of file RootOutputStreamTool.h.

◆ m_conversionSvc

ServiceHandle< ::IConversionSvc> Athena::RootOutputStreamTool::m_conversionSvc
private

ServiceHandle to the data conversion service.

Definition at line 81 of file RootOutputStreamTool.h.

◆ m_outputName

std::string Athena::RootOutputStreamTool::m_outputName
private

Name of the output file.

Definition at line 86 of file RootOutputStreamTool.h.

◆ m_storeSvc

ServiceHandle< ::StoreGateSvc> Athena::RootOutputStreamTool::m_storeSvc
private

ServiceHandle to the data store service.

Definition at line 79 of file RootOutputStreamTool.h.

◆ m_treeName

std::string Athena::RootOutputStreamTool::m_treeName
private

Name of the output tuple.

Definition at line 89 of file RootOutputStreamTool.h.


The documentation for this class was generated from the following files:
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Athena::RootOutputStreamTool::m_outputName
std::string m_outputName
Name of the output file.
Definition: RootOutputStreamTool.h:86
Athena::RootOutputStreamTool::m_storeSvc
ServiceHandle< ::StoreGateSvc > m_storeSvc
ServiceHandle to the data store service.
Definition: RootOutputStreamTool.h:79
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Athena::RootOutputStreamTool::m_clidSvc
ServiceHandle< ::IClassIDSvc > m_clidSvc
ServiceHandle to clid service.
Definition: RootOutputStreamTool.h:83
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
lumiFormat.outputName
string outputName
Definition: lumiFormat.py:65
Athena::RootOutputStreamTool::streamObjects
virtual StatusCode streamObjects(const IAthenaOutputStreamTool::TypeKeyPairs &typeKeys, const std::string &outputName="") override
Stream out objects.
Definition: RootOutputStreamTool.cxx:129
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DeMoScan.first
bool first
Definition: DeMoScan.py:534
Athena::RootOutputStreamTool::m_treeName
std::string m_treeName
Name of the output tuple.
Definition: RootOutputStreamTool.h:89
Athena::RootOutputStreamTool::m_conversionSvc
ServiceHandle< ::IConversionSvc > m_conversionSvc
ServiceHandle to the data conversion service.
Definition: RootOutputStreamTool.h:81
ServiceHandle< StoreGateSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37