The Gaudi Framework  master (37c0b60a)
ContextEventCounter.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 #include "ContextEventCounter.h"
12 
13 // ----------------------------------------------------------------------------
14 // Implementation file for class: ContextEventCounterPtr
15 //
16 // 27/10/2013: Marco Clemencic
17 // ----------------------------------------------------------------------------
20 
21 // ============================================================================
22 // Main execution
23 // ============================================================================
25  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
26 
27  if ( !m_ctxtSpecCounter ) {
28  m_ctxtSpecCounter = new int( 1 );
29  } else {
30  ++( *m_ctxtSpecCounter );
31  }
32  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter.get() << " -> "
33  << *m_ctxtSpecCounter << endmsg;
34 
35  return StatusCode::SUCCESS;
36 }
37 
38 // ============================================================================
39 // Finalize
40 // ============================================================================
42  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
43 
44  debug() << "Partial counts:" << endmsg;
45 
46  info() << "Total count of events: "
48  [this]( const int* p ) {
49  const int r = ( p ? *p : 0 );
50  // print partial counts
51  this->debug() << " " << p << " -> " << r << endmsg;
52  return r;
53  },
54  0 )
55  << endmsg;
56 
58 
59  return Algorithm::finalize(); // must be called after all other actions
60 }
61 
62 // ============================================================================
63 // Main execution
64 // ============================================================================
66  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Execute" << endmsg;
67 
69  debug() << "Context " << Gaudi::Hive::currentContextId() << " " << m_ctxtSpecCounter << endmsg;
70 
71  return StatusCode::SUCCESS;
72 }
73 
74 // ============================================================================
75 // Finalize
76 // ============================================================================
78  if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Finalize" << endmsg;
79 
80  if ( msgLevel( MSG::DEBUG ) ) {
81  debug() << "Partial counts:" << endmsg;
82  m_ctxtSpecCounter.for_each( [this]( const int i ) { this->debug() << " " << i << endmsg; } );
83  }
84 
85  info() << "Total count of events: " << m_ctxtSpecCounter.accumulate( 0 ) << endmsg;
86 
87  return Algorithm::finalize(); // must be called after all other actions
88 }
89 
90 // ============================================================================
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
Gaudi::Hive::ContextSpecificData::accumulate
T accumulate(T init) const
Return the sum of all the contained values using init as first value.
Definition: ContextSpecificPtr.h:178
ContextEventCounterData::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: ContextEventCounter.cpp:77
ContextEventCounterPtr::m_ctxtSpecCounter
Gaudi::Hive::ContextSpecificPtr< int > m_ctxtSpecCounter
Definition: ContextEventCounter.h:30
CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:148
ContextEventCounterData
Definition: ContextEventCounter.h:33
StatusCode
Definition: StatusCode.h:65
GaudiPython.Pythonizations.execute
execute
Definition: Pythonizations.py:578
Gaudi::Hive::ContextSpecificPtr::deleteAll
void deleteAll()
Definition: ContextSpecificPtr.h:135
Gaudi::Hive::ContextSpecificData::for_each
void for_each(F f) const
Call a function on each contained value.
Definition: ContextSpecificPtr.h:189
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:184
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ContextEventCounterData::execute
StatusCode execute() override
Standard constructor.
Definition: ContextEventCounter.cpp:65
ContextEventCounterPtr
Definition: ContextEventCounter.h:24
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Hive::currentContextId
GAUDI_API ContextIdType currentContextId()
Return the current context id.
Definition: ThreadLocalContext.cpp:28
ContextEventCounterData::m_ctxtSpecCounter
Gaudi::Hive::ContextSpecificData< int > m_ctxtSpecCounter
Definition: ContextEventCounter.h:39
ContextEventCounterPtr::finalize
StatusCode finalize() override
Algorithm finalization.
Definition: ContextEventCounter.cpp:41
Gaudi::Hive::ContextSpecificPtr::accumulate
auto accumulate(Mapper f, std::result_of_t< Mapper(const T *)> init) const -> decltype(init)
Taking a function f that from a T* produces a value, return the sum of all the values corresponding t...
Definition: ContextSpecificPtr.h:88
ContextEventCounter.h