| The Gaudi Framework v32r1 (f65d50dc)

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 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 // ============================================================================
83 StatusCode HistogramPersistencySvc::initialize() {
84 StatusCode status = PersistencySvc::initialize();
85 return status.isSuccess() ? reinitialize() : status;
86 }
87 // ============================================================================
88 // Reinitialize the service.
89 // ============================================================================
90 StatusCode HistogramPersistencySvc::reinitialize() {
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 {
128 setConversionSvc( service( m_histPersName ) ).ignore();
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 // ============================================================================
173 StatusCode HistogramPersistencySvc::createRep( DataObject* pObj, IOpaqueAddress*& refpAddr ) {
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 ) {
194 m_excluded.insert( path );
195 } else {
196 m_converted.insert( path );
197 }
198 }
199 //
200 return PersistencySvc::createRep( pObj, refpAddr ); // RETURN
201 }
202 // ============================================================================
203 // Standard Constructor
204 // ============================================================================
205 HistogramPersistencySvc::HistogramPersistencySvc( const std::string& name, ISvcLocator* svc )
206 : PersistencySvc( name, svc ) {
207 // bypass update handler
208 m_svcNames.value() = std::vector<std::string>{{"RootHistSvc"}};
209 }
210
211 // ============================================================================
212 // The END
213 // ============================================================================
PersistencySvc::service
SmartIF< IConversionSvc > & service(const std::string &nam)
Retrieve conversion service by name.
Definition: PersistencySvc.cpp:204
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:277
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:932
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
PersistencySvc::initialize
StatusCode initialize() override
Initialize the service.
Definition: PersistencySvc.cpp:489
HistogramPersistencySvc::m_convert
Gaudi::Property< std::vector< std::string > > m_convert
Definition: HistogramPersistencySvc.h:75
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >::setProperty
StatusCode setProperty(const Gaudi::Details::PropertyBase &p) override
set the property form another property
Definition: PropertyHolder.h:145
MsgStream.h
HistogramPersistencySvc::m_excluded
Set m_excluded
for the final report: the list of excluded histograms
Definition: HistogramPersistencySvc.h:84
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:101
PersistencySvc::m_svcNames
Gaudi::Property< std::vector< std::string > > m_svcNames
Definition: PersistencySvc.h:237
HistogramPersistencySvc::m_histPersName
Gaudi::Property< std::string > m_histPersName
Definition: HistogramPersistencySvc.h:73
MSG::DEBUG
Definition: IMessageSvc.h:15
std::endl
T endl(T... args)
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
PersistencySvc::setConversionSvc
StatusCode setConversionSvc(IConversionSvc *svc) override
Set conversion service the converter is connected to.
Definition: PersistencySvc.cpp:171
ISvcLocator::as
SmartIF< IFace > as()
Definition: ISvcLocator.h:103
HistogramPersistencySvc::reinitialize
StatusCode reinitialize() override
Reinitialize the service.
Definition: HistogramPersistencySvc.cpp:90
HistogramPersistencySvc::m_converted
Set m_converted
for the final report: the list of converted histograms
Definition: HistogramPersistencySvc.h:82
HistogramPersistencySvc::m_outputFile
Gaudi::Property< std::string > m_outputFile
Definition: HistogramPersistencySvc.h:74
std::string
STL class.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
HistogramPersistencySvc::m_exclude
Gaudi::Property< std::vector< std::string > > m_exclude
Definition: HistogramPersistencySvc.h:77
PersistencySvc::enable
bool enable(bool value)
Set enabled flag.
Definition: PersistencySvc.cpp:507
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:76
IDataProviderSvc.h
IJobOptionsSvc
Main interface for the JobOptions service.
Definition: IJobOptionsSvc.h:20
HistogramPersistencySvc::initialize
StatusCode initialize() override
Initialize the service.
Definition: HistogramPersistencySvc.cpp:83
HistogramPersistencySvc::m_warnings
Gaudi::Property< bool > m_warnings
Definition: HistogramPersistencySvc.h:79
HistogramPersistencySvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
PersistencySvc::createRep
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
Definition: PersistencySvc.cpp:125
PersistencySvc::finalize
StatusCode finalize() override
stop the service.
Definition: PersistencySvc.cpp:498
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:173
HistogramPersistencySvc::HistogramPersistencySvc
HistogramPersistencySvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: HistogramPersistencySvc.cpp:205
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
DataObject::name
const std::string & name() const
Retreive DataObject name. It is the name when registered in the store.
Definition: DataObject.cpp:62
std::set::insert
T insert(T... args)
PersistencySvc::conversionSvc
SmartIF< IConversionSvc > & conversionSvc() const override
Get conversion service the converter is connected to.
Definition: PersistencySvc.cpp:177
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
std::vector< std::string >
std::any_of
T any_of(T... args)
gaudirun.s
string s
Definition: gaudirun.py:316
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
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
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:92
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
DataObject.h
Gaudi.Configuration.log
log
Definition: Configuration.py:13
IJobOptionsSvc.h