The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
Gaudi::Monitoring::MessageSvcSink Struct Reference

Sink dedicated to printing messages to the MessageSvc. More...

Inheritance diagram for Gaudi::Monitoring::MessageSvcSink:
Collaboration diagram for Gaudi::Monitoring::MessageSvcSink:

Public Member Functions

 MessageSvcSink (const std::string &name, ISvcLocator *svcloc)
void flush (bool) override
 stop method, handles the printing
Public Member Functions inherited from Gaudi::Monitoring::BaseSink
StatusCode initialize () override
void registerEntity (Hub::Entity ent) override
 handles registration of a new entity
void removeEntity (Hub::Entity const &ent) override
 handles removal of an entity
StatusCode start () override
StatusCode stop () override
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
StatusCode configure () override
StatusCode initialize () override
StatusCode start () override
StatusCode stop () override
StatusCode finalize () override
StatusCode terminate () override
Gaudi::StateMachine::State FSMState () const override
Gaudi::StateMachine::State targetFSMState () const override
StatusCode reinitialize () override
StatusCode restart () override
StatusCode sysInitialize () override
 Initialize Service.
StatusCode sysStart () override
 Initialize Service.
StatusCode sysStop () override
 Initialize Service.
StatusCode sysFinalize () override
 Finalize Service.
StatusCode sysReinitialize () override
 Re-initialize the Service.
