Gaudi Framework, version v25r2
Home
Generated: Wed Jun 4 2014
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
.cern.ch
sw
Gaudi
releases
GAUDI
GAUDI_v25r2
RootHistCnv
src
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
= TFile::Open(
m_defFileName
.c_str(),
"RECREATE"
,
"GAUDI Histograms"
);
48
}
else
{
49
m_hfile
= 0;
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;
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
), m_hfile(0), m_prtWar(false) {
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
}
135
136
//-----------------------------------------------------------------------------
137
RootHistCnv::PersSvc::~PersSvc
()
138
//-----------------------------------------------------------------------------
139
{
140
if
( m_hfile != 0 ) {
141
delete
m_hfile;
142
m_hfile = 0;
143
}
144
}
Generated at Wed Jun 4 2014 14:48:58 for Gaudi Framework, version v25r2 by
Doxygen
version 1.8.2 written by
Dimitri van Heesch
, © 1997-2004