Gaudi Framework, version v23r9
Home
Generated: Thu Jul 18 2013
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
RootHistCnv
src
PersSvc.cpp
Go to the documentation of this file.
1
// $Id: PersSvc.cpp,v 1.15 2007/03/15 15:53:15 hmd Exp $
2
3
// Include files
4
#include "
GaudiKernel/DataObject.h
"
5
#include "
GaudiKernel/SvcFactory.h
"
6
#include "
GaudiKernel/MsgStream.h
"
7
#include "
GaudiKernel/ISvcLocator.h
"
8
#include "
GaudiKernel/IRegistry.h
"
9
#include "
GaudiKernel/SmartDataPtr.h
"
10
#include "
RootObjAddress.h
"
11
#include "
RConverter.h
"
12
#include "
PersSvc.h
"
13
#include "TFile.h"
14
15
//-----------------------------------------------------------------------------
16
//
17
// Implementation of class : RootHistCnv::PersSvc
18
//
19
// Author : Charles Leggett
20
//
21
//-----------------------------------------------------------------------------
22
23
// Instantiation of a static factory class used by clients to create
24
// instances of this service
25
DECLARE_NAMESPACE_SERVICE_FACTORY
(RootHistCnv,PersSvc)
26
27
namespace RootHistCnv {
28
static
std::string
stat_dir
=
"/stat"
;
29
static
std::string
undefFileName
=
"UndefinedROOTOutputFileName"
;
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
= TFile::Open(
m_defFileName
.c_str(),
"RECREATE"
,
"GAUDI Histograms"
);
50
}
else
{
51
m_hfile
= 0;
52
}
53
log <<
MSG::INFO
<<
"Writing ROOT histograms to: "
<<
m_defFileName
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;
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
}
127
128
//-----------------------------------------------------------------------------
129
RootHistCnv::PersSvc::PersSvc
(
const
std::string
& name,
ISvcLocator
* svc)
130
//-----------------------------------------------------------------------------
131
:
ConversionSvc
(name, svc,
ROOT_StorageType
), m_hfile(0), m_prtWar(false) {
132
declareProperty
(
"OutputFile"
,
m_defFileName
=
undefFileName
);
133
declareProperty
(
"ForceAlphaIds"
,
m_alphaIds
=
false
);
134
declareProperty
(
"OutputEnabled"
,
m_outputEnabled
=
true
,
135
"Flag to enable/disable the output to file."
);
136
}
137
138
//-----------------------------------------------------------------------------
139
RootHistCnv::PersSvc::~PersSvc
()
140
//-----------------------------------------------------------------------------
141
{
142
if
( m_hfile != 0 ) {
143
delete
m_hfile;
144
m_hfile = 0;
145
}
146
}
Generated at Thu Jul 18 2013 12:18:05 for Gaudi Framework, version v23r9 by
Doxygen
version 1.8.2 written by
Dimitri van Heesch
, © 1997-2004