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

#include <TestBoundariesUserAction.h>

Inheritance diagram for G4UA::TestBoundariesUserAction:
Collaboration diagram for G4UA::TestBoundariesUserAction:

Classes

struct  Data

Public Member Functions

 TestBoundariesUserAction ()
virtual void BeginOfRunAction (const G4Run *) override
virtual void EndOfRunAction (const G4Run *) override
virtual void UserSteppingAction (const G4Step *) 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 Types

typedef std::map< std::string, int > SMap

Private Member Functions

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

Private Attributes

SMap m_sel
TFile * m_file {}
TTree * m_tree {}
struct G4UA::TestBoundariesUserAction::Data m_data
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 23 of file TestBoundariesUserAction.h.

Member Typedef Documentation

◆ SMap

typedef std::map<std::string,int> G4UA::TestBoundariesUserAction::SMap
private

Definition at line 35 of file TestBoundariesUserAction.h.

Constructor & Destructor Documentation

◆ TestBoundariesUserAction()

G4UA::TestBoundariesUserAction::TestBoundariesUserAction ( )

Definition at line 22 of file TestBoundariesUserAction.cxx.

23 : AthMessaging(Gaudi::svcLocator()->service< IMessageSvc >( "MessageSvc" ),
24 "TestBoundariesUserAction")
25 {
26 }
AthMessaging()
Default constructor:

Member Function Documentation

◆ BeginOfRunAction()

void G4UA::TestBoundariesUserAction::BeginOfRunAction ( const G4Run * )
overridevirtual

Definition at line 28 of file TestBoundariesUserAction.cxx.

29 {
30 m_file = TFile::Open("points.root","RECREATE");
31 ATH_MSG_INFO("Open file points.root, create tree");
32 m_file->cd();
33 m_tree = new TTree("points","points");
34 m_tree->Branch("x",&m_data.x,"x/F");
35 m_tree->Branch("y",&m_data.y,"y/F");
36 m_tree->Branch("z",&m_data.z,"z/F");
37 m_tree->Branch("volume",&m_data.volume,"volume/I");
38 m_tree->Branch("enter",&m_data.enter,"enter/O");
39 m_tree->Branch("exit",&m_data.exit,"exit/O");
40 m_tree->Branch("leave",&m_data.leave,"leave/O");
41 }
#define ATH_MSG_INFO(x)
struct G4UA::TestBoundariesUserAction::Data m_data

◆ EndOfRunAction()

void G4UA::TestBoundariesUserAction::EndOfRunAction ( const G4Run * )
overridevirtual

Definition at line 43 of file TestBoundariesUserAction.cxx.

44 {
45 ATH_MSG_INFO("Writing file points.root");
46 m_file->cd();
47 m_tree->Write();
48 m_file->Close();
49 delete m_file;
50 m_file=nullptr;
51 m_tree=nullptr;
52 }

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

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

Definition at line 54 of file TestBoundariesUserAction.cxx.

55 {
56 G4StepPoint* preStep = aStep->GetPreStepPoint();
57 G4StepPoint* postStep = aStep->GetPostStepPoint();
58
59 if (!preStep || !postStep) {
60 ATH_MSG_ERROR("TestBoundariesUserAction Error something missing");
61 return;
62 }
63
64 const G4TouchableHistory* preTH = dynamic_cast<const G4TouchableHistory*>(preStep->GetTouchable());
65 const G4TouchableHistory* postTH = dynamic_cast<const G4TouchableHistory*>(postStep->GetTouchable());
66 G4LogicalVolume* preLV = preStep->GetPhysicalVolume()->GetLogicalVolume();
67
68 if (preTH) {
69 int preN=preTH->GetHistoryDepth();
70 if (preN>0) preLV = preTH->GetVolume(preN-1)->GetLogicalVolume();
71 }
72
73 G4LogicalVolume* postLV{};
74 if (postStep->GetPhysicalVolume())
75 postLV = postStep->GetPhysicalVolume()->GetLogicalVolume();
76 if (postTH) {
77 int postN = postTH->GetHistoryDepth();
78 if (postN>0) postLV = postTH->GetVolume(postN-1)->GetLogicalVolume();
79 }
80
81 if (postLV!=preLV) {
82 const G4ThreeVector& pos = aStep->GetPostStepPoint()->GetPosition();
83 m_data.Set(pos.x(),pos.y(),pos.z(),0);
84 if (preLV) {
85 const std::string& preStepPointName = preLV->GetName();
86 SMap::const_iterator it = m_sel.find(preStepPointName);
87 if (it!=m_sel.end()) {
88 m_data.volume = it->second;
89 m_data.Reset();
90 m_data.exit = true;
91 if (m_tree) m_tree->Fill();
92 }
93 }
94 if (postLV) {
95 SMap::const_iterator it = m_sel.find( postLV->GetName() );
96 if (it!=m_sel.end()) {
97 m_data.volume = it->second;
98 m_data.Reset();
99 m_data.enter = true;
100 if (m_tree) m_tree->Fill();
101 }
102 }
103 else {
104 m_data.volume = 0;
105 m_data.Reset();
106 m_data.leave = true;
107 if (m_tree) m_tree->Fill();
108 }
109 }
110 }
#define ATH_MSG_ERROR(x)

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_data

struct G4UA::TestBoundariesUserAction::Data G4UA::TestBoundariesUserAction::m_data
private

◆ m_file

TFile* G4UA::TestBoundariesUserAction::m_file {}
private

Definition at line 38 of file TestBoundariesUserAction.h.

38{};

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

◆ m_sel

SMap G4UA::TestBoundariesUserAction::m_sel
private

Definition at line 36 of file TestBoundariesUserAction.h.

◆ m_tree

TTree* G4UA::TestBoundariesUserAction::m_tree {}
private

Definition at line 39 of file TestBoundariesUserAction.h.

39{};

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