| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

PersSvc.cpp
Go to the documentation of this file.
1 // Include files
2 #include "GaudiKernel/DataObject.h"
3 #include "GaudiKernel/MsgStream.h"
4 #include "GaudiKernel/ISvcLocator.h"
5 #include "GaudiKernel/IRegistry.h"
6 #include "GaudiKernel/SmartDataPtr.h"
7 #include "RootObjAddress.h"
8 #include "RConverter.h"
9 #include "TFile.h"
10
11 namespace RootHistCnv {
12 static std::string stat_dir = "/stat";
13 static std::string undefFileName = "UndefinedROOTOutputFileName";
14 }
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
28 using RootHistCnv::PersSvc;
29 DECLARE_COMPONENT(PersSvc)
30
31
32 //-----------------------------------------------------------------------------
33 StatusCode RootHistCnv::PersSvc::initialize()
34 //-----------------------------------------------------------------------------
35 {
36 MsgStream log( msgSvc(), name() );
37
38 StatusCode status = ConversionSvc::initialize();
39 if( status.isFailure() ) return status;
40
41 // Get my properties from the JobOptionsSvc
42 if (setProperties().isFailure()) {
43 log << MSG::ERROR << "Could not set my properties" << endmsg;
44 return StatusCode::FAILURE;
45 }
46 if (m_outputEnabled) {
47 // Initialize ROOT if output file name is defined
48 if( undefFileName != m_defFileName ) {
49 m_hfile.reset( TFile::Open(m_defFileName.value().c_str(),"RECREATE","GAUDI Histograms") );
50 } else {
51 m_hfile.reset();
52 }
53 log << MSG::INFO << "Writing ROOT histograms to: " << m_defFileName.value()
54 << endmsg;
55 }
56 else {
57 log << MSG::INFO << "Writing ROOT histograms disabled." << endmsg;
58 }
59 return StatusCode(StatusCode::SUCCESS,true);
60 }
61
62
63 //-----------------------------------------------------------------------------
64 StatusCode RootHistCnv::PersSvc::finalize()
65 //-----------------------------------------------------------------------------
66 {
67 // Close ROOT only if the output file name is defined
68 MsgStream log( msgSvc(), name() );
69 log << MSG::DEBUG << "RootHistCnv::PersSvc::finalize()" << endmsg;
70 if( undefFileName != m_defFileName ) {
71 m_hfile->Write("",TObject::kOverwrite);
72 m_hfile->Close();
73 }
74 return ConversionSvc::finalize();
75 }
76
77 //-----------------------------------------------------------------------------
78 StatusCode RootHistCnv::PersSvc::createRep(DataObject* pObject,
79 IOpaqueAddress*& refpAddress)
80 //-----------------------------------------------------------------------------
81 {
82 // There are objects in the HDS to be stored
83 if( m_outputEnabled && undefFileName != m_defFileName ) {
84 SmartDataPtr<DataObject> top(dataProvider(), stat_dir);
85 if ( 0 != top ) {
86 IRegistry* pReg = top->registry();
87 if ( pReg ) {
88 if ( top.ptr() == pObject ) {
89 TDirectory* pDir = m_hfile.get();
90 refpAddress = new RootObjAddress( repSvcType(),
91 CLID_DataObject,
92 stat_dir,
93 m_defFileName,
94 long(pDir),
95 long(0));
96 return StatusCode::SUCCESS;
97 }
98 else {
99 StatusCode sc = ConversionSvc::createRep(pObject, refpAddress);
100 if( sc.isFailure() ) {
101 MsgStream log( msgSvc(), name() );
102 log << MSG::ERROR
103 << "Error while creating persistent Histogram:"
104 << pReg->identifier()
105 << endmsg;
106 }
107 return sc;
108 }
109 }
110 }
111 MsgStream err( msgSvc(), name() );
112 err << MSG::ERROR
113 << "Internal error while creating Histogram persistent representations"
114 << endmsg;
115 return StatusCode::FAILURE;
116 } else {
117 if (m_outputEnabled && !m_prtWar) {
118 m_prtWar = true;
119 MsgStream log( msgSvc(), name() );
120 log << MSG::WARNING
121 << "no ROOT output file name, "
122 << "Histograms cannot be persistified" << endmsg;
123 }
124 }
125 return StatusCode::SUCCESS;
126 }
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode::SUCCESS
Definition: StatusCode.h:30
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
StatusCode::FAILURE
Definition: StatusCode.h:29
RootHistCnv::PersSvc::finalize
StatusCode finalize() override
Finalise the service.
Definition: PersSvc.cpp:64
MsgStream.h
ConversionSvc::createRep
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
Definition: ConversionSvc.cpp:123
MSG::DEBUG
Definition: IMessageSvc.h:18
PersSvc.h
RootHistCnv::RootObjAddress
Definition: RootObjAddress.h:10
RConverter.h
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
RootHistCnv::PersSvc::createRep
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Convert a collection of transient data objects into another representation.
Definition: PersSvc.cpp:78
std::string
STL class.
SmartDataStorePtr< TYPE, SmartDataObjectPtr::ObjectLoader >::ptr
TYPE * ptr()
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:89
SmartDataPtr.h
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
ForwardSchedulerSimpleTest.msgSvc
msgSvc
Definition: ForwardSchedulerSimpleTest.py:112
RootHistCnv
Definition: DirectoryCnv.h:17
IRegistry.h
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
RootObjAddress.h
HiveAlgSequencer.top
top
Definition: HiveAlgSequencer.py:29
SmartDataPtr
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataPtr.h:46
MSG::ERROR
Definition: IMessageSvc.h:21
RootHistCnv::PersSvc
Persistency service - to store histograms in ROOT format.
Definition: PersSvc.h:19
MSG::WARNING
Definition: IMessageSvc.h:20
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
MSG::INFO
Definition: IMessageSvc.h:19
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
ConversionSvc::finalize
StatusCode finalize() override
stop the service.
Definition: ConversionSvc.cpp:268
ISvcLocator.h
ConversionSvc::initialize
StatusCode initialize() override
Initialize the service.
Definition: ConversionSvc.cpp:262
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
DataObject.h
Gaudi.Configuration.log
log
Definition: Configuration.py:13