StatusCode sysRestart () override
 Re-initialize the Service.
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
template<class T>
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
template<class T>
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
const std::vector< IAlgTool * > & tools () const
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 PropertyHolder ()=default
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
Gaudi::Details::PropertyBase * declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
Gaudi::Details::PropertyBase * property (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
PropertyHolder & operator= (const PropertyHolder &)=delete
Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
MsgStream & msgStream () const
 Return an uninitialized MsgStream.
MsgStream & msgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
MsgStream & always () const
 shortcut for the method msgStream(MSG::ALWAYS)
MsgStream & fatal () const
 shortcut for the method msgStream(MSG::FATAL)
MsgStream & err () const
 shortcut for the method msgStream(MSG::ERROR)
MsgStream & error () const
 shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning () const
 shortcut for the method msgStream(MSG::WARNING)
MsgStream & info () const
 shortcut for the method msgStream(MSG::INFO)
MsgStream & debug () const
 shortcut for the method msgStream(MSG::DEBUG)
MsgStream & verbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & msg () const
 shortcut for the method msgStream(MSG::INFO)
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
Public Member Functions inherited from Gaudi::Monitoring::Hub::Sink
virtual ~Sink ()=default

Public Attributes

Gaudi::Property< unsigned int > m_histoStringsWidth

Additional Inherited Members

Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
Protected Member Functions inherited from Gaudi::Monitoring::BaseSink
template<typename Callable>
void applyToAllEntities (Callable func) const
 applies a callable to all monitoring entities
template<typename Callable>
void applyToAllSortedEntities (Callable func) const
 applies a callable to all monitoring entities ordered by component the callable will be called once per entity and should have a signature ( std::string const&, std::string const&, nlohmann::json const& )
bool wanted (std::string const &name, std::vector< std::string > const &searchNames)
 deciding whether a given name matches the list of regexps given empty list means everything matches
Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 ~Service () override
int outputLevel () const
 get the Service's output level
Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const override final
 Set up local caches.
MSG::Level resetMessaging ()
 Reinitialize internal states.
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
Protected Attributes inherited from Gaudi::Monitoring::BaseSink
std::set< Gaudi::Monitoring::Hub::Entity, EntityOrder > m_monitoringEntities
Gaudi::Property< std::vector< std::string > > m_namesToSave
Gaudi::Property< std::vector< std::string > > m_componentsToSave
Gaudi::Property< std::vector< std::string > > m_typesToSave
std::thread m_flushThread
 Handling of regular flushes, if requested.
std::promise< void > m_flushThreadStop
Gaudi::Property< float > m_autoFlushPeriod
Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
Gaudi::Property< bool > m_autoRetrieveTools
Gaudi::Property< bool > m_checkToolDeps
SmartIF< IAuditorSvc > m_pAuditorSvc
 Auditor Service.

Detailed Description

Sink dedicated to printing messages to the MessageSvc.

Deals with counters and histograms at this stage. Relies on these entities to have a "type" entry in their json following the convention described in Accumulators.h

Definition at line 202 of file MessageSvcSink.cpp.

Constructor & Destructor Documentation

◆ MessageSvcSink()

Gaudi::Monitoring::MessageSvcSink::MessageSvcSink ( const std::string & name,
ISvcLocator * svcloc )
inline

Definition at line 203 of file MessageSvcSink.cpp.

203 : BaseSink( name, svcloc ) {
204 // only deal with counters, statentity and histograms
205 setProperty( "TypesToSave", std::vector<std::string>{ "counter:.*", "statentity", "histogram:.*" } )
206 .orThrow( "Unable to set TypesToSave property", "Gaudi::Monitoring::MessageSvcSink" );
207 // require a non-empty name for the owner
208 setProperty( "ComponentsToSave", std::vector<std::string>{ "^.+$" } )
209 .orThrow( "Unable to set ComponentsToSave property", "Gaudi::Monitoring::MessageSvcSink" );
210 }
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333

Member Function Documentation

◆ flush()

void Gaudi::Monitoring::MessageSvcSink::flush ( bool )
overridevirtual

stop method, handles the printing

Implements Gaudi::Monitoring::BaseSink.

Definition at line 220 of file MessageSvcSink.cpp.

220 {
221 std::string curAlgo = "";
222 // an array of counters, separating (in this order)
223 // regular counters from 1d / 2d / 3d histograms, from
224 // 1d / 2d / 3d profile histograms
225 std::array<std::ostringstream, 7> curLog;
226 // associated counters of non empty entities, in order
227 // to know whether to print or not the given section
228 std::array<unsigned int, 7> nbNonEmptyEntities{};
229 auto dumpAlgoCounters = [&]() {
230 MsgStream log{ msgSvc(), curAlgo };
231 // Regular counters first
232 if ( nbNonEmptyEntities[0] > 0 ) {
233 log << MSG::INFO << "Number of counters : " << nbNonEmptyEntities[0] << "\n"
234 << " | Counter | # | "
235 << " sum | mean/eff^* | rms/err^* | min | max |";
236 log << curLog[0].str() << endmsg;
237 }
238 // Now histograms
239 unsigned int nHistos = nbNonEmptyEntities[1] + nbNonEmptyEntities[2] + nbNonEmptyEntities[3] +
240 nbNonEmptyEntities[4] + nbNonEmptyEntities[5] + nbNonEmptyEntities[6];
241 if ( nHistos > 0 ) {
242 log << MSG::INFO << "Booked " << nHistos << " Histogram(s) : 1D=" << nbNonEmptyEntities[1]
243 << " 2D=" << nbNonEmptyEntities[2] << " 3D=" << nbNonEmptyEntities[3] << " 1DProf=" << nbNonEmptyEntities[4]
244 << " 2DProf=" << nbNonEmptyEntities[5] << " 3DProf=" << nbNonEmptyEntities[6] << endmsg;
245 if ( nbNonEmptyEntities[1] > 0 ) {
246 log << MSG::INFO << "1D histograms in directory \"" << curAlgo << "\" : " << nbNonEmptyEntities[1] << "\n"
247 << fmt::format(
248 fmt::runtime(
249 " | {:{}s} | {:{}s} | # | Mean | RMS | Skewness | Kurtosis |" ),
250 "ID", m_histoStringsWidth.value(), "Title", m_histoStringsWidth.value() )
251 << curLog[1].str() << endmsg;
252 }
253 if ( nbNonEmptyEntities[2] > 0 ) {
254 log << MSG::INFO << "2D histograms in directory \"" << curAlgo << "\" : " << nbNonEmptyEntities[2]
255 << curLog[2].str() << endmsg;
256 }
257 if ( nbNonEmptyEntities[3] > 0 ) {
258 log << MSG::INFO << "3D histograms in directory \"" << curAlgo << "\" : " << nbNonEmptyEntities[3]
259 << curLog[3].str() << endmsg;
260 }
261 if ( nbNonEmptyEntities[4] > 0 ) {
262 log << MSG::INFO << "1D profile histograms in directory \"" << curAlgo << "\" : " << nbNonEmptyEntities[4]
263 << "\n"
264 << fmt::format(
265 fmt::runtime(
266 " | {:{}s} | {:{}s} | # | Mean | RMS | Skewness | Kurtosis |" ),
267 "ID", m_histoStringsWidth.value(), "Title", m_histoStringsWidth.value() )
268 << curLog[4].str() << endmsg;
269 }
270 if ( nbNonEmptyEntities[5] > 0 ) {
271 log << MSG::INFO << "2D profile histograms in directory \"" << curAlgo << "\" : " << nbNonEmptyEntities[5]
272 << curLog[5].str() << endmsg;
273 }
274 if ( nbNonEmptyEntities[6] > 0 ) {
275 log << MSG::INFO << "3D profile histograms in directory \"" << curAlgo << "\" : " << nbNonEmptyEntities[6]
276 << curLog[6].str() << endmsg;
277 }
278 }
279 };
281 [&]( std::string const& algo, std::string const& name, Monitoring::Hub::Entity const& ent ) {
282 // Did we change to new component ?
283 if ( algo != curAlgo ) {
284 dumpAlgoCounters();
285 curAlgo = algo;
286 nbNonEmptyEntities = { 0, 0, 0, 0, 0, 0, 0 };
287 curLog = { std::ostringstream{}, std::ostringstream{}, std::ostringstream{}, std::ostringstream{},
288 std::ostringstream{}, std::ostringstream{}, std::ostringstream{} };
289 }
290 // first try dedicated binary printers for profile histograms
291 auto typeIndex = ent.typeIndex();
292 auto binWriter = binRegistry.find( typeIndex );
293 if ( binWriter != binRegistry.end() ) {
294 auto index = binWriter->second.first;
295 ++nbNonEmptyEntities[index];
296 std::string logLine = binWriter->second.second( name, ent, m_histoStringsWidth );
297 if ( logLine.size() > 0 ) { curLog[index] << "\n" << logLine; }
298 } else {
299 // use json representation of the entity
300 nlohmann::json const j = ent;
301 // do we have an histogram ?
302 const auto type = j.at( "type" ).get<std::string>();
303 if ( type.find( "histogram" ) == 0 ) {
304 if ( !j.at( "empty" ).template get<bool>() ) {
305 unsigned int d = j.at( "dimension" ).get<int>();
306 auto subtype = std::string_view( type ).substr( 10 ); // remove "histogram:" in front
307 bool isProfile = subtype.substr( 0, 15 ) == "WeightedProfile" || subtype.substr( 0, 7 ) == "Profile";
308 unsigned int index = ( isProfile ? 3 : 0 ) + d;
309 auto title = j.at( "title" ).get<std::string>();
310 std::string logLine{ "" };
311 switch ( d ) {
312 case 1:
314 break;
315 case 2:
317 break;
318 case 3:
320 break;
321 }
322 if ( logLine.size() > 0 ) {
323 curLog[index] << "\n" << logLine;
324 ++nbNonEmptyEntities[index];
325 }
326 }
327 } else {
328 // regular counter. Is current counter empty ?
329 if ( !j.at( "empty" ).template get<bool>() ) {
330 ++nbNonEmptyEntities[0];
331 curLog[0] << "\n";
332 printCounter( curLog[0], name, j );
333 }
334 }
335 }
336 } );
337 // last component
338 dumpAlgoCounters();
339}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
void applyToAllSortedEntities(Callable func) const
applies a callable to all monitoring entities ordered by component the callable will be called once p...
Definition BaseSink.h:111
std::string printHistogram1D(std::string_view type, std::string_view name, std::string_view title, const nlohmann::json &j, unsigned int stringsWidth=45)
Definition Utils.h:861
std::string printHistogram2D(std::string_view type, std::string_view name, std::string_view title, const nlohmann::json &j, unsigned int stringsWidth=45)
Definition Utils.h:905
std::string printHistogram3D(std::string_view type, std::string_view name, std::string_view title, const nlohmann::json &j, unsigned int stringsWidth=45)
Definition Utils.h:950
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
@ INFO
Definition IMessageSvc.h:22
Gaudi::Property< unsigned int > m_histoStringsWidth

Member Data Documentation

◆ m_histoStringsWidth

Gaudi::Property<unsigned int> Gaudi::Monitoring::MessageSvcSink::m_histoStringsWidth
Initial value:
{ this, "HistoStringsWidth", 45,
"length of histograms names and titles in the output" }

Definition at line 213 of file MessageSvcSink.cpp.

213 { this, "HistoStringsWidth", 45,
214 "length of histograms names and titles in the output" };

The documentation for this struct was generated from the following file: