ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
AthMessaging Class Reference

Class to provide easy MsgStream access and capabilities. More...

#include <AthenaBaseComps/AthMessaging.h>

Inherited by AFP_ToFRawData_v2, ALFA_CenterGravity, ALFA_EdgeMethod, ALFA_HalfReco, ALFA_MDGap, ALFA_MDMultiple, ALFA_MDOverlap, ALFA_MDTracking, ALFA_ODTracking, Analysis::JetTagCalibCondData, asg::AsgMessaging, AskForRoI, AthConstConverter, Athena::LeafCnv, Athena::RootCnv, Athena::xAODCnv, AthenaEventLoopMgr, AthenaHiveEventLoopMgr, AthenaPoolConverter, AthMemoryAuditor, AtlasDetectorID, AtlasDetectorIDHelper, CaloGeometryFromCaloDDM, CookieCutterHelpers::CentralPosition, CrackDMConstruction, CTP_Decoder, DebugView [private], DerivationFramework::BPhysPVCascadeTools, DerivationFramework::BPhysPVTools, DetDescrConverter, EventInfoByteStreamAuxCnv, EventInfoByteStreamxAODCnv, EventInfoMuonCalibStreamCnv, ExtParameterisedVolumeBuilder, FPGATrackSimFitConstantBank, FPGATrackSimModuleRelabel, G4AtlasRunManager, G4UA::AthenaTrackingAction, G4UA::CaloG4::CalibrationDefaultProcessing, G4UA::EnergyConservationTest, G4UA::FastIDKiller, G4UA::G4AtlantisDumper, G4UA::G4CosmicAndFilter, G4UA::G4CosmicFilter, G4UA::G4CosmicOrFilter, G4UA::G4HitFilter, G4UA::G4SimTimer, G4UA::HIPKiller, G4UA::HIPLArVolumeAccept, G4UA::HitWrapper, G4UA::HyperspaceCatcher, G4UA::iGeant4::PhysicsValidationUserAction, G4UA::LooperKiller, G4UA::LooperThresholdSet, G4UA::MaterialStepRecorder, G4UA::MCTruthSteppingAction, G4UA::MomentumConservation, G4UA::ScoringVolumeTrackKiller, G4UA::SG_StepNtuple, G4UA::StepHistogram, G4UA::StepNtuple, G4UA::StoppedParticleAction, G4UA::TestBoundariesUserAction, G4UA::VerboseSelector, G4UA::VolumeDebugger, G4UA::VolumeDumper, Geo2G4Builder, Geo2G4MaterialFactory, Geo2G4SolidFactory, HGTD_DetectorManager, HGTD_GmxInterface, HLT::HLTResultMTByteStreamCnv, IDPVM::ResolutionHelper, IDTPM::PlotMgr, IDTPM::TrackAnalysisCollections, IDTPM::TrackMatchingLookupBase< T, R >, InDet::InDetMaterialVeto, InDet::TRT_ElectronPidTool::ToTcalculator, InDetDD::AthenaComps, InDetDD::BCMPrimeGmxInterface, InDetDD::DistortedMaterialManager, InDetDD::ExtraMaterial, InDetDD::InDetDetectorManager, InDetDD::ITk::PixelGmxInterface, InDetDD::ITk::StripGmxInterface, InDetDD::SiCommonItems, InDetDD::TRT_DetElementContainer, InDetDD::VolumeBuilder, InDetMaterialManager, InDetPlotBase, InducedChargeModel, IOVDbFolder, JetTagDQA::BTaggingValidationPlots, L1TriggerResultByteStreamCnv, LArAlignHelper, LArCondFlatBase, LArCondSuperCellBase, LArFebConfig, LArG4::EC::HVHelper, LArGeo::BarrelConstruction, LArGeo::BarrelCryostatConstruction, LArGeo::EMECConstruction, LArGeo::EMECSupportConstruction, LArGeo::LArDetectorFactory, LArGeo::LArDetectorFactoryLite, LArHVIdMappingReader, LArLATOMEDecoder::EventProcess, LArMaterialManager, LArTTCellMap, LArWheelSliceSolid, LArWheelSolid, LUCID_DigitByteStreamCnv, LVL1BS::CmxCpHitsByteStreamAuxCnv, LVL1BS::CmxCpHitsByteStreamxAODCnv, LVL1BS::CmxCpTobByteStreamAuxCnv, LVL1BS::CmxCpTobByteStreamxAODCnv, LVL1BS::CmxEtSumsByteStreamAuxCnv, LVL1BS::CmxEtSumsByteStreamxAODCnv, LVL1BS::CmxJetHitsByteStreamAuxCnv, LVL1BS::CmxJetHitsByteStreamxAODCnv, LVL1BS::CmxJetTobByteStreamAuxCnv, LVL1BS::CmxJetTobByteStreamxAODCnv, LVL1BS::CmxRoIByteStreamAuxCnv, LVL1BS::CmxRoIByteStreamxAODCnv, LVL1BS::CpmTobRoiByteStreamAuxCnv, LVL1BS::CpmTobRoiByteStreamxAODCnv, LVL1BS::CpmTowerByteStreamAuxCnv, LVL1BS::CpmTowerByteStreamxAODCnv, LVL1BS::JemEtSumsByteStreamAuxCnv, LVL1BS::JemEtSumsByteStreamxAODCnv, LVL1BS::JemTobRoiByteStreamAuxCnv, LVL1BS::JemTobRoiByteStreamxAODCnv, LVL1BS::JetElementByteStreamAuxCnv, LVL1BS::JetElementByteStreamxAODCnv, LVL1BS::L1CaloByteStreamAuxCnv< ContainerT, AuxContainerT >, LVL1BS::L1TopoByteStreamAuxCnv, LVL1BS::L1TopoByteStreamxAODCnv, LVL1BS::PpmByteStreamAuxCnv, LVL1BS::PpmByteStreamxAODCnv, LVL1BS::RodHeaderByteStreamAuxCnv, LVL1BS::RodHeaderByteStreamxAODCnv, LVL1TGC::TGCBIS78, LVL1TGC::TGCBIS78CoincidenceMap, LVL1TGC::TGCEIFICoincidenceMap, LVL1TGC::TGCGoodMF, LVL1TGC::TGCNSW, LVL1TGC::TGCTMDB, LVL1TGCTrigger::TGCDatabaseManager, LVL1TGCTrigger::TGCNSWCoincidenceMap, McVtxFilter, MM_StripsResponseSimulation, MMLoadVariables, MMT_Diamond, MMT_Parameters, Muon::DigitEffiData, Muon::STgcClusterBuilderCommon, Muon::TgcSlbDataHelper, Muon::TwinTubeMap, MuonCalib::CalibT0DbOperations, MuonG4R4::MdtSensitiveDetector, MuonG4R4::MmSensitiveDetector, MuonG4R4::RpcSensitiveDetector, MuonG4R4::sTgcSensitiveDetector, MuonG4R4::TgcSensitiveDetector, MuonGM::MuonChamber, MuonGM::MuonChamberLite, MuonGM::MuonDetectorManager, MuonGM::MuonPadDesign, MuonGM::MuonReadoutElement, MuonGM::MuonStation, MuonGM::MYSQL, MuonGM::RDBReaderAtlas, MuonGM::Station, MuonGM::TgcReadoutParams, MuonGMR4::MuonDetectorManager, MuonGMR4::MuonReadoutElement, MuonGMR4::StripDesign, MuonHoughHisto2D, MuonHoughTransformer, MuonHoughTransformSteering, MuonR4::CalibSegmentChi2Minimizer [private], MuonR4::MdtSegmentFitter, MuonR4::MdtSegmentSeedGenerator, MuonR4::SegmentAmbiSolver, MuonVal::IParticleFourMomBranch, MuonVal::MuonTesterBranch, MuonVal::MuonTesterTree, NswCalibDbTimeChargeData, NswErrorCalibData, NSWL1::L1TdrStgcTriggerLogic, ParticleCandidateList, PileUpEventLoopMgr, PileUpStream, PixelGeoDC2::PixelGeometryManager, pool::IFileCatalog, RatesHistoBase, Ringer::BuildCaloRingsFctorBase, RoIBResultByteStreamCnv< ROBF >, RootAuxDynIO::RNTupleAuxDynReader, RootAuxDynIO::RNTupleAuxDynWriter, RootAuxDynIO::TBranchAuxDynWriter, RootStorageSvc::RNTupleWriterHelper, Routing2, SCT_ReadoutData, ServicesTracker, SingleLogicalVolumeFactory, SqliteRecordset, sTGCAsBuiltData2, sTgcDigitMaker, TCCPlotsBase, TgcDigitJitterData, TgcDigitMaker, TgcDigitThresholdData, TGCTriggerBWCWReader, TileCellDim, TileCorrelation, TileDddbManager, TileDetDescrManager, TilePulseShape, TileROD_Encoder, TrackFitter, IDTPM::TrackMatchingLookupBase< xAOD::TrackParticle >, IDTPM::TrackMatchingLookupBase< xAOD::TrackParticle, xAOD::TruthParticle >, IDTPM::TrackMatchingLookupBase< xAOD::TruthParticle, xAOD::TrackParticle >, Trig::TrigBtagEmulationChain, TrigCostAuditor, TrigSORFromPtreeHelper, Trk::AlignModule, Trk::GeoShapeConverter, Trk::VolumeConverter, TRRegionXMLHandler, TRT_PAI_effectiveGas, TRT_PAI_gasMixture, TRTDigCondBase, TRTDigSettings, TRTElectronicsProcessing, TRTNoise, TRTProcessingOfStraw, TRTTimeCorrection, TRTTransitionRadiation, VolumeTreeNavigator, ZDC_DetFactory, ZDC_DetManager, and ZdcLucrodDecoder.

