ATLAS Offline Software
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
G4UA::LooperKiller Class Referencefinal

A user action to kill looping tracks. More...

#include <LooperKiller.h>

Inheritance diagram for G4UA::LooperKiller:
Collaboration diagram for G4UA::LooperKiller:

Classes

struct  Config
 
struct  Report
 

Public Member Functions

 LooperKiller (const Config &config)
 
virtual void UserSteppingAction (const G4Step *) override
 
const ReportgetReport () const
 Retrieve results. 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 Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t
 

Private Member Functions

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

Private Attributes

StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default) More...
 
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default) More...
 
Config m_config
 My configuration options. More...
 
Report m_report
 
int m_count_steps
 
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

A user action to kill looping tracks.

Definition at line 22 of file LooperKiller.h.

Member Typedef Documentation

◆ StoreGateSvc_t

Definition at line 54 of file LooperKiller.h.

Constructor & Destructor Documentation

◆ LooperKiller()

G4UA::LooperKiller::LooperKiller ( const Config config)

Definition at line 33 of file LooperKiller.cxx.

34  : AthMessaging(Gaudi::svcLocator()->service<IMessageSvc>("MessageSvc"),
35  "LooperKiller"),
36  m_evtStore("StoreGateSvc/StoreGateSvc", "LooperKiller"),
37  m_detStore("StoreGateSvc/DetectorStore", "LooperKiller"),
39  {
40  }

Member Function Documentation

◆ getReport()

const Report& G4UA::LooperKiller::getReport ( ) const
inline

Retrieve results.

Definition at line 49 of file LooperKiller.h.

50  { return m_report; }

◆ 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 }

◆ 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::LooperKiller::UserSteppingAction ( const G4Step *  aStep)
overridevirtual

Definition at line 43 of file LooperKiller.cxx.

44  {
45 
46  if (aStep->GetTrack()->GetCurrentStepNumber() < m_config.MaxSteps) {
47  if (m_count_steps==0) return;
48  // Track recovered...
49  ATH_MSG_WARNING("Track finished on its own. Congrats. Moving on with the event.");
50  m_count_steps = 0;
51  G4TransportationManager *tm = G4TransportationManager::GetTransportationManager();
52  tm->GetNavigatorForTracking()->SetVerboseLevel(0);
53  tm->GetPropagatorInField()->SetVerboseLevel(0);
54  G4RunManagerKernel *rmk = G4RunManagerKernel::GetRunManagerKernel();
55  rmk->GetTrackingManager()->SetVerboseLevel(0);
56  rmk->GetTrackingManager()->GetSteppingManager()->SetVerboseLevel(0);
57  rmk->GetStackManager()->SetVerboseLevel(0);
58  return;
59  } else if (aStep->GetTrack()->GetCurrentStepNumber() == m_config.MaxSteps) {
60  ATH_MSG_WARNING("LooperKiller triggered!! Hold on to your hats!!!!!!!!" );
61  }
62 
63  G4TransportationManager *tm = G4TransportationManager::GetTransportationManager();
64  tm->GetNavigatorForTracking()->SetVerboseLevel(m_config.VerboseLevel);
65  tm->GetPropagatorInField()->SetVerboseLevel(m_config.VerboseLevel);
66 
67  G4RunManagerKernel *rmk = G4RunManagerKernel::GetRunManagerKernel();
68  rmk->GetTrackingManager()->SetVerboseLevel(m_config.VerboseLevel);
69  rmk->GetTrackingManager()->GetSteppingManager()->SetVerboseLevel(m_config.VerboseLevel);
70  rmk->GetStackManager()->SetVerboseLevel(m_config.VerboseLevel);
71 
72  m_count_steps++;
73 
75  m_count_steps = 0;
77  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
78  tm->GetNavigatorForTracking()->SetVerboseLevel(0);
79  tm->GetPropagatorInField()->SetVerboseLevel(0);
80  rmk->GetTrackingManager()->SetVerboseLevel(0);
81  rmk->GetTrackingManager()->GetSteppingManager()->SetVerboseLevel(0);
82  rmk->GetStackManager()->SetVerboseLevel(0);
83  int pdg_id{0};
84  TrackHelper trackHelper(aStep->GetTrack());
85  if ( m_config.BSM_Only && (trackHelper.IsPrimary() || trackHelper.IsRegisteredSecondary()) ) {
86  HepMC::GenParticlePtr part = trackHelper.GetTrackInformation()->GetCurrentGenParticle();
87  if (part) { pdg_id = part->pdg_id(); }
88  }
89  if ( !m_config.BSM_Only || MC::isBSM(pdg_id)) { // Sometimes we may ony want to bail out for BSM particles.
90  // Bail out...
91  if (m_config.AbortEvent){
92  rmk->GetEventManager()->AbortCurrentEvent();
93  rmk->GetEventManager()->GetNonconstCurrentEvent()->SetEventAborted();
94  }
95  if (m_config.SetError){
96 
97  // Set error state in eventInfo
98  SG::WriteHandle<EventInfo> eic("McEventInfo");
99  if (! eic.isValid()){
100  ATH_MSG_WARNING( "Failed to retrieve EventInfo" );
101  } else {
102  eic->setErrorState(EventInfo::Core,EventInfo::Error);
103  ATH_MSG_WARNING( "Set error state in event info!" );
104  }
105  } // End of set error
106  } // End of BSM-only check
107  const std::string name = aStep->GetTrack()->GetDefinition()->GetParticleName();
108  if ( ( m_config.BSM_Only && !MC::isBSM(pdg_id) ) || !m_config.AbortEvent ) {
109  ATH_MSG_INFO ("Quietly stopped tracking looping " << name
110  << " (trackID " << aStep->GetTrack()->GetTrackID()
111  << ", track pos: "<<aStep->GetTrack()->GetPosition()
112  << ", mom: "<<aStep->GetTrack()->GetMomentum()
113  << ", parentID " << aStep->GetTrack()->GetParentID() << ")");
114  }
115  else {
116  ATH_MSG_WARNING ("Stopped tracking looping " << name
117  << " (trackID " << aStep->GetTrack()->GetTrackID()
118  << ", track pos: "<<aStep->GetTrack()->GetPosition()
119  << ", mom: "<<aStep->GetTrack()->GetMomentum()
120  << ", parentID " << aStep->GetTrack()->GetParentID() << "). The event will abort now.");
121  }
122  } // End of handling end of error time
123  }

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::LooperKiller::m_config
private

