The Gaudi Framework master (934d2c3c)
Loading...
Searching...
No Matches
HistogramPersistencySvc.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11// ============================================================================
12// HistogramPersistencySvc.cpp
13//--------------------------------------------------------------------
14//
15// Package : System ( The LHCb Offline System)
16//
17// Description: implementation of the Event data persistency service
18// This specialized service only deals with event related
19// data
20//
21// Author : M.Frank
22// History :
23// +---------+----------------------------------------------+---------
24// | Date | Comment | Who
25// +---------+----------------------------------------------+---------
26// | 29/10/98| Initial version | MF
27// +---------+----------------------------------------------+---------
28//
29//====================================================================
30// ============================================================================
31// Include files
32// ============================================================================
33// GaudiKernel
34// ============================================================================
40#include <GaudiKernel/SmartIF.h>
41// ============================================================================
42// local
43// ============================================================================
45// ============================================================================
46// AIDA
47// ============================================================================
49#ifdef __clang__
50# pragma clang diagnostic push
51# pragma clang diagnostic ignored "-Wkeyword-macro"
52#endif
53#define class class GAUDI_API
54#ifdef __clang__
55# pragma clang diagnostic pop
56#endif
57#include <AIDA/IBaseHistogram.h>
58#undef class
59// ============================================================================
60// Instantiation of a static factory class used by clients to create
61// instances of this service
63
64// ============================================================================
65// Finalize the service.
67 //
68 if ( !( m_convert.empty() && m_exclude.empty() ) ) { // print message if any of the two properties is used
69 info() << "Histograms Converted/Excluded: " << m_converted.size() << "/" << m_excluded.size() << endmsg;
70 }
71 if ( msgLevel( MSG::DEBUG ) ) {
72 if ( !m_excluded.empty() ) {
73 auto& log = debug();
74 log << "Excluded Histos : #" << m_excluded.size();
75 for ( const auto& item : m_excluded ) { log << std::endl << " '" << item << "'"; }
76 log << endmsg;
77 }
78 //
79 if ( !m_converted.empty() ) {
80 auto& log = debug();
81 log << "Converted Histos : #" << m_converted.size();
82 for ( const auto& item : m_converted ) { log << std::endl << " '" << item << "'"; }
83 log << endmsg;
84 }
85 }
87}
88// ============================================================================
89// Initialize the service.
90// ============================================================================
95// ============================================================================
96// Reinitialize the service.
97// ============================================================================
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 } else {
105 setProperty( prpMgr->getProperty( "HistogramPersistency" ) ).ignore();
106 }
107
108 // To keep backward compatibility, we set the property of conversion service
109 // into JobOptions catalogue
110 if ( !m_outputFile.empty() ) {
111 auto& opts = serviceLocator()->getOptsSvc();
112 const std::string outputFile = '"' + m_outputFile + '"';
113 if ( m_histPersName == "ROOT" ) {
114 opts.set( "RootHistSvc.OutputFile", outputFile );
115 } else if ( m_histPersName == "HBOOK" ) {
116 opts.set( "HbookHistSvc.OutputFile", outputFile );
117 }
118 }
119
120 // Load the Histogram persistency service that's required as default
121 setConversionSvc( nullptr ).ignore();
122 if ( m_histPersName == "ROOT" ) {
123 setConversionSvc( service( "RootHistSvc" ) ).ignore();
124 if ( !conversionSvc() ) { return StatusCode::FAILURE; }
125 enable( true );
126 } else if ( m_histPersName == "HBOOK" ) {
127 setConversionSvc( service( "HbookHistSvc" ) ).ignore();
128 if ( !conversionSvc() ) { return StatusCode::FAILURE; }
129 enable( true );
130 } else if ( m_histPersName == "NONE" ) {
131 enable( false );
132 if ( msgLevel( MSG::DEBUG ) ) debug() << "Histograms saving not required." << endmsg;
133 } else {
135 if ( !conversionSvc() ) { return StatusCode::FAILURE; }
136 enable( true );
137 if ( m_warnings ) { warning() << "Unknown Histogram Persistency Mechanism " << m_histPersName << endmsg; }
138 }
139 return StatusCode::SUCCESS;
140}
141// ============================================================================
142namespace {
143 // ==========================================================================
145 const std::string s_NULL = "<NULL>";
146 // ==========================================================================
152 // ==========================================================================
153 inline bool match( const std::string& name, const std::string& pat ) {
154 // the most primitive match
155 return std::string::npos != name.find( pat );
156 }
157 // ==========================================================================
162 inline const std::string& oname( const DataObject* obj ) {
163 if ( !obj ) { return s_NULL; }
164 auto reg = obj->registry();
165 return reg ? reg->identifier() : obj->name();
166 }
167 // ==========================================================================
173 inline bool match( const DataObject* obj, const std::string& pat ) { return obj && match( oname( obj ), pat ); }
174 // ==========================================================================
175} // namespace
176// ============================================================================
177// Convert the transient object to the requested representation.
178// ============================================================================
180 // enable the conversion
181 enable( true );
182 // conversion is possible ?
183 if ( m_histPersName == "NONE" ) {
184 enable( false );
185 return PersistencySvc::createRep( pObj, refpAddr ); // RETURN
186 }
187 // histogram ?
188 if ( dynamic_cast<AIDA::IBaseHistogram*>( pObj ) ) {
189
190 auto match_pObj = [&]( const std::string& s ) { return match( pObj, s ); };
191 // Empty ConvertHistos property means convert all
192 bool select = ( m_convert.empty() || std::any_of( m_convert.begin(), m_convert.end(), match_pObj ) ) &&
193 std::none_of( m_exclude.begin(), m_exclude.end(), match_pObj );
194 //
195 enable( select );
196 //
197 const auto& path = oname( pObj );
198 //
199 if ( !select ) {
200 m_excluded.insert( path );
201 } else {
202 m_converted.insert( path );
203 }
204 }
205 //
206 return PersistencySvc::createRep( pObj, refpAddr ); // RETURN
207}
208// ============================================================================
209// Standard Constructor
210// ============================================================================
212 : PersistencySvc( name, svc ) {
213 // bypass update handler
214 m_svcNames.value() = std::vector<std::string>{ { "RootHistSvc" } };
215}
216
217// ============================================================================
218// The END
219// ============================================================================
bool PyHelper setProperty(IInterface *p, char *name, char *value)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
complex< _Tp > log(const complex< _Tp > &)
constexpr bool any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
constexpr bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
static const size_type npos
void insert(_InputIterator __first, _InputIterator __last)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
const std::string & name() const
Retreive DataObject name. It is the name when registered in the store.
IRegistry * registry() const
Get pointer to Registry.
Definition DataObject.h:79
const ValueType & value() const
Definition Property.h:246
auto empty() const
Definition Property.h:272
auto begin() const
Definition Property.h:282
auto end() const
Definition Property.h:287
HistogramPersistencySvc class implementation definition.
Set m_converted
for the final report: the list of converted histograms
Gaudi::Property< std::string > m_histPersName
StatusCode initialize() override
Initialize the service.
HistogramPersistencySvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
StatusCode finalize() override
Finalize the service.
Gaudi::Property< std::vector< std::string > > m_convert
Gaudi::Property< bool > m_warnings
StatusCode reinitialize() override
Reinitialize the service.
Set m_excluded
for the final report: the list of excluded histograms
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
Gaudi::Property< std::string > m_outputFile
Gaudi::Property< std::vector< std::string > > m_exclude
Opaque address interface definition.
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition IProperty.h:32
virtual const id_type & identifier() const =0
Full identifier (or key).
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
SmartIF< IFace > as()
Definition ISvcLocator.h:64
Gaudi::Interfaces::IOptionsSvc & getOptsSvc()
Direct access to Gaudi::Interfaces::IOptionsSvc implementation.
PersistencySvc class implementation definition.
StatusCode setConversionSvc(IConversionSvc *svc) override
Set conversion service the converter is connected to.
Gaudi::Property< std::vector< std::string > > m_svcNames
SmartIF< IConversionSvc > conversionSvc() override
Get conversion service the converter is connected to.
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
StatusCode initialize() override
Initialize the service.
bool enable(bool value)
Set enabled flag.
StatusCode finalize() override
stop the service.
SmartIF< IConversionSvc > & service(const std::string &nam)
Retrieve conversion service by name.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
void ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:128
bool isSuccess() const
Definition StatusCode.h:302
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
@ DEBUG
Definition IMessageSvc.h:22