Collaboration diagram for AthMessaging:

Public Member Functions

 AthMessaging (IMessageSvc *msgSvc, const std::string &name)
 Constructor. More...
 
 AthMessaging (const std::string &name)
 Constructor with auto-retrieval of the MessageSvc. More...
 
virtual ~AthMessaging ()
 Destructor: More...
 
bool msgLvl (const MSG::Level lvl) const
 Test the output level. More...
 
MsgStream & msg () const
 The standard message stream. More...
 
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Member Functions

 AthMessaging ()
 Default constructor: More...
 
 AthMessaging (const AthMessaging &rhs)
 
AthMessagingoperator= (const AthMessaging &rhs)
 
void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

std::string m_nm
 Message source name. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging) More...
 

Detailed Description

Class to provide easy MsgStream access and capabilities.

All the expensive operations (e.g. retrieval of MessageSvc) are done lazily, i.e. only when a message is printed to keep the construction of this class as fast as possible.

One usually inherits from this class and uses it like so:

class MyClass : public AthMessaging, ... {
public:
MyClass() : AthMessaging("MyName") {}
void print() {
ATH_MSG_INFO("Hello World");
}
};

The above will retrieve the pointer to the MessageSvc when needed. If you have access to it already, it is preferred to pass it explicitly:

MyClass() : AthMessaging(msgSvc, "MyName") {}

