ATLAS Offline Software
Loading...
Searching...
No Matches
G4UA::VerboseSelector Class Reference

#include <VerboseSelector.h>

Inheritance diagram for G4UA::VerboseSelector:
Collaboration diagram for G4UA::VerboseSelector:

Classes

struct  Config

Public Member Functions

 VerboseSelector (const Config &config)
virtual void UserSteppingAction (const G4Step *) override
virtual void PreUserTrackingAction (const G4Track *) override
virtual void PostUserTrackingAction (const G4Track *) override
virtual void BeginOfEventAction (const G4Event *) override
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

ServiceHandle< StoreGateSvcm_evtStore
 Pointer to StoreGate (event store by default)
ServiceHandle< StoreGateSvcm_detStore
 Pointer to StoreGate (detector store by default)
Config m_config
uint64_t m_evtCount
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels)
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging)

Detailed Description

Definition at line 20 of file VerboseSelector.h.

Constructor & Destructor Documentation

◆ VerboseSelector()

G4UA::VerboseSelector::VerboseSelector ( const Config & config)

Definition at line 33 of file VerboseSelector.cxx.

33 :
34 AthMessaging(Gaudi::svcLocator()->service< IMessageSvc >( "MessageSvc" ),"VerboseSelector"),
35 m_evtStore("StoreGateSvc/StoreGateSvc", "VerboseSelector"),
36 m_detStore("StoreGateSvc/DetectorStore", "LooperKiller"),
37 m_config(config),m_evtCount(0)
38 {}
AthMessaging()
Default constructor:
ServiceHandle< StoreGateSvc > m_detStore
Pointer to StoreGate (detector store by default)
ServiceHandle< StoreGateSvc > m_evtStore
Pointer to StoreGate (event store by default)

Member Function Documentation

◆ BeginOfEventAction()

void G4UA::VerboseSelector::BeginOfEventAction ( const G4Event * )
overridevirtual

Definition at line 40 of file VerboseSelector.cxx.

41 {
42 SG::ReadHandle<xAOD::EventInfo> eic("EventInfo");
43 if (!eic.isValid()){
44 ATH_MSG_WARNING( "Failed to retrieve EventInfo" );
45 } else {
46 m_evtCount = eic->eventNumber();
47 }
48 }
#define ATH_MSG_WARNING(x)

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

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

Definition at line 163 of file AthMessaging.h.

164{
165 MsgStream* ms = m_msg_tls.get();
166 if (!ms) {
167 if (!m_initialized.test_and_set()) initMessaging();
168 ms = new MsgStream(m_imsg,m_nm);
169 m_msg_tls.reset( ms );
170 }
171
172 ms->setLevel (m_lvl);
173 return *ms;
174}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

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

The standard message stream.

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

Definition at line 178 of file AthMessaging.h.

179{ return msg() << lvl; }
MsgStream & msg() const
The standard message stream.

◆ msgLvl()

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

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_lvl <= lvl) {
154 msg() << lvl;
155 return true;
156 } else {
157 return false;
158 }
159}

◆ PostUserTrackingAction()

void G4UA::VerboseSelector::PostUserTrackingAction ( const G4Track * aTrack)
overridevirtual

Definition at line 139 of file VerboseSelector.cxx.

140 {
141 if(m_evtCount==(uint64_t)m_config.targetEvent||m_config.targetEvent<0){
142 if(aTrack->GetTrackID()==m_config.targetTrack||m_config.targetTrack<0)
143 G4EventManager::GetEventManager()->GetTrackingManager()->SetVerboseLevel(0);
144 for (auto& pdgID : m_config.targetPdgIDs) {
145 if (std::abs(aTrack->GetParticleDefinition()->GetPDGEncoding()) == pdgID ) {
146 G4EventManager::GetEventManager()->GetTrackingManager()->SetVerboseLevel(0);
147 break;
148 }
149 }
150 }
151 }

◆ PreUserTrackingAction()

void G4UA::VerboseSelector::PreUserTrackingAction ( const G4Track * aTrack)
overridevirtual

Definition at line 99 of file VerboseSelector.cxx.

