| The Gaudi Framework v27r1

- 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/SmartIF.h"
27 #include "GaudiKernel/MsgStream.h"
28 #include "GaudiKernel/ISvcLocator.h"
29 #include "GaudiKernel/IJobOptionsSvc.h"
30 #include "GaudiKernel/DataObject.h"
31 #include "GaudiKernel/IRegistry.h"
32 #include "GaudiKernel/IDataProviderSvc.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()) )
62 { // print message if any of the two properties is used
63 info() << "Histograms Converted/Excluded: "
64 << m_converted.size() << "/" << m_excluded.size() << endmsg ;
65 }
66 if (msgLevel(MSG::DEBUG)) {
67 if ( !m_excluded.empty() )
68 {
69 auto& log = debug();
70 log << "Excluded Histos : #" << m_excluded.size() ;
71 for ( const auto& item : m_excluded )
72 { log << std::endl << " '" << item << "'" ; }
73 log << endmsg ;
74 }
75 //
76 if ( !m_converted.empty() )
77 {
78 auto& log = debug();
79 log << "Converted Histos : #" << m_converted.size() ;
80 for ( const auto& item : m_converted )
81 { log << std::endl << " '" << item << "'" ; }
82 log << endmsg ;
83 }
84 }
85 return PersistencySvc::finalize();
86 }
87 // ============================================================================
88 // Initialize the service.
89 // ============================================================================
90 StatusCode HistogramPersistencySvc::initialize() {
91 StatusCode status = PersistencySvc::initialize();
92 return status.isSuccess() ? reinitialize() : status;
93 }
94 // ============================================================================
95 // Reinitialize the service.
96 // ============================================================================
97 StatusCode HistogramPersistencySvc::reinitialize()
98 {
99 // Obtain the IProperty of the ApplicationMgr
100 auto prpMgr = serviceLocator()->as<IProperty>();
101 if ( !prpMgr ) {
102 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.empty() ) {
112 auto joptsvc = serviceLocator()->service<IJobOptionsSvc> ("JobOptionsSvc");
113 if( joptsvc ) {
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
124 setConversionSvc(nullptr).ignore();
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 warning() << "Histograms saving not required." << endmsg;
143 }
144 }
145 else {
146 setConversionSvc(service(m_histPersName)).ignore();
147 if ( !conversionSvc() ) {
148 return StatusCode::FAILURE;
149 }
150 enable(true);
151 if ( m_warnings ) {
152 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 ( !obj ) { return s_NULL ; }
185 auto reg = obj->registry() ;
186 return reg ? reg -> identifier() : obj -> name () ;
187 }
188 // ==========================================================================
194 inline bool match ( const DataObject* obj ,
195 const std::string& pat )
196 {
197 return obj && 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 ( dynamic_cast<AIDA::IBaseHistogram*> ( pObj ) )
218 {
219
220 auto match_pObj = [&](const std::string& s) { return match( pObj , s ); };
221 // Empty ConvertHistos property means convert all
222 bool select = ( m_convert.empty()
223 || std::any_of( m_convert.begin(), m_convert.end(), match_pObj )
224 ) && std::none_of( m_exclude.begin(), m_exclude.end(), match_pObj );
225 //
226 enable ( select ) ;
227 //
228 const auto& path = oname ( pObj ) ;
229 //
230 if ( !select ) { m_excluded.insert ( path ) ; }
231 else { m_converted.insert ( path ) ; }
232 }
233 //
234 return PersistencySvc::createRep ( pObj , refpAddr ) ; // RETURN
235 }
236 // ============================================================================
237 // Standard Constructor
238 // ============================================================================
239 HistogramPersistencySvc::HistogramPersistencySvc
240 ( const std::string& name ,
241 ISvcLocator* svc )
242 : PersistencySvc(name, svc)
243 {
244 std::vector<std::string> defServices;
245 defServices.push_back("RootHistSvc");
246 m_svcNames.set(defServices);
247 declareProperty ("HistogramPersistency", m_histPersName = "");
248 declareProperty ("OutputFile", m_outputFile = "");
249 //
250 declareProperty
251 ("ConvertHistos" , m_convert ,
252 "The list of patterns to be accepted for conversion" ) ;
253 //
254 declareProperty
255 ("ExcludeHistos" , m_exclude ,
256 "The list of patterns to be excluded for conversion" ) ;
257 declareProperty("Warnings",m_warnings=true,
258 "Set this property to false to suppress warning messages");
259 }
260
261 // ============================================================================
262 // The END
263 // ============================================================================
PersistencySvc::service
SmartIF< IConversionSvc > & service(const std::string &nam)
Retrieve conversion service by name.
Definition: PersistencySvc.cpp:222
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
std::string::empty
T empty(T...args)
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
PersistencySvc::initialize
StatusCode initialize() override
Initialize the service.
Definition: PersistencySvc.cpp:536
MsgStream.h
Gaudi.Configuration.log
tuple log
Definition: Configuration.py:13
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
Service::setProperty
StatusCode setProperty(const Property &p) override
Definition: Service.cpp:330
PersistencySvc::setConversionSvc
StatusCode setConversionSvc(IConversionSvc *svc) override
Set conversion service the converter is connected to.
Definition: PersistencySvc.cpp:183
ISvcLocator::as
SmartIF< IFace > as()
Definition: ISvcLocator.h:106
HistogramPersistencySvc::reinitialize
StatusCode reinitialize() override
Reinitialize the service.
Definition: HistogramPersistencySvc.cpp:97
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
HistogramPersistencySvc::m_warnings
bool m_warnings
Flag to disable warning messages when using external input.
Definition: HistogramPersistencySvc.h:91
std::string
STL class.
SimpleProperty< std::string >
PersistencySvc::enable
bool enable(bool value)
Set enabled flag.
Definition: PersistencySvc.cpp:560
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:78
std::vector::push_back
T push_back(T...args)
IDataProviderSvc.h
IJobOptionsSvc
Main interface for the JobOptions service.
Definition: IJobOptionsSvc.h:20
HistogramPersistencySvc::initialize
StatusCode initialize() override
Initialize the service.
Definition: HistogramPersistencySvc.cpp:90
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
StatusCode::FAILURE
Definition: StatusCode.h:29
HistogramPersistencySvc.h
StatusCode::SUCCESS
Definition: StatusCode.h:30
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:133
PersistencySvc::finalize
StatusCode finalize() override
stop the service.
Definition: PersistencySvc.cpp:547
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:205
HistogramPersistencySvc::HistogramPersistencySvc
HistogramPersistencySvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: HistogramPersistencySvc.cpp:240
Gaudi::Utils::Histos::path
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
Definition: HistoTableFormat.cpp:191
std::string::find
T find(T...args)
PersistencySvc::conversionSvc
SmartIF< IConversionSvc > & conversionSvc() const override
Get conversion service the converter is connected to.
Definition: PersistencySvc.cpp:189
std::vector< std::string >
std::any_of
T any_of(T...args)
gaudirun.s
string s
Definition: gaudirun.py:245
ana.item
tuple item
print s1,s2
Definition: ana.py:146
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:108
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:112
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:21
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
HistogramPersistencySvc::m_outputFile
std::string m_outputFile
Name of the outputFile.
Definition: HistogramPersistencySvc.h:81
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
AnalysisInit.select
def select(list, sel)
Definition: AnalysisInit.py:29
DataObject.h
HistogramPersistencySvc::m_histPersName
std::string m_histPersName
Name of the Hist Pers type.
Definition: HistogramPersistencySvc.h:79
IJobOptionsSvc.h