Definition at line 54 of file AthMessaging.h.

Constructor & Destructor Documentation

◆ AthMessaging() [1/4]

AthMessaging::AthMessaging ( IMessageSvc *  msgSvc,
const std::string &  name 
)

Constructor.

Parameters
msgSvcPointer to the MessageSvc
nameName of the message stream

Definition at line 13 of file AthMessaging.cxx.

14  :
16 {}

◆ AthMessaging() [2/4]

AthMessaging::AthMessaging ( const std::string &  name)

Constructor with auto-retrieval of the MessageSvc.

Parameters
nameName of the message stream

Definition at line 19 of file AthMessaging.cxx.

19  :
20  m_nm(name)
21 {}

◆ ~AthMessaging()

AthMessaging::~AthMessaging ( )
virtual

Destructor:

Definition at line 24 of file AthMessaging.cxx.

25 {}

◆ AthMessaging() [3/4]

AthMessaging::AthMessaging ( )
private

Default constructor:

◆ AthMessaging() [4/4]

AthMessaging::AthMessaging ( const AthMessaging rhs)
private

Member Function Documentation

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
private

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40 {
42  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inline

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 164 of file AthMessaging.h.

165 {
166  MsgStream* ms = m_msg_tls.get();
167  if (!ms) {
168  if (!m_initialized.test_and_set()) initMessaging();
169  ms = new MsgStream(m_imsg,m_nm);
170  m_msg_tls.reset( ms );
171  }
172 
173  ms->setLevel (m_lvl);
174  return *ms;
175 }

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level  lvl) const
inline

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 179 of file AthMessaging.h.

180 { return msg() << lvl; }

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level  lvl) const
inline

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152 {
153  if (!m_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }

◆ operator=()

AthMessaging& AthMessaging::operator= ( const AthMessaging rhs)
private

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level  lvl)

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29 {
30  m_lvl = lvl;
31 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivate

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivate

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivate

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivate

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
private

Message source name.

Definition at line 129 of file AthMessaging.h.


The documentation for this class was generated from the following files:
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
AthMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
Definition: AthMessaging.h:132