ATLAS Offline Software
Loading...
Searching...
No Matches
UserLimitsSvc Class Referencefinal

Concrete Tool to apply G4 User Limits. More...

#include "G4AtlasTools/UserLimitsSvc.h"

Inheritance diagram for UserLimitsSvc:
Collaboration diagram for UserLimitsSvc:

Public Member Functions

 UserLimitsSvc (const std::string &name, ISvcLocator *pSvcLocator)
virtual ~UserLimitsSvc ()=default
virtual StatusCode initialize () override final

Private Member Functions

bool isMatch (const std::string &pattern, const std::string &logicalVolume) const
 Functions for string comparison.
bool contains (const std::string &pattern, const std::string &logicalVolume) const

Private Attributes

Gaudi::Property< double > m_MaxStep {this, "MaxStep", -1., "Maximum step length"}
 Maximum step length.
Gaudi::Property< double > m_MinEkine {this, "MinEkine", -1., "Minimum remaining kinetic energy for a track"}
 Minimum remaining kinetic energy for a track.
Gaudi::Property< double > m_MaxTrackLength {this, "MaxTrackLength", -1., "Maximum total track length"}
 Maximum total track length.
Gaudi::Property< double > m_MaxTime {this, "MaxTime", -1., "Maximum global time for a track"}
 Maximum global time for a track.
Gaudi::Property< double > m_MinRange {this, "MinRange", -1., "Minimum remaining range for a track"}
 Minimum remaining range for a track.
Gaudi::Property< std::string > m_matchType {this, "MatchType", "isMatch", "Use 'contains' or 'isMatch' function for string comparison"}
 Use 'contains' or 'isMatch' function for string comparison.
Gaudi::Property< std::vector< std::string > > m_logicalVolumes {this, "VolumeList" , {}, "List of Logical volume to which these limits should be applied"}
 List of Logical volume to which these limits should be applied.

Detailed Description

Concrete Tool to apply G4 User Limits.

Definition at line 21 of file UserLimitsSvc.h.

Constructor & Destructor Documentation

◆ UserLimitsSvc()

UserLimitsSvc::UserLimitsSvc ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 16 of file UserLimitsSvc.cxx.

17 : base_class(name,pSvcLocator)
18{
19}

◆ ~UserLimitsSvc()

virtual UserLimitsSvc::~UserLimitsSvc ( )
virtualdefault

Member Function Documentation

◆ contains()

bool UserLimitsSvc::contains ( const std::string & pattern,
const std::string & logicalVolume ) const
private

Definition at line 75 of file UserLimitsSvc.cxx.

76{
77 return (logicalVolume.find(pattern) != std::string::npos);
78}

◆ initialize()

StatusCode UserLimitsSvc::initialize ( )
finaloverridevirtual

Definition at line 22 of file UserLimitsSvc.cxx.

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}
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Property< std::vector< std::string > > m_logicalVolumes
List of Logical volume to which these limits should be applied.
Gaudi::Property< double > m_MaxTime
Maximum global time for a track.
Gaudi::Property< double > m_MinRange
Minimum remaining range for a track.
bool isMatch(const std::string &pattern, const std::string &logicalVolume) const
Functions for string comparison.
bool contains(const std::string &pattern, const std::string &logicalVolume) const
Gaudi::Property< double > m_MinEkine
Minimum remaining kinetic energy for a track.
Gaudi::Property< std::string > m_matchType
Use 'contains' or 'isMatch' function for string comparison.
UserLimitsSvc(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< double > m_MaxTrackLength
Maximum total track length.
Gaudi::Property< double > m_MaxStep
Maximum step length.
unsigned long ul
setBGCode setTAP setLVL2ErrorBits bool

◆ isMatch()

bool UserLimitsSvc::isMatch ( const std::string & pattern,
const std::string & logicalVolume ) const
private

Functions for string comparison.

Definition at line 80 of file UserLimitsSvc.cxx.

81{
82 // straightforward cases
83 if (a=="*") return true;
84 if (a==b) return true;
85 // wildcards
86 boost::char_separator<char> sep{"*"};
87 typedef boost::tokenizer< boost::char_separator<char> > tokenizer;
88 tokenizer tok{a, sep};
89 bool returnValue=true;
90 std::string temp=b;
91 //FIXME This next bit is a bit hacky
92 std::vector<std::string> tokens;
93 for (const auto& token : tok)
94 {
95 tokens.push_back(token);
96 }
97 for (unsigned int i=0;i<tokens.size();i++)
98 {
99 if (tokens[i].empty()) continue;
100 std::string::size_type npos=temp.find(tokens[i]);
101 if (i==0 && npos)
102 return false;
103 if (npos!=std::string::npos)
104 {
105 temp=temp.substr(npos, temp.size()-npos);
106 }
107 else
108 {
109 returnValue=false;
110 break;
111 }
112 }
113 if (returnValue && !tokens[tokens.size()-1].empty())
114 {
115 std::string temp=tokens[tokens.size()-1];
116 std::string temp2=b.substr(b.size()-temp.size(),temp.size());
117 if (temp!=temp2)
118 return false;
119 }
120 return returnValue;
121}
static Double_t a
static const Attributes_t empty

Member Data Documentation

◆ m_logicalVolumes

Gaudi::Property<std::vector<std::string> > UserLimitsSvc::m_logicalVolumes {this, "VolumeList" , {}, "List of Logical volume to which these limits should be applied"}
private

List of Logical volume to which these limits should be applied.

Definition at line 46 of file UserLimitsSvc.h.

46{this, "VolumeList" , {}, "List of Logical volume to which these limits should be applied"};

◆ m_matchType

Gaudi::Property<std::string> UserLimitsSvc::m_matchType {this, "MatchType", "isMatch", "Use 'contains' or 'isMatch' function for string comparison"}
private

Use 'contains' or 'isMatch' function for string comparison.

Definition at line 44 of file UserLimitsSvc.h.

44{this, "MatchType", "isMatch", "Use 'contains' or 'isMatch' function for string comparison"};

◆ m_MaxStep

Gaudi::Property<double> UserLimitsSvc::m_MaxStep {this, "MaxStep", -1., "Maximum step length"}
private

Maximum step length.

Definition at line 34 of file UserLimitsSvc.h.

34{this, "MaxStep", -1., "Maximum step length"};

◆ m_MaxTime

Gaudi::Property<double> UserLimitsSvc::m_MaxTime {this, "MaxTime", -1., "Maximum global time for a track"}
private

Maximum global time for a track.

Definition at line 40 of file UserLimitsSvc.h.

40{this, "MaxTime", -1., "Maximum global time for a track"};

◆ m_MaxTrackLength

Gaudi::Property<double> UserLimitsSvc::m_MaxTrackLength {this, "MaxTrackLength", -1., "Maximum total track length"}
private

Maximum total track length.

Definition at line 38 of file UserLimitsSvc.h.

38{this, "MaxTrackLength", -1., "Maximum total track length"};

◆ m_MinEkine

Gaudi::Property<double> UserLimitsSvc::m_MinEkine {this, "MinEkine", -1., "Minimum remaining kinetic energy for a track"}
private

Minimum remaining kinetic energy for a track.

Definition at line 36 of file UserLimitsSvc.h.

36{this, "MinEkine", -1., "Minimum remaining kinetic energy for a track"};

◆ m_MinRange

Gaudi::Property<double> UserLimitsSvc::m_MinRange {this, "MinRange", -1., "Minimum remaining range for a track"}
private

Minimum remaining range for a track.

Definition at line 42 of file UserLimitsSvc.h.

42{this, "MinRange", -1., "Minimum remaining range for a track"};

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