| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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"
27 #include "GaudiKernel/IDataProviderSvc.h"
28 #include "GaudiKernel/IJobOptionsSvc.h"
29 #include "GaudiKernel/IRegistry.h"
30 #include "GaudiKernel/ISvcLocator.h"
31 #include "GaudiKernel/MsgStream.h"
32 #include "GaudiKernel/SmartIF.h"
33 // ============================================================================
34 // local
35 // ============================================================================
36 #include "HistogramPersistencySvc.h"
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
54 DECLARE_COMPONENT( HistogramPersistencySvc )
55
56 // ============================================================================
57 // Finalize the service.
58 StatusCode HistogramPersistencySvc::finalize()
59 {
60 //
61 if ( !( m_convert.empty() && m_exclude.empty() ) ) { // print message if any of the two properties is used
62 info() << "Histograms Converted/Excluded: " << m_converted.size() << "/" << m_excluded.size() << endmsg;
63 }
64 if ( msgLevel( MSG::DEBUG ) ) {
65 if ( !m_excluded.empty() ) {
66 auto& log = debug();
67 log << "Excluded Histos : #" << m_excluded.size();
68 for ( const auto& item : m_excluded ) {
69 log << std::endl << " '" << item << "'";
70 }
71 log << endmsg;
72 }
73 //
74 if ( !m_converted.empty() ) {
75 auto& log = debug();
76 log << "Converted Histos : #" << m_converted.size();
77 for ( const auto& item : m_converted ) {
78 log << std::endl << " '" << item << "'";
79 }
80 log << endmsg;
81 }
82 }
83 return PersistencySvc::finalize();
84 }
85 // ============================================================================
86 // Initialize the service.
87 // ============================================================================
88 StatusCode HistogramPersistencySvc::initialize()
89 {
90 StatusCode status = PersistencySvc::initialize();
91 return status.isSuccess() ? reinitialize() : status;
92 }
93 // ============================================================================
94 // Reinitialize the service.
95 // ============================================================================
96 StatusCode HistogramPersistencySvc::reinitialize()
97 {
98 // Obtain the IProperty of the ApplicationMgr
99 auto prpMgr = serviceLocator()->as<IProperty>();
100 if ( !prpMgr ) {
101 fatal() << "IProperty interface not found in ApplicationMgr." << endmsg;
102 return StatusCode::FAILURE;
103 } else {
104 setProperty( prpMgr->getProperty( "HistogramPersistency" ) ).ignore();
105 }
106
107 // To keep backward compatibility, we set the property of conversion service
108 // into JobOptions catalogue
109 if ( !m_outputFile.empty() ) {
110 auto joptsvc = serviceLocator()->service<IJobOptionsSvc>( "JobOptionsSvc" );
111 if ( joptsvc ) {
112 Gaudi::Property<std::string> p( "OutputFile", m_outputFile );
113 if ( m_histPersName == "ROOT" ) {
114 joptsvc->addPropertyToCatalogue( "RootHistSvc", p ).ignore();
115 } else if ( m_histPersName == "HBOOK" ) {
116 joptsvc->addPropertyToCatalogue( "HbookHistSvc", p ).ignore();
117 }
118 }
119 }
120
121 // Load the Histogram persistency service that's required as default
122 setConversionSvc( nullptr ).ignore();
123 if ( m_histPersName == "ROOT" ) {
124 setConversionSvc( service( "RootHistSvc" ) ).ignore();
125 if ( !conversionSvc() ) {
126 return StatusCode::FAILURE;
127 }
128 enable( true );
129 } else if ( m_histPersName == "HBOOK" ) {
130 setConversionSvc( service( "HbookHistSvc" ) ).ignore();
131 if ( !conversionSvc() ) {
132 return StatusCode::FAILURE;
133 }
134 enable( true );
135 } else if ( m_histPersName == "NONE" ) {
136 enable( false );
137 if ( m_warnings ) {
138 warning() << "Histograms saving not required." << endmsg;
139 }
140 } else {
141 setConversionSvc( service( m_histPersName ) ).ignore();
142 if ( !conversionSvc() ) {
143 return StatusCode::FAILURE;
144 }
145 enable( true );
146 if ( m_warnings ) {
147 warning() << "Unknown Histogram Persistency Mechanism " << m_histPersName << endmsg;
148 }
149 }
150 return StatusCode::SUCCESS;
151 }
152 // ============================================================================
153 namespace
154 {
155 // ==========================================================================
157 const std::string s_NULL = "<NULL>";
158 // ==========================================================================
164 // ==========================================================================
165 inline bool match( const std::string& name, const std::string& pat )
166 {
167 // the most primitive match
168 return std::string::npos != name.find( pat );
169 }
170 // ==========================================================================
175 inline const std::string& oname( const DataObject* obj )
176 {
177 if ( !obj ) {
178 return s_NULL;
179 }
180 auto reg = obj->registry();
181 return reg ? reg->identifier() : obj->name();
182 }
183 // ==========================================================================
189 inline bool match( const DataObject* obj, const std::string& pat ) { return obj && match( oname( obj ), pat ); }
190 // ==========================================================================
191 }
192 // ============================================================================
193 // Convert the transient object to the requested representation.
194 // ============================================================================
195 StatusCode HistogramPersistencySvc::createRep( DataObject* pObj, IOpaqueAddress*& refpAddr )
196 {
197 // enable the conversion
198 enable( true );
199 // conversion is possible ?
200 if ( "NONE" == m_histPersName ) {
201 enable( false );
202 return PersistencySvc::createRep( pObj, refpAddr ); // RETURN
203 }
204 // histogram ?
205 if ( dynamic_cast<AIDA::IBaseHistogram*>( pObj ) ) {
206
207 auto match_pObj = [&]( const std::string& s ) { return match( pObj, s ); };
208 // Empty ConvertHistos property means convert all
209 bool select = ( m_convert.empty() || std::any_of( m_convert.begin(), m_convert.end(), match_pObj ) ) &&
210 std::none_of( m_exclude.begin(), m_exclude.end(), match_pObj );
211 //
212 enable( select );
213 //
214 const auto& path = oname( pObj );
215 //
216 if ( !select ) {
217 m_excluded.insert( path );
218 } else {
219 m_converted.insert( path );
220 }
221 }
222 //
223 return PersistencySvc::createRep( pObj, refpAddr ); // RETURN
224 }
225 // ============================================================================
226 // Standard Constructor
227 // ============================================================================
228 HistogramPersistencySvc::HistogramPersistencySvc( const std::string& name, ISvcLocator* svc )
229 : PersistencySvc( name, svc )
230 {
231 // bypass update handler
232 m_svcNames.value() = std::vector<std::string>{{"RootHistSvc"}};
233 }
234
235 // ============================================================================
236 // The END
237 // ============================================================================
PersistencySvc::service
SmartIF< IConversionSvc > & service(const std::string &nam)
Retrieve conversion service by name.
Definition: PersistencySvc.cpp:226
StatusCode::SUCCESS
Definition: StatusCode.h:29
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:895
PersistencySvc::initialize
StatusCode initialize() override
Initialize the service.
Definition: PersistencySvc.cpp:525
HistogramPersistencySvc::m_convert
Gaudi::Property< std::vector< std::string > > m_convert
Definition: HistogramPersistencySvc.h:78
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:319
PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >::setProperty
StatusCode setProperty(const Gaudi::Details::PropertyBase &p) override
set the property form another property
Definition: PropertyHolder.h:208
MsgStream.h
HistogramPersistencySvc::m_excluded
Set m_excluded
for the final report: the list of excluded histograms
Definition: HistogramPersistencySvc.h:87
PersistencySvc::m_svcNames
Gaudi::Property< std::vector< std::string > > m_svcNames
Definition: PersistencySvc.h:248
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
HistogramPersistencySvc::m_histPersName
Gaudi::Property< std::string > m_histPersName
Definition: HistogramPersistencySvc.h:76
MSG::DEBUG
Definition: IMessageSvc.h:16
std::endl
T endl(T...args)
PersistencySvc::setConversionSvc
StatusCode setConversionSvc(IConversionSvc *svc) override
Set conversion service the converter is connected to.
Definition: PersistencySvc.cpp:190
ISvcLocator::as
SmartIF< IFace > as()
Definition: ISvcLocator.h:109
HistogramPersistencySvc::reinitialize
StatusCode reinitialize() override
Reinitialize the service.
Definition: HistogramPersistencySvc.cpp:96
HistogramPersistencySvc::m_converted
Set m_converted
for the final report: the list of converted histograms
Definition: HistogramPersistencySvc.h:85
HistogramPersistencySvc::m_outputFile
Gaudi::Property< std::string > m_outputFile
Definition: HistogramPersistencySvc.h:77
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:73
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
std::string
STL class.
HistogramPersistencySvc::m_exclude
Gaudi::Property< std::vector< std::string > > m_exclude
Definition: HistogramPersistencySvc.h:80
PersistencySvc::enable
bool enable(bool value)
Set enabled flag.
Definition: PersistencySvc.cpp:549
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
IDataProviderSvc.h
IJobOptionsSvc
Main interface for the JobOptions service.
Definition: IJobOptionsSvc.h:20
HistogramPersistencySvc::initialize
StatusCode initialize() override
Initialize the service.
Definition: HistogramPersistencySvc.cpp:88
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:109
HistogramPersistencySvc::m_warnings
Gaudi::Property< bool > m_warnings
Definition: HistogramPersistencySvc.h:82
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
HistogramPersistencySvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
PersistencySvc::createRep
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
Definition: PersistencySvc.cpp:136
PersistencySvc::finalize
StatusCode finalize() override
stop the service.
Definition: PersistencySvc.cpp:537
SmartIF.h
IRegistry.h
PersistencySvc
PersistencySvc class implementation definition.
Definition: PersistencySvc.h:50
HistogramPersistencySvc
HistogramPersistencySvc class implementation definition.
Definition: HistogramPersistencySvc.h:47
HistogramPersistencySvc::createRep
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
Definition: HistogramPersistencySvc.cpp:195
PersistencySvc::conversionSvc
SmartIF< IConversionSvc > & conversionSvc() const override
Get conversion service the converter is connected to.
Definition: PersistencySvc.cpp:197
HistogramPersistencySvc::HistogramPersistencySvc
HistogramPersistencySvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: HistogramPersistencySvc.cpp:228
std::set::insert
T insert(T...args)
std::string::find
T find(T...args)
std::vector< std::string >
std::any_of
T any_of(T...args)
gaudirun.s
string s
Definition: gaudirun.py:253
DataObject::name
const std::string & name() const
Retreive DataObject name. It is the name when registered in the store.
Definition: DataObject.cpp:68
StatusCode::FAILURE
Definition: StatusCode.h:29
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:84
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:100
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:20
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
ISvcLocator.h
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:292
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
DataObject.h
Gaudi.Configuration.log
log
Definition: Configuration.py:13
IJobOptionsSvc.h