100 {
101 if(m_evtCount==(uint64_t)m_config.targetEvent||m_config.targetEvent<0)
102 {
103 int trackID = aTrack->GetTrackID();
104 TrackHelper trackHelper(aTrack);
105
106 AtlasG4EventUserInfo* atlasG4EvtUserInfo = static_cast<AtlasG4EventUserInfo*>
107 (G4EventManager::GetEventManager()->GetConstCurrentEvent()->
108 GetUserInformation());
109
110 int currentBarcode(0);
111
112 if (trackHelper.IsPrimary() || trackHelper.IsRegisteredSecondary()) {
113 currentBarcode = HepMC::barcode(atlasG4EvtUserInfo->GetCurrentGenParticle()); // FIXME Barcode-based
114 }
115
116 bool p1 = m_config.targetTrack<0 && m_config.targetBarcode<0 && m_config.targetPdgIDs.empty();
117 bool p2 = trackID==m_config.targetTrack;
118 bool p3 = currentBarcode==m_config.targetBarcode;
119 bool p4 = false;
120
121 for (auto& pdgID : m_config.targetPdgIDs) {
122 if (std::abs(aTrack->GetParticleDefinition()->GetPDGEncoding()) == pdgID ) {
123 p4 = true;
124 break;
125 }
126 }
127
128 if(p1 || p2 || p3 || p4) {
129 ATH_MSG_INFO(std::endl << "---------> Dumping now track #"
130 << trackID << " barcode " << currentBarcode
131 << " pdgID " << aTrack->GetParticleDefinition()->GetPDGEncoding()
132 << " in event " << m_evtCount);
133 G4EventManager::GetEventManager()->GetTrackingManager()->
134 SetVerboseLevel(m_config.verboseLevel);
135 }
136 }
137 }
#define ATH_MSG_INFO(x)
HepMC::GenParticlePtr GetCurrentGenParticle()
return a pointer to the GenParticle corresponding to the current G4Track (if there is one).
int barcode(const T *p)
Definition Barcode.h:16

◆ setLevel()

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

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}

◆ UserSteppingAction()

void G4UA::VerboseSelector::UserSteppingAction ( const G4Step * aStep)
overridevirtual

Definition at line 50 of file VerboseSelector.cxx.

51 {
52 if(m_evtCount==(uint64_t)m_config.targetEvent||m_config.targetEvent<0){
53
54 const G4ThreeVector& myPos = aStep->GetPostStepPoint()->GetPosition();
55 if ( ( myPos.x() < m_config.Xmax && myPos.x() > m_config.Xmin &&
56 myPos.y() < m_config.Ymax && myPos.y() > m_config.Ymin &&
57 myPos.z() < m_config.Zmax && myPos.z() > m_config.Zmin ) ||
58 m_config.verb==2){
59
60 G4TransportationManager *tm = G4TransportationManager::GetTransportationManager();
61 tm->GetNavigatorForTracking()->SetVerboseLevel(m_config.verboseLevel);
62 tm->GetPropagatorInField()->SetVerboseLevel(m_config.verboseLevel);
63
64 G4RunManagerKernel *rmk = G4RunManagerKernel::GetRunManagerKernel();
65 rmk->GetTrackingManager()->SetVerboseLevel(m_config.verboseLevel);
66 rmk->GetTrackingManager()->GetSteppingManager()->SetVerboseLevel(m_config.verboseLevel);
67 rmk->GetStackManager()->SetVerboseLevel(m_config.verboseLevel);
68
69 G4Track *tr = aStep->GetTrack();
70 const G4ThreeVector& mom = tr->GetMomentumDirection();
71
72 std::cout << "Moving " << tr->GetDefinition()->GetParticleName() << " at (" << myPos.x()
73 << ", " << myPos.y() << ", " << myPos.z() << ") to (" << mom.x() << ", " << mom.y()
74 << ", " << mom.z() << ") from ";
75 if (aStep->GetPreStepPoint()->GetPhysicalVolume()) std::cout << aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName();
76 else std::cout << "noVolume";
77 std::cout << " to ";
78 if (aStep->GetPostStepPoint()->GetPhysicalVolume()) std::cout << aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
79 else std::cout << "outOfWorld";
80 std::cout << " with KE=" << tr->GetKineticEnergy() << " pT=" << tr->GetMomentum().perp()
81 << " eta=" << tr->GetMomentum().eta() << " length " << aStep->GetStepLength() << " energy "
82 << aStep->GetTotalEnergyDeposit() << " with process ";
83 if (aStep->GetPostStepPoint()->GetProcessDefinedStep()) std::cout << aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
84 else std::cout << "Unknown";
85 std::cout << " from a ";
86 if (tr->GetCreatorProcess()) std::cout << tr->GetCreatorProcess()->GetProcessName();
87 else if (tr->GetParentID()==0) std::cout << "Generator";
88 else std::cout << "pid="<<tr->GetParentID();
89 if (tr->GetLogicalVolumeAtVertex()) std::cout << " in " << tr->GetLogicalVolumeAtVertex()->GetName() << ", ";
90 else std::cout << " nowhere, ";
91 std::cout << tr->GetTrackLength() << " mm ago" << std::endl;
92
93 if (m_config.verb==1) m_config.verb=2;
94
95 }
96 }
97 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

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

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_config

Config G4UA::VerboseSelector::m_config
private

Definition at line 54 of file VerboseSelector.h.

◆ m_detStore

ServiceHandle<StoreGateSvc> G4UA::VerboseSelector::m_detStore
private

Pointer to StoreGate (detector store by default)

Definition at line 53 of file VerboseSelector.h.

◆ m_evtCount

uint64_t G4UA::VerboseSelector::m_evtCount
private

Definition at line 55 of file VerboseSelector.h.

◆ m_evtStore

ServiceHandle<StoreGateSvc> G4UA::VerboseSelector::m_evtStore
private

Pointer to StoreGate (event store by default)

Definition at line 51 of file VerboseSelector.h.

◆ m_imsg

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

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lvl

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

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

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

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
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.


The documentation for this class was generated from the following files: