Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PersSvc.cpp
Go to the documentation of this file.
1 // Include files
7 #include "RConverter.h"
8 #include "RootObjAddress.h"
9 #include "TFile.h"
10 
11 namespace RootHistCnv {
12  static std::string stat_dir = "/stat";
13  static std::string undefFileName = "UndefinedROOTOutputFileName";
14 } // namespace RootHistCnv
15 
16 #include "PersSvc.h"
17 
18 //-----------------------------------------------------------------------------
19 //
20 // Implementation of class : RootHistCnv::PersSvc
21 //
22 // Author : Charles Leggett
23 //
24 //-----------------------------------------------------------------------------
25 
26 // Instantiation of a static factory class used by clients to create
27 // instances of this service
30 
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
34 {
35 
37  if ( status.isFailure() ) return status;
38 
39  // Get my properties from the JobOptionsSvc
40  if ( setProperties().isFailure() ) {
41  error() << "Could not set my properties" << endmsg;
42  return StatusCode::FAILURE;
43  }
44  if ( m_outputEnabled ) {
45  // Initialize ROOT if output file name is defined
46  if ( undefFileName != m_defFileName ) {
47  m_hfile.reset( TFile::Open( m_defFileName.value().c_str(), "RECREATE", "GAUDI Histograms" ) );
48  } else {
49  m_hfile.reset();
50  }
51  info() << "Writing ROOT histograms to: " << m_defFileName.value() << endmsg;
52  } else {
53  info() << "Writing ROOT histograms disabled." << endmsg;
54  }
55  return StatusCode( StatusCode::SUCCESS, true );
56 }
57 
58 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 {
62  // Close ROOT only if the output file name is defined
63  debug() << "RootHistCnv::PersSvc::finalize()" << endmsg;
64  if ( m_outputEnabled ) {
65  if ( undefFileName != m_defFileName ) {
66  m_hfile->Write( "", TObject::kOverwrite );
67  m_hfile->Close();
68  }
69  }
70  return ConversionSvc::finalize();
71 }
72 
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
76 {
77  // There are objects in the HDS to be stored
78  if ( m_outputEnabled && undefFileName != m_defFileName ) {
79  SmartDataPtr<DataObject> top( dataProvider(), stat_dir );
80  if ( top ) {
81  IRegistry* pReg = top->registry();
82  if ( pReg ) {
83  if ( top.ptr() == pObject ) {
84  TDirectory* pDir = m_hfile.get();
85  refpAddress = new RootObjAddress( repSvcType(), CLID_DataObject, stat_dir, m_defFileName.value(),
86  long( pDir ), long( 0 ) );
87  return StatusCode::SUCCESS;
88  } else {
89  StatusCode sc = ConversionSvc::createRep( pObject, refpAddress );
90  if ( sc.isFailure() ) {
91  error() << "Error while creating persistent Histogram:" << pReg->identifier() << endmsg;
92  }
93  return sc;
94  }
95  }
96  }
97  error() << "Internal error while creating Histogram persistent representations" << endmsg;
98  return StatusCode::FAILURE;
99  } else {
100  if ( m_outputEnabled && !m_prtWar ) {
101  m_prtWar = true;
102  warning() << "no ROOT output file name, "
103  << "Histograms cannot be persistified" << endmsg;
104  }
105  }
106  return StatusCode::SUCCESS;
107 }
StatusCode finalize() override
Finalise the service.
Definition: PersSvc.cpp:59
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
bool isFailure() const
Definition: StatusCode.h:130
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Convert a collection of transient data objects into another representation.
Definition: PersSvc.cpp:74
STL class.
TYPE * ptr()
Automatic conversion to data type.
#define DECLARE_COMPONENT(type)
virtual const id_type & identifier() const =0
Full identifier (or key)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataPtr.h:47
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Persistency service - to store histograms in ROOT format.
Definition: PersSvc.h:18
Opaque address interface definition.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
StatusCode finalize() override
stop the service.
StatusCode initialize() override
Initialize the service.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192