ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Atlas
G4AtlasServices
src
UserLimitsSvc.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// class header
6
#include "
UserLimitsSvc.h
"
7
8
// Geant4 includes used in functions
9
#include "G4LogicalVolume.hh"
10
#include "G4LogicalVolumeStore.hh"
11
#include "G4UserLimits.hh"
12
13
// STL library
14
#include "
CxxUtils/StringUtils.h
"
15
#include <limits>
16
UserLimitsSvc::UserLimitsSvc
(
const
std::string& name, ISvcLocator* pSvcLocator )
17
: base_class(name,pSvcLocator)
18
{
19
}
20
21
// Athena method, called at initialization time
22
StatusCode
UserLimitsSvc::initialize
()
23
{
24
ATH_MSG_INFO
(
" initializing UserLimitsSvc "
<<name() );
25
G4LogicalVolumeStore& lvs=*(G4LogicalVolumeStore::GetInstance());
26
27
ATH_MSG_INFO
(
"G4LogicalVolumeStore size: "
<< lvs.size());
28
std::set<G4String> volumes;
29
for
(
unsigned
int
i = 0; i < lvs.size(); i++) {
30
volumes.insert(lvs[i]->GetName());
31
}
32
ATH_MSG_INFO
(
"G4LogicalVolumeStore unique size: "
<< volumes.size());
33
34
// Define with a configurable string which string comparison fucntion to use
35
using
function_t = bool (
UserLimitsSvc
::*) (
const
std::string& pattern,
const
std::string& logicalVolume)
const
;
36
std::map<std::string, function_t> funcMap;
37
funcMap.emplace(
"isMatch"
, &
UserLimitsSvc::isMatch
);
38
funcMap.emplace(
"contains"
, &
UserLimitsSvc::contains
);
39
40
// Call Limit setting methods here:
41
std::vector<std::string>::const_iterator volumeItr(
m_logicalVolumes
.value().begin());
42
const
std::vector<std::string>::const_iterator endOfVolumesItr(
m_logicalVolumes
.value().end());
43
while
(volumeItr!=endOfVolumesItr)
44
{
45
const
std::string& volName(*volumeItr);
46
unsigned
int
ndone(0);
47
for
(
unsigned
int
i=0;i<lvs.size();i++)
48
{
49
G4LogicalVolume *lv=lvs[i];
50
// Compare two strings with a configurable method...
51
if
( (this->*(funcMap[
m_matchType
.value()]))(volName, lv->GetName()) ){
52
G4UserLimits *ul=lv->GetUserLimits();
53
if
(!ul) ul=
new
G4UserLimits;
54
if
(-0.5 <
m_MaxStep
) { ul->SetMaxAllowedStep(
m_MaxStep
); }
55
if
(-0.5 <
m_MinEkine
) { ul->SetUserMinEkine(
m_MinEkine
); }
56
if
(-0.5 <
m_MaxTrackLength
) { ul->SetUserMaxTrackLength(
m_MaxTrackLength
); }
57
if
(-0.5 <
m_MaxTime
) { ul->SetUserMaxTime(
m_MaxTime
); }
58
if
(-0.5 <
m_MinRange
) { ul->SetUserMinRange(
m_MinRange
); }
59
lv->SetUserLimits(ul);
60
++ndone;
61
}
62
}
63
if
(-0.5 <
m_MaxStep
) {
ATH_MSG_DEBUG
(
"MaxStep set to "
<<
m_MaxStep
<<
" to "
<<ndone<<
" copies of "
<<volName ); }
64
if
(-0.5 <
m_MinEkine
){
ATH_MSG_DEBUG
(
"MinEkine set to "
<<
m_MinEkine
<<
" to "
<<ndone<<
" copies of "
<<volName );}
65
if
(-0.5 <
m_MaxTrackLength
) {
ATH_MSG_DEBUG
(
"MaxTrackLength set to "
<<
m_MaxTrackLength
<<
" to "
<<ndone<<
" copies of "
<<volName ); }
66
if
(-0.5 <
m_MaxTime
) {
ATH_MSG_DEBUG
(
"MaxTime set to "
<<
m_MaxTime
<<
" to "
<<ndone<<
" copies of "
<<volName ); }
67
if
(-0.5 <
m_MinRange
) {
ATH_MSG_DEBUG
(
"MinRange set to "
<<
m_MinRange
<<
" to "
<<ndone<<
" copies of "
<<volName ); }
68
69
++volumeItr;
70
}
71
// TODO would probably be more CPU efficient to loop over the geometry and compare with each limit volume.
72
return
StatusCode::SUCCESS;
73
}
74
75
bool
UserLimitsSvc::contains
(
const
std::string& pattern,
const
std::string& logicalVolume)
const
76
{
77
return
(logicalVolume.find(pattern) != std::string::npos);
78
}
79
80
bool
UserLimitsSvc::isMatch
(
const
std::string&
a
,
const
std::string& b)
const
81
{
82
// straightforward cases
83
if
(
a
==
"*"
)
return
true
;
84
if
(
a
==b)
return
true
;
85
// wildcards
86
bool
returnValue=
true
;
87
std::string temp=b;
88
//FIXME This next bit is a bit hacky
89
const
std::vector<std::string> tokens =
CxxUtils::tokenize
(
a
,
'*'
);
90
for
(
unsigned
int
i=0;i<tokens.size();i++)
91
{
92
if
(tokens[i].
empty
())
continue
;
93
std::string::size_type npos=temp.find(tokens[i]);
94
if
(i==0 && npos)
95
return
false
;
96
if
(npos!=std::string::npos)
97
{
98
temp=temp.substr(npos, temp.size()-npos);
99
}
100
else
101
{
102
returnValue=
false
;
103
break
;
104
}
105
}
106
if
(returnValue && !tokens[tokens.size()-1].empty())
107
{
108
std::string temp=tokens[tokens.size()-1];
109
std::string temp2=b.substr(b.size()-temp.size(),temp.size());
110
if
(temp!=temp2)
111
return
false
;
112
}
113
return
returnValue;
114
}
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
StringUtils.h
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
UserLimitsSvc.h
empty
static const Attributes_t empty
Definition
XmlStreamer.cxx:16
UserLimitsSvc::m_logicalVolumes
Gaudi::Property< std::vector< std::string > > m_logicalVolumes
List of Logical volume to which these limits should be applied.
Definition
UserLimitsSvc.h:46
UserLimitsSvc::m_MaxTime
Gaudi::Property< double > m_MaxTime
Maximum global time for a track.
Definition
UserLimitsSvc.h:40
UserLimitsSvc::m_MinRange
Gaudi::Property< double > m_MinRange
Minimum remaining range for a track.
Definition
UserLimitsSvc.h:42
UserLimitsSvc::isMatch
bool isMatch(const std::string &pattern, const std::string &logicalVolume) const
Functions for string comparison.
Definition
UserLimitsSvc.cxx:80
UserLimitsSvc::initialize
virtual StatusCode initialize() override final
Definition
UserLimitsSvc.cxx:22
UserLimitsSvc::contains
bool contains(const std::string &pattern, const std::string &logicalVolume) const
Definition
UserLimitsSvc.cxx:75
UserLimitsSvc::m_MinEkine
Gaudi::Property< double > m_MinEkine
Minimum remaining kinetic energy for a track.
Definition
UserLimitsSvc.h:36
UserLimitsSvc::m_matchType
Gaudi::Property< std::string > m_matchType
Use 'contains' or 'isMatch' function for string comparison.
Definition
UserLimitsSvc.h:44
UserLimitsSvc::UserLimitsSvc
UserLimitsSvc(const std::string &name, ISvcLocator *pSvcLocator)
Definition
UserLimitsSvc.cxx:16
UserLimitsSvc::m_MaxTrackLength
Gaudi::Property< double > m_MaxTrackLength
Maximum total track length.
Definition
UserLimitsSvc.h:38
UserLimitsSvc::m_MaxStep
Gaudi::Property< double > m_MaxStep
Maximum step length.
Definition
UserLimitsSvc.h:34
CxxUtils::tokenize
std::vector< std::string > tokenize(std::string_view the_str, std::string_view delimiters)
Splits the string into smaller substrings.
Definition
Control/CxxUtils/Root/StringUtils.cxx:12
Generated on
for ATLAS Offline Software by
1.17.0