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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /digits_hits/detector/src/G4SDStructure.cc (Version 11.3.0) and /digits_hits/detector/src/G4SDStructure.cc (Version 11.0.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 //                                                 27 //
 28                                                    28 
 29 // G4SDStructure                                   29 // G4SDStructure
 30 #include "G4SDStructure.hh"                        30 #include "G4SDStructure.hh"
 31                                                << 
 32 #include "G4ios.hh"                                31 #include "G4ios.hh"
 33                                                    32 
 34 G4SDStructure::G4SDStructure(const G4String& a     33 G4SDStructure::G4SDStructure(const G4String& aPath)
                                                   >>  34   : verboseLevel(0)
 35 {                                                  35 {
 36   pathName = aPath;                                36   pathName = aPath;
 37   dirName = aPath;                             <<  37   dirName  = aPath;
 38   auto i = dirName.length();                   <<  38   G4int i  = dirName.length();
 39   if (i > 1) {                                 <<  39   if(i > 1)
                                                   >>  40   {
 40     dirName.erase(i - 1);                          41     dirName.erase(i - 1);
 41     auto isl = dirName.rfind('/');             <<  42     G4int isl = dirName.rfind('/');
 42     dirName.erase(0, isl + 1);                     43     dirName.erase(0, isl + 1);
 43     dirName += "/";                                44     dirName += "/";
 44   }                                                45   }
 45 }                                                  46 }
 46                                                    47 
 47 G4SDStructure::~G4SDStructure()                    48 G4SDStructure::~G4SDStructure()
 48 {                                                  49 {
 49   for (auto st : structure)                    <<  50   for(auto st : structure)
 50     delete st;                                     51     delete st;
 51   structure.clear();                               52   structure.clear();
 52   for (auto dt : detector)                     <<  53   for(auto dt : detector)
 53     delete dt;                                     54     delete dt;
 54   detector.clear();                                55   detector.clear();
 55 }                                                  56 }
 56                                                    57 
 57 G4bool G4SDStructure::operator==(const G4SDStr <<  58 G4bool G4SDStructure::operator==(const G4SDStructure& right) const
                                                   >>  59 {
                                                   >>  60   return (this == &right);
                                                   >>  61 }
 58                                                    62 
 59 void G4SDStructure::AddNewDetector(G4VSensitiv <<  63 void G4SDStructure::AddNewDetector(G4VSensitiveDetector* aSD,
                                                   >>  64                                    const G4String& treeStructure)
 60 {                                                  65 {
 61   G4String remainingPath = treeStructure;          66   G4String remainingPath = treeStructure;
 62   remainingPath.erase(0, pathName.length());       67   remainingPath.erase(0, pathName.length());
 63   if (! remainingPath.empty()) {  // The detec <<  68   if(!remainingPath.empty())
 64                                   // First, ch <<  69   {  // The detector should be kept in subdirectory.
 65     G4String subD = ExtractDirName(remainingPa <<  70      // First, check if the subdirectoy exists.
                                                   >>  71     G4String subD         = ExtractDirName(remainingPath);
 66     G4SDStructure* tgtSDS = FindSubDirectory(s     72     G4SDStructure* tgtSDS = FindSubDirectory(subD);
 67     if (tgtSDS == nullptr) {  // Subdirectory  <<  73     if(tgtSDS == nullptr)
                                                   >>  74     {  // Subdirectory not found. Create a new directory.
 68       subD.insert(0, pathName);                    75       subD.insert(0, pathName);
 69       tgtSDS = new G4SDStructure(subD);            76       tgtSDS = new G4SDStructure(subD);
 70       structure.push_back(tgtSDS);                 77       structure.push_back(tgtSDS);
 71     }                                              78     }
 72     tgtSDS->AddNewDetector(aSD, treeStructure)     79     tgtSDS->AddNewDetector(aSD, treeStructure);
 73   }                                                80   }
 74   else {  // The sensitive detector should be  <<  81   else
                                                   >>  82   {  // The sensitive detector should be kept in this directory.
 75     G4VSensitiveDetector* tgtSD = GetSD(aSD->G     83     G4VSensitiveDetector* tgtSD = GetSD(aSD->GetName());
 76     if (tgtSD == nullptr) {                    <<  84     if(!tgtSD)
                                                   >>  85     {
 77       detector.push_back(aSD);                     86       detector.push_back(aSD);
 78     }                                              87     }
 79     else if (tgtSD != aSD) {                   <<  88     else if(tgtSD != aSD)
                                                   >>  89     {
 80 #ifdef G4VERBOSE                                   90 #ifdef G4VERBOSE
 81       G4ExceptionDescription ed;                   91       G4ExceptionDescription ed;
 82       ed << aSD->GetName() << " had already be     92       ed << aSD->GetName() << " had already been stored in " << pathName
 83          << ". Object pointer is overwritten.\     93          << ". Object pointer is overwritten.\n";
 84       ed << "It's users' responsibility to del     94       ed << "It's users' responsibility to delete the old sensitive detector "
 85             "object.";                             95             "object.";
 86       G4Exception("G4SDStructure::AddNewDetect <<  96       G4Exception("G4SDStructure::AddNewDetector()", "DET1010", JustWarning,
                                                   >>  97                   ed);
 87 #endif                                             98 #endif
 88       RemoveSD(tgtSD);                             99       RemoveSD(tgtSD);
 89       detector.push_back(aSD);                    100       detector.push_back(aSD);
 90     }                                             101     }
 91   }                                               102   }
 92 }                                                 103 }
 93                                                   104 
 94 G4SDStructure* G4SDStructure::FindSubDirectory    105 G4SDStructure* G4SDStructure::FindSubDirectory(const G4String& subD)
 95 {                                                 106 {
 96   for (auto st : structure) {                  << 107   for(auto st : structure)
 97     if (subD == st->dirName) return st;        << 108   {
                                                   >> 109     if(subD == st->dirName)
                                                   >> 110       return st;
 98   }                                               111   }
 99   return nullptr;                                 112   return nullptr;
100 }                                                 113 }
101                                                   114 
102 G4VSensitiveDetector* G4SDStructure::GetSD(con    115 G4VSensitiveDetector* G4SDStructure::GetSD(const G4String& aSDName)
103 {                                                 116 {
104   for (auto det : detector) {                  << 117   for(auto det : detector)
105     if (aSDName == det->GetName()) return det; << 118   {
                                                   >> 119     if(aSDName == det->GetName())
                                                   >> 120       return det;
106   }                                               121   }
107   return nullptr;                                 122   return nullptr;
108 }                                                 123 }
109                                                   124 
110 void G4SDStructure::RemoveSD(G4VSensitiveDetec    125 void G4SDStructure::RemoveSD(G4VSensitiveDetector* sd)
111 {                                                 126 {
112   auto det = std::find(detector.begin(), detec    127   auto det = std::find(detector.begin(), detector.end(), sd);
113   if (det != detector.end()) detector.erase(de << 128   if(det != detector.end())
                                                   >> 129     detector.erase(det);
114 }                                                 130 }
115                                                   131 
116 G4String G4SDStructure::ExtractDirName(const G    132 G4String G4SDStructure::ExtractDirName(const G4String& aName)
117 {                                                 133 {
118   G4String subD = aName;                          134   G4String subD = aName;
119   auto i = aName.find('/');                    << 135   auto i       = aName.find('/');
120   if (i != G4String::npos) subD.erase(i + 1);  << 136   if(i != G4String::npos)
                                                   >> 137     subD.erase(i + 1);
121   return subD;                                    138   return subD;
122 }                                                 139 }
123                                                   140 
124 void G4SDStructure::Activate(const G4String& a    141 void G4SDStructure::Activate(const G4String& aName, G4bool sensitiveFlag)
125 {                                                 142 {
126   G4String aPath = aName;                         143   G4String aPath = aName;
127   aPath.erase(0, pathName.length());              144   aPath.erase(0, pathName.length());
128   if (aPath.find('/') != std::string::npos) {  << 145   if(aPath.find('/') != std::string::npos)
129     G4String subD = ExtractDirName(aPath);     << 146   {  // Command is ordered for a subdirectory.
                                                   >> 147     G4String subD         = ExtractDirName(aPath);
130     G4SDStructure* tgtSDS = FindSubDirectory(s    148     G4SDStructure* tgtSDS = FindSubDirectory(subD);
131     if (tgtSDS == nullptr) {  // The subdirect << 149     if(tgtSDS == nullptr)
                                                   >> 150     {  // The subdirectory is not found
132       G4cout << subD << " is not found in " <<    151       G4cout << subD << " is not found in " << pathName << G4endl;
133     }                                             152     }
134     else {                                     << 153     else
                                                   >> 154     {
135       tgtSDS->Activate(aName, sensitiveFlag);     155       tgtSDS->Activate(aName, sensitiveFlag);
136     }                                             156     }
137   }                                               157   }
138   else if (aPath.empty()) {  // Command is ord << 158   else if(aPath.empty())
139     for (auto det : detector)                  << 159   {  // Command is ordered for all detectors in this directory.
                                                   >> 160     for(auto det : detector)
140       det->Activate(sensitiveFlag);               161       det->Activate(sensitiveFlag);
141     for (auto st : structure)                  << 162     for(auto st : structure)
142       st->Activate(G4String("/"), sensitiveFla    163       st->Activate(G4String("/"), sensitiveFlag);
143   }                                               164   }
144   else {  // Command is ordered to a particula << 165   else
                                                   >> 166   {  // Command is ordered to a particular detector.
145     G4VSensitiveDetector* tgtSD = GetSD(aPath)    167     G4VSensitiveDetector* tgtSD = GetSD(aPath);
146     if (tgtSD == nullptr) {  // The detector i << 168     if(tgtSD == nullptr)
                                                   >> 169     {  // The detector is not found.
147       G4cout << aPath << " is not found in " <    170       G4cout << aPath << " is not found in " << pathName << G4endl;
148     }                                             171     }
149     else {                                     << 172     else
                                                   >> 173     {
150       tgtSD->Activate(sensitiveFlag);             174       tgtSD->Activate(sensitiveFlag);
151     }                                             175     }
152   }                                               176   }
153 }                                                 177 }
154                                                   178 
155 G4VSensitiveDetector* G4SDStructure::FindSensi << 179 G4VSensitiveDetector* G4SDStructure::FindSensitiveDetector(
                                                   >> 180   const G4String& aName, G4bool warning)
156 {                                                 181 {
157   G4String aPath = aName;                         182   G4String aPath = aName;
158   aPath.erase(0, pathName.length());              183   aPath.erase(0, pathName.length());
159   if (aPath.find('/') != std::string::npos) {  << 184   if(aPath.find('/') != std::string::npos)
160     G4String subD = ExtractDirName(aPath);     << 185   {  // SD exists in sub-directory
                                                   >> 186     G4String subD         = ExtractDirName(aPath);
161     G4SDStructure* tgtSDS = FindSubDirectory(s    187     G4SDStructure* tgtSDS = FindSubDirectory(subD);
162     if (tgtSDS == nullptr) {  // The subdirect << 188     if(tgtSDS == nullptr)
163       if (warning) G4cout << subD << " is not  << 189     {  // The subdirectory is not found
                                                   >> 190       if(warning)
                                                   >> 191         G4cout << subD << " is not found in " << pathName << G4endl;
164       return nullptr;                             192       return nullptr;
165     }                                             193     }
166                                                << 194     else
167     return tgtSDS->FindSensitiveDetector(aName << 195     {
                                                   >> 196       return tgtSDS->FindSensitiveDetector(aName, warning);
                                                   >> 197     }
168   }                                               198   }
169                                                << 199   else
170   // SD must exist in this directory           << 200   {  // SD must exist in this directory
171   G4VSensitiveDetector* tgtSD = GetSD(aPath);  << 201     G4VSensitiveDetector* tgtSD = GetSD(aPath);
172   if (tgtSD == nullptr) {  // The detector is  << 202     if(tgtSD == nullptr)
173     if (warning) G4cout << aPath << " is not f << 203     {  // The detector is not found.
                                                   >> 204       if(warning)
                                                   >> 205         G4cout << aPath << " is not found in " << pathName << G4endl;
                                                   >> 206     }
                                                   >> 207     return tgtSD;
174   }                                               208   }
175   return tgtSD;                                << 
176 }                                                 209 }
177                                                   210 
178 void G4SDStructure::Initialize(G4HCofThisEvent    211 void G4SDStructure::Initialize(G4HCofThisEvent* HCE)
179 {                                                 212 {
180   // Broadcast to subdirectories.                 213   // Broadcast to subdirectories.
181   for (auto st : structure) {                  << 214   for(auto st : structure)
                                                   >> 215   {
182     st->Initialize(HCE);                          216     st->Initialize(HCE);
183   }                                               217   }
184   // Initialize all detectors in this director    218   // Initialize all detectors in this directory.
185   for (auto dt : detector) {                   << 219   for(auto dt : detector)
186     if (dt->isActive()) dt->Initialize(HCE);   << 220   {
                                                   >> 221     if(dt->isActive())
                                                   >> 222       dt->Initialize(HCE);
187   }                                               223   }
188 }                                                 224 }
189                                                   225 
190 void G4SDStructure::Terminate(G4HCofThisEvent*    226 void G4SDStructure::Terminate(G4HCofThisEvent* HCE)
191 {                                                 227 {
192   // Broadcast to subdirectories.                 228   // Broadcast to subdirectories.
193   for (auto st : structure) {                  << 229   for(auto st : structure)
                                                   >> 230   {
194     st->Terminate(HCE);                           231     st->Terminate(HCE);
195   }                                               232   }
196   // Terminate all detectors in this directory    233   // Terminate all detectors in this directory.
197   for (auto dt : detector) {                   << 234   for(auto dt : detector)
198     if (dt->isActive()) dt->EndOfEvent(HCE);   << 235   {
                                                   >> 236     if(dt->isActive())
                                                   >> 237       dt->EndOfEvent(HCE);
199   }                                               238   }
200 }                                                 239 }
201                                                   240 
202 void G4SDStructure::ListTree()                    241 void G4SDStructure::ListTree()
203 {                                                 242 {
204   G4cout << pathName << G4endl;                   243   G4cout << pathName << G4endl;
205   for (auto sd : detector) {                   << 244   for(auto sd : detector)
                                                   >> 245   {
206     G4cout << pathName << sd->GetName();          246     G4cout << pathName << sd->GetName();
207     if (sd->isActive()) {                      << 247     if(sd->isActive())
                                                   >> 248     {
208       G4cout << "   *** Active ";                 249       G4cout << "   *** Active ";
209     }                                             250     }
210     else {                                     << 251     else
                                                   >> 252     {
211       G4cout << "   XXX Inactive ";               253       G4cout << "   XXX Inactive ";
212     }                                             254     }
213     G4cout << G4endl;                             255     G4cout << G4endl;
214   }                                               256   }
215   for (auto st : structure)                    << 257   for(auto st : structure)
216     st->ListTree();                               258     st->ListTree();
217 }                                                 259 }
218                                                   260