GeomVolSelectorBasic.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Robert Hatcher <rhatcher@fnal.gov>
8 
9  For the class documentation see the corresponding header file.
10 
11  Important revisions after version 2.0.0 :
12  @ February 04, 2010 - RWH
13  Was first added in v2.5.1.
14  Introduce GeomVolSelectorBasic as concrete example of GeomVolSelectorI that
15  accepts/rejects path segments based on volume name, material, medium, or
16  path in geometry hierarchy.
17 
18 */
19 //____________________________________________________________________________
20 
25 
26 using namespace genie;
27 using namespace genie::geometry;
28 
29 #include <TGeoVolume.h>
30 #include <TGeoMaterial.h>
31 #include <TGeoMedium.h>
32 
33 //____________________________________________________________________________
35  : GeomVolSelectorI("Basic")
36 {
37 
38 }
39 
40 //___________________________________________________________________________
42 {
43 
44 }
45 
46 //___________________________________________________________________________
48 {
50 }
52 {
54 }
56 {
58 }
60 {
62  if ( fRequiredPath.size() > 0 || fForbiddenPath.size() > 0 ) {
63 #ifdef PATHSEG_KEEP_PATH
64  SetNeedPath();
65 #else
66  LOG("GeomVolSelectorBasic", pFATAL)
67  << "PathSegment is not defined to hold fPathString -- selectors can not cut on it";
68 #endif
69  }
70 }
71 
72 //___________________________________________________________________________
73 // nothing special needs to be done at the beginning or end of a new PathSegmentList
74 void GeomVolSelectorBasic::BeginPSList(const PathSegmentList* /* untrimmed */ ) const
75 { ; }
76 
78 { ; }
79 
80 //___________________________________________________________________________
82 {
83  bool reject = false;
84 
85  // not splitting PathSegment into 2 or more PathSegment elements
86  // so either
87  // - keep "as is"
88  // - adjust the low/high endpoints
89  // - not copy to output list (
90  // be careful about steps outside all the geometry that might not
91  // have an associated volume/media/material
92 
93 
94  if ( ! reject ) {
95  std::string volname = ( ps.fVolume) ? ps.fVolume->GetName() : "no-volume";
96  reject = RejectString(volname,fRequiredVol,fForbiddenVol);
97  }
98 
99  if ( ! reject ) {
100  std::string medname = ( ps.fMedium) ? ps.fMedium->GetName() : "no-medium";
101  reject = RejectString(medname,fRequiredMed,fForbiddenMed);
102  }
103 
104  if ( ! reject ) {
105  std::string matname = ( ps.fMaterial) ? ps.fMaterial->GetName() : "no-material";
106  reject = RejectString(matname,fRequiredMat,fForbiddenMat);
107  }
108 
109 #ifdef PATHSEG_KEEP_PATH
110  if ( ! reject ) {
112  }
113 #endif
114 
115  if ( reject ) ps.fStepRangeSet.clear();
116 
117 }
118 
119 //___________________________________________________________________________
120 void GeomVolSelectorBasic::ParseSelection(const string& strall,
121  vector<string>& required,
122  vector<string>& forbidden)
123 {
124  required.clear();
125  forbidden.clear();
126  vector<string> pieces = genie::utils::str::Split(strall,":;,");
127  size_t n = pieces.size();
128  for ( size_t i = 0; i < n; ++i ) {
129  string& strone = pieces[i];
130  if ( strone == "" ) continue; // reject null strings
131  if ( strone.find("-") == 0 ) forbidden.push_back(strone.substr(1,std::string::npos));
132  else if ( strone.find("+") == 0 ) required.push_back(strone.substr(1,std::string::npos));
133  else required.push_back(strone);
134  }
135 }
136 //___________________________________________________________________________
138  const vector<string>& required,
139  const vector<string>& forbidden) const
140 {
141  bool reject = false;
142 
143  // must have at least one of the required elements (if there are any)
144  size_t nrequired = required.size();
145  if ( nrequired > 0 ) {
146  bool found = false;
147  for (size_t jr = 0; jr < nrequired; ++jr) {
148  if ( str.find(required[jr]) != std::string::npos ) {
149  found = true;
150  break; // found at least one case, so we're good
151  }
152  }
153  if ( ! found ) reject = true;
154  }
155 
156  // can not have any of the forbidden elements
157  size_t nforbidden = forbidden.size();
158  if ( nforbidden > 0 ) {
159  for (size_t jf = 0; jf < nforbidden; ++jf) {
160  if ( str.find(forbidden[jf]) != std::string::npos ) {
161  reject = true;
162  break; // found at least one case, so we can reject
163  }
164  }
165  }
166 
167  return reject;
168 }
169 //___________________________________________________________________________
170 
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
StepRangeSet fStepRangeSet
collection of {steplo,stephi} pairs
#define pFATAL
Definition: Messenger.h:57
GENIE geometry drivers.
Object to be filled with the neutrino path-segments representing geometry volume steps (generally bou...
GENIE Interface for user-defined volume selector functors.
const TGeoMaterial * fMaterial
ref only ptr to TGeoMaterial
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
const TGeoVolume * fVolume
ref only ptr to TGeoVolume
const TGeoMedium * fMedium
ref only ptr to TGeoMedium
void ParseSelection(const string &str, vector< string > &required, vector< string > &forbidden)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:42
void TrimSegment(PathSegment &segment) const
bool RejectString(const string &str, const vector< string > &required, const vector< string > &forbidden) const
void BeginPSList(const PathSegmentList *untrimmed) const
std::string fPathString
full path names