Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HistogramPersistencySvc.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // HistogramPersistencySvc.cpp
3 //--------------------------------------------------------------------
4 //
5 // Package : System ( The LHCb Offline System)
6 //
7 // Description: implementation of the Event data persistency service
8 // This specialized service only deals with event related
9 // data
10 //
11 // Author : M.Frank
12 // History :
13 // +---------+----------------------------------------------+---------
14 // | Date | Comment | Who
15 // +---------+----------------------------------------------+---------
16 // | 29/10/98| Initial version | MF
17 // +---------+----------------------------------------------+---------
18 //
19 //====================================================================
20 #define PERSISTENCYSVC_HISTOGRAMPERSISTENCYSVC_CPP
21 // ============================================================================
22 // Include files
23 // ============================================================================
24 // GaudiKernel
25 // ============================================================================
26 #include "GaudiKernel/DataObject.h"
29 #include "GaudiKernel/IRegistry.h"
31 #include "GaudiKernel/MsgStream.h"
32 #include "GaudiKernel/SmartIF.h"
33 // ============================================================================
34 // local
35 // ============================================================================
37 // ============================================================================
38 // AIDA
39 // ============================================================================
41 #ifdef __clang__
42 # pragma clang diagnostic push
43 # pragma clang diagnostic ignored "-Wkeyword-macro"
44 #endif
45 #define class class GAUDI_API
46 #ifdef __clang__
47 # pragma clang diagnostic pop
48 #endif
49 #include "AIDA/IBaseHistogram.h"
50 #undef class
51 // ============================================================================
52 // Instantiation of a static factory class used by clients to create
53 // instances of this service
55 
56 // ============================================================================
57 // Finalize the service.
59  //
60  if ( !( m_convert.empty() && m_exclude.empty() ) ) { // print message if any of the two properties is used
61  info() << "Histograms Converted/Excluded: " << m_converted.size() << "/" << m_excluded.size() << endmsg;
62  }
63  if ( msgLevel( MSG::DEBUG ) ) {
64  if ( !m_excluded.empty() ) {
65  auto& log = debug();
66  log << "Excluded Histos : #" << m_excluded.size();
67  for ( const auto& item : m_excluded ) { log << std::endl << " '" << item << "'"; }
68  log << endmsg;
69  }
70  //
71  if ( !m_converted.empty() ) {
72  auto& log = debug();
73  log << "Converted Histos : #" << m_converted.size();
74  for ( const auto& item : m_converted ) { log << std::endl << " '" << item << "'"; }
75  log << endmsg;
76  }
77  }
78  return PersistencySvc::finalize();
79 }
80 // ============================================================================
81 // Initialize the service.
82 // ============================================================================
85  return status.isSuccess() ? reinitialize() : status;
86 }
87 // ============================================================================
88 // Reinitialize the service.
89 // ============================================================================
91  // Obtain the IProperty of the ApplicationMgr
92  auto prpMgr = serviceLocator()->as<IProperty>();
93  if ( !prpMgr ) {
94  fatal() << "IProperty interface not found in ApplicationMgr." << endmsg;
95  return StatusCode::FAILURE;
96  } else {
97  setProperty( prpMgr->getProperty( "HistogramPersistency" ) ).ignore();
98  }
99 
100  // To keep backward compatibility, we set the property of conversion service
101  // into JobOptions catalogue
102  if ( !m_outputFile.empty() ) {
103  auto joptsvc = serviceLocator()->service<IJobOptionsSvc>( "JobOptionsSvc" );
104  if ( joptsvc ) {
105  Gaudi::Property<std::string> p( "OutputFile", m_outputFile );
106  if ( m_histPersName == "ROOT" ) {
107  joptsvc->addPropertyToCatalogue( "RootHistSvc", p ).ignore();
108  } else if ( m_histPersName == "HBOOK" ) {
109  joptsvc->addPropertyToCatalogue( "HbookHistSvc", p ).ignore();
110  }
111  }
112  }
113 
114  // Load the Histogram persistency service that's required as default
115  setConversionSvc( nullptr ).ignore();
116  if ( m_histPersName == "ROOT" ) {
117  setConversionSvc( service( "RootHistSvc" ) ).ignore();
118  if ( !conversionSvc() ) { return StatusCode::FAILURE; }
119  enable( true );
120  } else if ( m_histPersName == "HBOOK" ) {
121  setConversionSvc( service( "HbookHistSvc" ) ).ignore();
122  if ( !conversionSvc() ) { return StatusCode::FAILURE; }
123  enable( true );
124  } else if ( m_histPersName == "NONE" ) {
125  enable( false );
126  if ( m_warnings ) { warning() << "Histograms saving not required." << endmsg; }
127  } else {
129  if ( !conversionSvc() ) { return StatusCode::FAILURE; }
130  enable( true );
131  if ( m_warnings ) { warning() << "Unknown Histogram Persistency Mechanism " << m_histPersName << endmsg; }
132  }
133  return StatusCode::SUCCESS;
134 }
135 // ============================================================================
136 namespace {
137  // ==========================================================================
139  const std::string s_NULL = "<NULL>";
140  // ==========================================================================
146  // ==========================================================================
147  inline bool match( const std::string& name, const std::string& pat ) {
148  // the most primitive match
149  return std::string::npos != name.find( pat );
150  }
151  // ==========================================================================
156  inline const std::string& oname( const DataObject* obj ) {
157  if ( !obj ) { return s_NULL; }
158  auto reg = obj->registry();
159  return reg ? reg->identifier() : obj->name();
160  }
161  // ==========================================================================
167  inline bool match( const DataObject* obj, const std::string& pat ) { return obj && match( oname( obj ), pat ); }
168  // ==========================================================================
169 } // namespace
170 // ============================================================================
171 // Convert the transient object to the requested representation.
172 // ============================================================================
174  // enable the conversion
175  enable( true );
176  // conversion is possible ?
177  if ( "NONE" == m_histPersName ) {
178  enable( false );
179  return PersistencySvc::createRep( pObj, refpAddr ); // RETURN
180  }
181  // histogram ?
182  if ( dynamic_cast<AIDA::IBaseHistogram*>( pObj ) ) {
183 
184  auto match_pObj = [&]( const std::string& s ) { return match( pObj, s ); };
185  // Empty ConvertHistos property means convert all
186  bool select = ( m_convert.empty() || std::any_of( m_convert.begin(), m_convert.end(), match_pObj ) ) &&
187  std::none_of( m_exclude.begin(), m_exclude.end(), match_pObj );
188  //
189  enable( select );
190  //
191  const auto& path = oname( pObj );
192  //
193  if ( !select ) {
195  } else {
197  }
198  }
199  //
200  return PersistencySvc::createRep( pObj, refpAddr ); // RETURN
201 }
202 // ============================================================================
203 // Standard Constructor
204 // ============================================================================
206  : PersistencySvc( name, svc ) {
207  // bypass update handler
208  m_svcNames.value() = std::vector<std::string>{{"RootHistSvc"}};
209 }
210 
211 // ============================================================================
212 // The END
213 // ============================================================================
SmartIF< IConversionSvc > & service(const std::string &nam)
Retrieve conversion service by name.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
StatusCode initialize() override
Initialize the service.
Gaudi::Property< std::vector< std::string > > m_convert
Implementation of property with value of concrete type.
Definition: Property.h:352
StatusCode setProperty(const Gaudi::Details::PropertyBase &p) override
set the property form another property
Set m_excluded
for the final report: the list of excluded histograms
Gaudi::Property< std::vector< std::string > > m_svcNames
bool isSuccess() const
Definition: StatusCode.h:267
Gaudi::Property< std::string > m_histPersName
T endl(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
StatusCode setConversionSvc(IConversionSvc *svc) override
Set conversion service the converter is connected to.
SmartIF< IFace > as()
Definition: ISvcLocator.h:103
StatusCode reinitialize() override
Reinitialize the service.
Set m_converted
for the final report: the list of converted histograms
Gaudi::Property< std::string > m_outputFile
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
STL class.
#define DECLARE_COMPONENT(type)
Gaudi::Property< std::vector< std::string > > m_exclude
bool enable(bool value)
Set enabled flag.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
Main interface for the JobOptions service.
StatusCode initialize() override
Initialize the service.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Gaudi::Property< bool > m_warnings
virtual const id_type & identifier() const =0
Full identifier (or key)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
StatusCode finalize() override
stop the service.
PersistencySvc class implementation definition.
HistogramPersistencySvc class implementation definition.
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
SmartIF< IConversionSvc > & conversionSvc() const override
Get conversion service the converter is connected to.
HistogramPersistencySvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
T insert(T...args)
T find(T...args)
T any_of(T...args)
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
string s
Definition: gaudirun.py:312
constexpr static const auto FAILURE
Definition: StatusCode.h:86
const std::string & name() const
Retreive DataObject name. It is the name when registered in the store.
Definition: DataObject.cpp:62
Opaque address interface definition.
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:20
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:277
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192