ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
UserLimitsSvc Class Referencefinal

#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. More...
 
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. More...
 
Gaudi::Property< double > m_MinEkine {this, "MinEkine", -1., "Minimum remaining kinetic energy for a track"}
 Minimum remaining kinetic energy for a track. More...
 
Gaudi::Property< double > m_MaxTrackLength {this, "MaxTrackLength", -1., "Maximum total track length"}
 Maximum total track length. More...
 
Gaudi::Property< double > m_MaxTime {this, "MaxTime", -1., "Maximum global time for a track"}
 Maximum global time for a track. More...
 
Gaudi::Property< double > m_MinRange {this, "MinRange", -1., "Minimum remaining range for a track"}
 Minimum remaining range for a track. More...
 
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. More...
 
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. More...
 

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 }

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

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.

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

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

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

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

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

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


The documentation for this class was generated from the following files:
UserLimitsSvc::contains
bool contains(const std::string &pattern, const std::string &logicalVolume) const
Definition: UserLimitsSvc.cxx:75
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
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_MaxStep
Gaudi::Property< double > m_MaxStep
Maximum step length.
Definition: UserLimitsSvc.h:34
UserLimitsSvc::m_MinEkine
Gaudi::Property< double > m_MinEkine
Minimum remaining kinetic energy for a track.
Definition: UserLimitsSvc.h:36
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
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::m_MaxTrackLength
Gaudi::Property< double > m_MaxTrackLength
Maximum total track length.
Definition: UserLimitsSvc.h:38
lumiFormat.i
int i
Definition: lumiFormat.py:85
UserLimitsSvc::m_MaxTime
Gaudi::Property< double > m_MaxTime
Maximum global time for a track.
Definition: UserLimitsSvc.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
detail::ul
unsigned long ul
Definition: PrimitiveHelpers.h:46
grepfile.sep
sep
Definition: grepfile.py:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
UserLimitsSvc::m_matchType
Gaudi::Property< std::string > m_matchType
Use 'contains' or 'isMatch' function for string comparison.
Definition: UserLimitsSvc.h:44
a
TList * a
Definition: liststreamerinfos.cxx:10
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
UserLimitsSvc
Definition: UserLimitsSvc.h:21