9#include "G4LogicalVolume.hh"
10#include "G4LogicalVolumeStore.hh"
11#include "G4UserLimits.hh"
14#include <boost/tokenizer.hpp>
17 : base_class(name,pSvcLocator)
25 G4LogicalVolumeStore& lvs=*(G4LogicalVolumeStore::GetInstance());
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());
32 ATH_MSG_INFO(
"G4LogicalVolumeStore unique size: " << volumes.size());
35 using function_t = bool (
UserLimitsSvc::*) (
const std::string& pattern,
const std::string& logicalVolume)
const;
36 std::map<std::string, function_t> funcMap;
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)
45 const std::string& volName(*volumeItr);
46 unsigned int ndone(0);
47 for (
unsigned int i=0;i<lvs.size();i++)
49 G4LogicalVolume *lv=lvs[i];
51 if ( (this->*(funcMap[
m_matchType.value()]))(volName, lv->GetName()) ){
52 G4UserLimits *ul=lv->GetUserLimits();
53 if (!ul) ul=
new G4UserLimits;
59 lv->SetUserLimits(ul);
72 return StatusCode::SUCCESS;
77 return (logicalVolume.find(pattern) != std::string::npos);
83 if (
a==
"*")
return true;
84 if (
a==b)
return true;
86 boost::char_separator<char> sep{
"*"};
87 typedef boost::tokenizer< boost::char_separator<char> > tokenizer;
88 tokenizer tok{
a, sep};
89 bool returnValue=
true;
92 std::vector<std::string> tokens;
93 for (
const auto& token : tok)
95 tokens.push_back(token);
97 for (
unsigned int i=0;i<tokens.size();i++)
99 if (tokens[i].
empty())
continue;
100 std::string::size_type npos=temp.find(tokens[i]);
103 if (npos!=std::string::npos)
105 temp=temp.substr(npos, temp.size()-npos);
113 if (returnValue && !tokens[tokens.size()-1].empty())
115 std::string temp=tokens[tokens.size()-1];
116 std::string temp2=b.substr(b.size()-temp.size(),temp.size());
static const Attributes_t empty
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.
virtual StatusCode initialize() override final
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.