| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 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
HistogramPersistencySvc.cpp
Go to the documentation of this file.
1 // $Id: HistogramPersistencySvc.cpp,v 1.9 2008/10/09 13:40:18 marcocle Exp $
2 // ============================================================================
3 // HistogramPersistencySvc.cpp
4 //--------------------------------------------------------------------
5 //
6 // Package : System ( The LHCb Offline System)
7 //
8 // Description: implementation of the Event data persistency service
9 // This specialized service only deals with event related
10 // data
11 //
12 // Author : M.Frank
13 // History :
14 // +---------+----------------------------------------------+---------
15 // | Date | Comment | Who
16 // +---------+----------------------------------------------+---------
17 // | 29/10/98| Initial version | MF
18 // +---------+----------------------------------------------+---------
19 //
20 //====================================================================
21 #define PERSISTENCYSVC_HISTOGRAMPERSISTENCYSVC_CPP
22 // ============================================================================
23 // Include files
24 // ============================================================================
25 // GaudiKernel
26 // ============================================================================
27 #include "GaudiKernel/SmartIF.h"
28 #include "GaudiKernel/MsgStream.h"
29 #include "GaudiKernel/ISvcLocator.h"
30 #include "GaudiKernel/IJobOptionsSvc.h"
31 #include "GaudiKernel/DataObject.h"
32 #include "GaudiKernel/IRegistry.h"
33 #include "GaudiKernel/IDataProviderSvc.h"
34 // ============================================================================
35 // local
36 // ============================================================================
37 #include "HistogramPersistencySvc.h"
38 // ============================================================================
39 // AIDA
40 // ============================================================================
42 #define class class GAUDI_API
43 #include "AIDA/IBaseHistogram.h"
44 #undef class
45 // ============================================================================
46 // Instantiation of a static factory class used by clients to create
47 // instances of this service
48 DECLARE_COMPONENT(HistogramPersistencySvc)
49
50 // ============================================================================
51 // Finalize the service.
52 StatusCode HistogramPersistencySvc::finalize()
53 {
54 //
55 MsgStream log ( msgSvc() , name() );
56 if ( !(m_convert.empty() && m_exclude.empty()) )
57 { // print message if any of the two properties is used
58 log << MSG::INFO << "Histograms Converted/Excluded: "
59 << m_converted.size() << "/" << m_excluded.size() << endmsg ;
60 }
61 if (msgLevel(MSG::DEBUG)) {
62 if ( !m_excluded.empty() )
63 {
64 log << MSG::DEBUG << "Excluded Histos : #" << m_excluded.size() ;
65 for ( Set::const_iterator item = m_excluded.begin() ;
66 m_excluded.end() != item ; ++item )
67 { log << std::endl << " '" << (*item) << "'" ; }
68 log << endmsg ;
69 }
70 //
71 if ( !m_converted.empty() )
72 {
73 log << MSG::DEBUG << "Converted Histos : #" << m_converted.size() ;
74 for ( Set::const_iterator item = m_converted.begin() ;
75 m_converted.end() != item ; ++item )
76 { log << std::endl << " '" << (*item) << "'" ; }
77 log << endmsg ;
78 }
79 }
80 return PersistencySvc::finalize();
81 }
82 // ============================================================================
83 // Initialize the service.
84 // ============================================================================
85 StatusCode HistogramPersistencySvc::initialize() {
86 StatusCode status = PersistencySvc::initialize();
87 if ( status.isSuccess() ) {
88 status = reinitialize();
89 }
90 return status;
91 }
92 // ============================================================================
93 // Reinitialize the service.
94 // ============================================================================
95 StatusCode HistogramPersistencySvc::reinitialize()
96 {
97 MsgStream log(msgSvc(), name());
98 // Obtain the IProperty of the ApplicationMgr
99 SmartIF<IProperty> prpMgr(serviceLocator());
100 if ( !prpMgr.isValid() ) {
101 log << MSG::FATAL << "IProperty interface not found in ApplicationMgr." << endmsg;
102 return StatusCode::FAILURE;
103 }
104 else {
105 setProperty(prpMgr->getProperty("HistogramPersistency")).ignore();
106 }
107
108 // To keep backward compatibility, we set the property of conversion service
109 // into JobOptions catalogue
110 if( m_outputFile != "" ) {
111 SmartIF<IJobOptionsSvc> joptsvc(serviceLocator()->service("JobOptionsSvc"));
112 if( joptsvc.isValid() ) {
113 StringProperty p("OutputFile", m_outputFile);
114 if ( m_histPersName == "ROOT" ) {
115 joptsvc->addPropertyToCatalogue("RootHistSvc", p).ignore();
116 } else if (m_histPersName == "HBOOK" ) {
117 joptsvc->addPropertyToCatalogue("HbookHistSvc", p).ignore();
118 }
119 }
120 }
121
122 // Load the Histogram persistency service that's required as default
123 setConversionSvc(0).ignore();
124 if ( m_histPersName == "ROOT" ) {
125 setConversionSvc(service("RootHistSvc")).ignore();
126 if ( !conversionSvc() ) {
127 return StatusCode::FAILURE;
128 }
129 enable(true);
130 }
131 else if ( m_histPersName == "HBOOK" ) {
132 setConversionSvc(service("HbookHistSvc")).ignore();
133 if ( !conversionSvc() ) {
134 return StatusCode::FAILURE;
135 }
136 enable(true);
137 }
138 else if ( m_histPersName == "NONE" ) {
139 enable(false);
140 if ( m_warnings ) {
141 log << MSG::WARNING << "Histograms saving not required." << endmsg;
142 }
143 }
144 else {
145 setConversionSvc(service(m_histPersName)).ignore();
146 if ( !conversionSvc() ) {
147 return StatusCode::FAILURE;
148 }
149 enable(true);
150 if ( m_warnings ) {
151 log << MSG::WARNING << "Unknown Histogram Persistency Mechanism " << m_histPersName << endmsg;
152 }
153 }
154 return StatusCode::SUCCESS;
155 }
156 // ============================================================================
157 namespace
158 {
159 // ==========================================================================
161 const std::string s_NULL = "<NULL>" ;
162 // ==========================================================================
168 // ==========================================================================
169 inline bool match
170 ( const std::string& name ,
171 const std::string& pat )
172 {
173 // the most primitive match
174 return std::string::npos != name.find ( pat );
175 }
176 // ==========================================================================
181 inline const std::string& oname ( const DataObject* obj )
182 {
183 if ( 0 == obj ) { return s_NULL ; }
184 const IRegistry* reg = obj->registry() ;
185 return ( 0 == reg ) ? obj -> name () : reg -> identifier () ;
186 }
187 // ==========================================================================
193 inline bool match ( const DataObject* obj ,
194 const std::string& pat )
195 {
196 if ( 0 == obj ) { return false ; }
197 return match ( oname ( obj ) , pat ) ;
198 }
199 // ==========================================================================
200 }
201 // ============================================================================
202 // Convert the transient object to the requested representation.
203 // ============================================================================
204 StatusCode HistogramPersistencySvc::createRep
205 ( DataObject* pObj ,
206 IOpaqueAddress*& refpAddr )
207 {
208 // enable the conversion
209 enable ( true ) ;
210 // conversion is possible ?
211 if ( "NONE" == m_histPersName )
212 {
213 enable ( false ) ;
214 return PersistencySvc::createRep ( pObj , refpAddr ) ; // RETURN
215 }
216 // histogram ?
217 if ( 0 != dynamic_cast<AIDA::IBaseHistogram*> ( pObj ) )
218 {
219 bool select = false ;
220 // Empty ConvertHistos property means convert all
221 if ( m_convert.empty() ) { select = true ; }
222 else
223 {
224 for ( Strings::const_iterator item = m_convert.begin() ;
225 m_convert.end() != item ; ++item )
226 { if ( match ( pObj , *item ) ) { select = true ; break ; } }
227 }
228 // exclude ?
229 for ( Strings::const_iterator item = m_exclude.begin() ;
230 m_exclude.end() != item && select ; ++item )
231 { if ( match ( pObj , *item ) ) { select = false ; break ; } }
232 //
233 enable ( select ) ;
234 //
235 const std::string& path = oname ( pObj ) ;
236 //
237 if ( !select ) { m_excluded.insert ( path ) ; }
238 else { m_converted.insert ( path ) ; }
239 }
240 //
241 return PersistencySvc::createRep ( pObj , refpAddr ) ; // RETURN
242 }
243 // ============================================================================
244 // Standard Constructor
245 // ============================================================================
246 HistogramPersistencySvc::HistogramPersistencySvc
247 ( const std::string& name ,
248 ISvcLocator* svc )
249 : PersistencySvc(name, svc)
250 //
251 , m_convert ()
252 , m_exclude ()
253 , m_converted ()
254 , m_excluded ()
255 //
256 {
257 std::vector<std::string> defServices;
258 defServices.push_back("RootHistSvc");
259 m_svcNames.set(defServices);
260 declareProperty ("HistogramPersistency", m_histPersName = "");
261 declareProperty ("OutputFile", m_outputFile = "");
262 //
263 declareProperty
264 ("ConvertHistos" , m_convert ,
265 "The list of patterns to be accepted for conversion" ) ;
266 //
267 declareProperty
268 ("ExcludeHistos" , m_exclude ,
269 "The list of patterns to be excluded for conversion" ) ;
270 declareProperty("Warnings",m_warnings=true,
271 "Set this property to false to suppress warning messages");
272 }
273 // ============================================================================
274 // Standard Destructor
275 // ============================================================================
276 HistogramPersistencySvc::~HistogramPersistencySvc() {}
277 // ============================================================================
278
279
280 // ============================================================================
281 // The END
282 // ============================================================================