| The Gaudi Framework v27r1

- 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 "PersSvc.h"
10 #include "TFile.h"
11
12 //-----------------------------------------------------------------------------
13 //
14 // Implementation of class : RootHistCnv::PersSvc
15 //
16 // Author : Charles Leggett
17 //
18 //-----------------------------------------------------------------------------
19
20 // Instantiation of a static factory class used by clients to create
21 // instances of this service
22 using RootHistCnv::PersSvc;
23 DECLARE_COMPONENT(PersSvc)
24
25 namespace RootHistCnv {
26 static std::string stat_dir = "/stat";
27 static std::string undefFileName = "UndefinedROOTOutputFileName";
28 }
29
30 //-----------------------------------------------------------------------------
31 StatusCode RootHistCnv::PersSvc::initialize()
32 //-----------------------------------------------------------------------------
33 {
34 MsgStream log( msgSvc(), name() );
35
36 StatusCode status = ConversionSvc::initialize();
37 if( status.isFailure() ) return status;
38
39 // Get my properties from the JobOptionsSvc
40 if (setProperties().isFailure()) {
41 log << MSG::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.c_str(),"RECREATE","GAUDI Histograms") );
48 } else {
49 m_hfile.reset();
50 }
51 log << MSG::INFO << "Writing ROOT histograms to: " << m_defFileName
52 << endmsg;
53 }
54 else {
55 log << MSG::INFO << "Writing ROOT histograms disabled." << endmsg;
56 }
57 return StatusCode(StatusCode::SUCCESS,true);
58 }
59
60
61 //-----------------------------------------------------------------------------
62 StatusCode RootHistCnv::PersSvc::finalize()
63 //-----------------------------------------------------------------------------
64 {
65 // Close ROOT only if the output file name is defined
66 MsgStream log( msgSvc(), name() );
67 log << MSG::DEBUG << "RootHistCnv::PersSvc::finalize()" << endmsg;
68 if( undefFileName != m_defFileName ) {
69 m_hfile->Write("",TObject::kOverwrite);
70 m_hfile->Close();
71 }
72 return ConversionSvc::finalize();
73 }
74
75 //-----------------------------------------------------------------------------
76 StatusCode RootHistCnv::PersSvc::createRep(DataObject* pObject,
77 IOpaqueAddress*& refpAddress)
78 //-----------------------------------------------------------------------------
79 {
80 // There are objects in the HDS to be stored
81 if( m_outputEnabled && undefFileName != m_defFileName ) {
82 SmartDataPtr<DataObject> top(dataProvider(), stat_dir);
83 if ( 0 != top ) {
84 IRegistry* pReg = top->registry();
85 if ( pReg ) {
86 if ( top.ptr() == pObject ) {
87 TDirectory* pDir = m_hfile.get();
88 refpAddress = new RootObjAddress( repSvcType(),
89 CLID_DataObject,
90 stat_dir,
91 m_defFileName,
92 long(pDir),
93 long(0));
94 return StatusCode::SUCCESS;
95 }
96 else {
97 StatusCode sc = ConversionSvc::createRep(pObject, refpAddress);
98 if( sc.isFailure() ) {
99 MsgStream log( msgSvc(), name() );
100 log << MSG::ERROR
101 << "Error while creating persistent Histogram:"
102 << pReg->identifier()
103 << endmsg;
104 }
105 return sc;
106 }
107 }
108 }
109 MsgStream err( msgSvc(), name() );
110 err << MSG::ERROR
111 << "Internal error while creating Histogram persistent representations"
112 << endmsg;
113 return StatusCode::FAILURE;
114 } else {
115 if (m_outputEnabled && !m_prtWar) {
116 m_prtWar = true;
117 MsgStream log( msgSvc(), name() );
118 log << MSG::WARNING
119 << "no ROOT output file name, "
120 << "Histograms cannot be persistified" << endmsg;
121 }
122 }
123 return StatusCode::SUCCESS;
124 }
125
126 //-----------------------------------------------------------------------------
127 RootHistCnv::PersSvc::PersSvc(const std::string& name, ISvcLocator* svc)
128 //-----------------------------------------------------------------------------
129 : ConversionSvc(name, svc, ROOT_StorageType) {
130 declareProperty("OutputFile", m_defFileName = undefFileName);
131 declareProperty("ForceAlphaIds", m_alphaIds = false);
132 declareProperty("OutputEnabled", m_outputEnabled = true,
133 "Flag to enable/disable the output to file.");
134 }
RootHistCnv::PersSvc::m_outputEnabled
bool m_outputEnabled
Flag to enable/disable the output to file.
Definition: PersSvc.h:41
ConversionSvc::createRep
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Implementation of IConverter: Convert the transient object to the requested representation.
Definition: ConversionSvc.cpp:123
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
RootHistCnv::PersSvc::finalize
StatusCode finalize() override
Finalise the service.
Definition: PersSvc.cpp:62
MsgStream.h
Gaudi.Configuration.log
tuple log
Definition: Configuration.py:13
MSG::DEBUG
Definition: IMessageSvc.h:18
PersSvc.h
RootHistCnv::RootObjAddress
Definition: RootObjAddress.h:10
RConverter.h
RootHistCnv::PersSvc::PersSvc
PersSvc(const std::string &name, ISvcLocator *svc)
Standard constructor.
Definition: PersSvc.cpp:127
merge_files.sc
int sc
Definition: merge_files.py:167
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
RootHistCnv::PersSvc::m_defFileName
std::string m_defFileName
Default file name.
Definition: PersSvc.h:37
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:76
std::string
STL class.
SmartDataStorePtr< TYPE, SmartDataObjectPtr::ObjectLoader >::ptr
TYPE * ptr()
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:89
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
SmartDataPtr.h
ConversionSvc::finalize
virtual StatusCode finalize()
stop the service.
Definition: ConversionSvc.cpp:268
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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
ROOT_StorageType
const long ROOT_StorageType
Definition: ClassID.h:52
RootHistCnv::PersSvc::m_alphaIds
bool m_alphaIds
Force alphabetic histograms/ntuple IDs.
Definition: PersSvc.h:40
std::unique_ptr::reset
T reset(T...args)
Service::setProperties
StatusCode setProperties()
Method for setting declared properties to the values specified for the job.
Definition: Service.cpp:363
RootObjAddress.h
HiveAlgSequencer.top
tuple top
Definition: HiveAlgSequencer.py:29
std::string::c_str
T c_str(T...args)
SmartDataPtr
A small class used to access easily (and efficiently) data items residing in data stores...
Definition: SmartDataPtr.h:46
CommonMessagingBase::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:73
MSG::ERROR
Definition: IMessageSvc.h:21
RootHistCnv::PersSvc
Persistency service - to store histograms in ROOT format.
Definition: PersSvc.h:19
ConversionSvc::initialize
virtual StatusCode initialize()
Initialize the service.
Definition: ConversionSvc.cpp:262
MSG::WARNING
Definition: IMessageSvc.h:20
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
ConversionSvc
Base class for all conversion services.
Definition: ConversionSvc.h:46
Service::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
MSG::INFO
Definition: IMessageSvc.h:19
RootHistCnv::PersSvc::m_hfile
std::unique_ptr< TFile > m_hfile
Pointer to the ROOT file.
Definition: PersSvc.h:38
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
ISvcLocator.h
RootHistCnv::PersSvc::initialize
StatusCode initialize() override
Initialise the service.
Definition: PersSvc.cpp:31
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
ForwardSchedulerSimpleTest.msgSvc
tuple msgSvc
Definition: ForwardSchedulerSimpleTest.py:112
DataObject.h