ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
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. 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

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

Private Attributes

ServiceHandle< StoreGateSvcm_evtStore
 Pointer to StoreGate (event store by default) More...
 
ServiceHandle< StoreGateSvcm_detStore
 Pointer to StoreGate (detector store by default) More...
 
Config m_config
 
uint64_t m_evtCount
 
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

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"),
38  {}

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  }

◆ 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  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
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 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
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 179 of file AthMessaging.h.

180 { return msg() << lvl; }

◆ 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_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }

◆ PostUserTrackingAction()

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

Definition at line 139 of file VerboseSelector.cxx.

140  {
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  {
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  }

◆ 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  {
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.

◆ m_lvl

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

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ 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:
G4UA::VerboseSelector::Config::Ymin
double Ymin
Definition: VerboseSelector.h:37
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
G4UA::VerboseSelector::Config::Xmin
double Xmin
Definition: VerboseSelector.h:36
AtlasG4EventUserInfo
This class is attached to G4Event objects as UserInformation. It holds a pointer to the HepMC::GenEve...
Definition: AtlasG4EventUserInfo.h:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
G4UA::VerboseSelector::Config::targetEvent
int targetEvent
Definition: VerboseSelector.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
G4UA::VerboseSelector::m_config
Config m_config
Definition: VerboseSelector.h:54
G4UA::VerboseSelector::Config::Xmax
double Xmax
Definition: VerboseSelector.h:36
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
G4UA::VerboseSelector::Config::targetPdgIDs
std::vector< double > targetPdgIDs
Definition: VerboseSelector.h:39
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
G4UA::VerboseSelector::m_detStore
ServiceHandle< StoreGateSvc > m_detStore
Pointer to StoreGate (detector store by default)
Definition: VerboseSelector.h:53
ParticleJetTools::p3
Amg::Vector3D p3(const xAOD::TruthVertex *p)
Definition: ParticleJetLabelCommon.cxx:55
AtlasG4EventUserInfo::GetCurrentGenParticle
HepMC::GenParticlePtr GetCurrentGenParticle()
return a pointer to the GenParticle corresponding to the current G4Track (if there is one).
Definition: AtlasG4EventUserInfo.h:59
TrackHelper
Definition: TrackHelper.h:14
AthMessaging::AthMessaging
AthMessaging()
Default constructor:
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
G4UA::VerboseSelector::m_evtStore
ServiceHandle< StoreGateSvc > m_evtStore
Pointer to StoreGate (event store by default)
Definition: VerboseSelector.h:51
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
G4UA::VerboseSelector::Config::verboseLevel
int verboseLevel
Definition: VerboseSelector.h:34
G4UA::VerboseSelector::Config::Ymax
double Ymax
Definition: VerboseSelector.h:37
G4UA::VerboseSelector::Config::Zmin
double Zmin
Definition: VerboseSelector.h:38
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
G4UA::VerboseSelector::m_evtCount
uint64_t m_evtCount
Definition: VerboseSelector.h:55
G4UA::VerboseSelector::Config::Zmax
double Zmax
Definition: VerboseSelector.h:38
G4UA::VerboseSelector::Config::targetBarcode
int targetBarcode
Definition: VerboseSelector.h:33
G4UA::VerboseSelector::Config::targetTrack
int targetTrack
Definition: VerboseSelector.h:32
G4UA::VerboseSelector::Config::verb
int verb
Definition: VerboseSelector.h:35
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
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