My configuration options.

Definition at line 61 of file LooperKiller.h.

◆ m_count_steps

int G4UA::LooperKiller::m_count_steps
private

Definition at line 63 of file LooperKiller.h.

◆ m_detStore

StoreGateSvc_t G4UA::LooperKiller::m_detStore
private

Pointer to StoreGate (detector store by default)

Definition at line 58 of file LooperKiller.h.

◆ m_evtStore

StoreGateSvc_t G4UA::LooperKiller::m_evtStore
private

Pointer to StoreGate (event store by default)

Definition at line 56 of file LooperKiller.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.

◆ m_report

Report G4UA::LooperKiller::m_report
private

Definition at line 62 of file LooperKiller.h.


The documentation for this class was generated from the following files:
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
EventInfo::Error
@ Error
Definition: EventInfo/EventInfo/EventInfo.h:67
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
isBSM
bool isBSM(const T &p)
Definition: AtlasPID.h:224
G4UA::LooperKiller::m_count_steps
int m_count_steps
Definition: LooperKiller.h:63
G4UA::LooperKiller::Config::AbortEvent
bool AbortEvent
Definition: LooperKiller.h:32
HepMC::GenParticlePtr
GenParticle * GenParticlePtr
Definition: GenParticle.h:37
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
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
TrackHelper
Definition: TrackHelper.h:14
AthMessaging::AthMessaging
AthMessaging()
Default constructor:
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
G4UA::LooperKiller::Report::killed_tracks
long killed_tracks
Definition: LooperKiller.h:39
G4UA::LooperKiller::m_evtStore
StoreGateSvc_t m_evtStore
Pointer to StoreGate (event store by default)
Definition: LooperKiller.h:56
EventInfo::Core
@ Core
Definition: EventInfo/EventInfo/EventInfo.h:61
G4UA::LooperKiller::Config::PrintSteps
int PrintSteps
Definition: LooperKiller.h:30
G4UA::LooperKiller::m_config
Config m_config
My configuration options.
Definition: LooperKiller.h:61
G4UA::LooperKiller::Config::BSM_Only
bool BSM_Only
Definition: LooperKiller.h:34
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
G4UA::LooperKiller::m_report
Report m_report
Definition: LooperKiller.h:62
G4UA::LooperKiller::Config::VerboseLevel
int VerboseLevel
Definition: LooperKiller.h:31
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
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
G4UA::LooperKiller::Config::SetError
bool SetError
Definition: LooperKiller.h:33
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
G4UA::LooperKiller::m_detStore
StoreGateSvc_t m_detStore
Pointer to StoreGate (detector store by default)
Definition: LooperKiller.h:58
G4UA::LooperKiller::Config::MaxSteps
int MaxSteps
Definition: LooperKiller.h:29