Gaudi Framework, version v24r2

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

Generated at Wed Dec 4 2013 14:33:07 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004