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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 9.5)


  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 // $Id: G4SDStructure.cc,v 1.3 2006-06-29 18:05:53 gunter Exp $
                                                   >>  28 // GEANT4 tag $Name: not supported by cvs2svn $
 27 //                                                 29 //
 28                                                    30 
 29 // G4SDStructure                                   31 // G4SDStructure
 30 #include "G4SDStructure.hh"                        32 #include "G4SDStructure.hh"
 31                                                << 
 32 #include "G4ios.hh"                                33 #include "G4ios.hh"
 33                                                    34 
 34 G4SDStructure::G4SDStructure(const G4String& a <<  35 G4SDStructure::G4SDStructure(G4String aPath):verboseLevel(0)
 35 {                                                  36 {
 36   pathName = aPath;                                37   pathName = aPath;
 37   dirName = aPath;                                 38   dirName = aPath;
 38   auto i = dirName.length();                   <<  39   G4int i = dirName.length();
 39   if (i > 1) {                                 <<  40   if( i > 1 )
 40     dirName.erase(i - 1);                      <<  41   {
 41     auto isl = dirName.rfind('/');             <<  42     dirName.remove(i-1);
 42     dirName.erase(0, isl + 1);                 <<  43     G4int isl = dirName.last('/');
                                                   >>  44     dirName.remove(0,isl+1);
 43     dirName += "/";                                45     dirName += "/";
 44   }                                                46   }
 45 }                                                  47 }
 46                                                    48 
 47 G4SDStructure::~G4SDStructure()                    49 G4SDStructure::~G4SDStructure()
 48 {                                                  50 {
 49   for (auto st : structure)                    <<  51   size_t nTree = structure.size();
 50     delete st;                                 <<  52   for(size_t iTree=0;iTree<nTree;iTree++)
 51   structure.clear();                           <<  53   { delete structure[iTree]; }
 52   for (auto dt : detector)                     <<  54   size_t nDet = detector.size();
 53     delete dt;                                 <<  55   for(size_t iDet=0;iDet<nDet;iDet++)
 54   detector.clear();                            <<  56   { delete detector[iDet]; }
 55 }                                                  57 }
 56                                                    58 
 57 G4bool G4SDStructure::operator==(const G4SDStr <<  59 G4int G4SDStructure::operator==(const G4SDStructure &right) const
                                                   >>  60 {
                                                   >>  61   return (this==&right);
                                                   >>  62 }
 58                                                    63 
 59 void G4SDStructure::AddNewDetector(G4VSensitiv <<  64 void G4SDStructure::AddNewDetector(G4VSensitiveDetector*aSD, 
                                                   >>  65                                    G4String treeStructure)
 60 {                                                  66 {
 61   G4String remainingPath = treeStructure;          67   G4String remainingPath = treeStructure;
 62   remainingPath.erase(0, pathName.length());   <<  68   remainingPath.remove(0,pathName.length());
 63   if (! remainingPath.empty()) {  // The detec <<  69   if( ! remainingPath.isNull() )
 64                                   // First, ch <<  70   {  // The detector should be kept in subdirectory.
 65     G4String subD = ExtractDirName(remainingPa <<  71      // First, check if the subdirectoy exists.
                                                   >>  72     G4String subD = ExtractDirName( remainingPath );
 66     G4SDStructure* tgtSDS = FindSubDirectory(s     73     G4SDStructure* tgtSDS = FindSubDirectory(subD);
 67     if (tgtSDS == nullptr) {  // Subdirectory  <<  74     if( tgtSDS == 0 )
 68       subD.insert(0, pathName);                <<  75     { // Subdirectory not found. Create a new directory.
                                                   >>  76       subD.prepend(pathName);
 69       tgtSDS = new G4SDStructure(subD);            77       tgtSDS = new G4SDStructure(subD);
 70       structure.push_back(tgtSDS);             <<  78       structure.push_back( tgtSDS );
 71     }                                              79     }
 72     tgtSDS->AddNewDetector(aSD, treeStructure) <<  80     tgtSDS->AddNewDetector(aSD,treeStructure);
 73   }                                                81   }
 74   else {  // The sensitive detector should be  <<  82   else
 75     G4VSensitiveDetector* tgtSD = GetSD(aSD->G <<  83   { // The sensitive detector should be kept in this directory.
 76     if (tgtSD == nullptr) {                    <<  84     G4VSensitiveDetector* tgtSD = GetSD( aSD->GetName() );
 77       detector.push_back(aSD);                 <<  85     if( tgtSD != 0 )
                                                   >>  86     {
                                                   >>  87       G4cout << aSD->GetName() << " had already stored in "
                                                   >>  88            << pathName << G4endl;
 78     }                                              89     }
 79     else if (tgtSD != aSD) {                   <<  90     else
 80 #ifdef G4VERBOSE                               <<  91     {
 81       G4ExceptionDescription ed;               <<  92       detector.push_back( aSD );
 82       ed << aSD->GetName() << " had already be << 
 83          << ". Object pointer is overwritten.\ << 
 84       ed << "It's users' responsibility to del << 
 85             "object.";                         << 
 86       G4Exception("G4SDStructure::AddNewDetect << 
 87 #endif                                         << 
 88       RemoveSD(tgtSD);                         << 
 89       detector.push_back(aSD);                 << 
 90     }                                              93     }
 91   }                                                94   }
 92 }                                                  95 }
 93                                                    96 
 94 G4SDStructure* G4SDStructure::FindSubDirectory <<  97 G4SDStructure* G4SDStructure::FindSubDirectory(G4String subD)
 95 {                                                  98 {
 96   for (auto st : structure) {                  <<  99   for( size_t i=0; i<structure.size(); i++ )
 97     if (subD == st->dirName) return st;        << 100   {
 98   }                                            << 101     if( subD == structure[i]->dirName ) return structure[i];
 99   return nullptr;                              << 102   } 
                                                   >> 103   return 0;
100 }                                                 104 }
101                                                   105 
102 G4VSensitiveDetector* G4SDStructure::GetSD(con << 106 G4VSensitiveDetector* G4SDStructure::GetSD(G4String aSDName)
103 {                                                 107 {
104   for (auto det : detector) {                  << 108   for( size_t i=0; i<detector.size(); i++ )
105     if (aSDName == det->GetName()) return det; << 109   {
                                                   >> 110     G4VSensitiveDetector* tgtSD = detector[i];
                                                   >> 111     if( aSDName == tgtSD->GetName() ) return tgtSD;
106   }                                               112   }
107   return nullptr;                              << 113   return 0;
108 }                                                 114 }
109                                                   115 
110 void G4SDStructure::RemoveSD(G4VSensitiveDetec << 116 G4String G4SDStructure::ExtractDirName(G4String aName)
111 {                                              << 
112   auto det = std::find(detector.begin(), detec << 
113   if (det != detector.end()) detector.erase(de << 
114 }                                              << 
115                                                << 
116 G4String G4SDStructure::ExtractDirName(const G << 
117 {                                                 117 {
118   G4String subD = aName;                          118   G4String subD = aName;
119   auto i = aName.find('/');                    << 119   G4int i = aName.first('/');
120   if (i != G4String::npos) subD.erase(i + 1);  << 120   if( i != G4int(std::string::npos) ) subD.remove(i+1);
121   return subD;                                    121   return subD;
122 }                                                 122 }
123                                                   123 
124 void G4SDStructure::Activate(const G4String& a << 124 void G4SDStructure::Activate(G4String aName, G4bool sensitiveFlag)
125 {                                                 125 {
126   G4String aPath = aName;                         126   G4String aPath = aName;
127   aPath.erase(0, pathName.length());           << 127   aPath.remove(0,pathName.length());
128   if (aPath.find('/') != std::string::npos) {  << 128   if( aPath.first('/') != G4int(std::string::npos) )
                                                   >> 129   {  // Command is ordered for a subdirectory.
129     G4String subD = ExtractDirName(aPath);        130     G4String subD = ExtractDirName(aPath);
130     G4SDStructure* tgtSDS = FindSubDirectory(s    131     G4SDStructure* tgtSDS = FindSubDirectory(subD);
131     if (tgtSDS == nullptr) {  // The subdirect << 132     if( tgtSDS == 0 )
                                                   >> 133     {  // The subdirectory is not found
132       G4cout << subD << " is not found in " <<    134       G4cout << subD << " is not found in " << pathName << G4endl;
133     }                                             135     }
134     else {                                     << 136     else
135       tgtSDS->Activate(aName, sensitiveFlag);  << 137     { 
                                                   >> 138       tgtSDS->Activate(aName,sensitiveFlag);
136     }                                             139     }
137   }                                               140   }
138   else if (aPath.empty()) {  // Command is ord << 141   else if( aPath.isNull() )
139     for (auto det : detector)                  << 142   {  // Command is ordered for all detectors in this directory.
140       det->Activate(sensitiveFlag);            << 143     for( size_t i=0; i<detector.size(); i++)
141     for (auto st : structure)                  << 144     { 
142       st->Activate(G4String("/"), sensitiveFla << 145       detector[i]->Activate(sensitiveFlag);
                                                   >> 146     }
                                                   >> 147     for( size_t j=0;j<structure.size(); j++)
                                                   >> 148     {
                                                   >> 149       structure[j]->Activate(G4String("/"),sensitiveFlag);
                                                   >> 150     }
143   }                                               151   }
144   else {  // Command is ordered to a particula << 152   else
                                                   >> 153   {  // Command is ordered to a particular detector.
145     G4VSensitiveDetector* tgtSD = GetSD(aPath)    154     G4VSensitiveDetector* tgtSD = GetSD(aPath);
146     if (tgtSD == nullptr) {  // The detector i << 155     if( tgtSD == 0 )
                                                   >> 156     {  // The detector is not found.
147       G4cout << aPath << " is not found in " <    157       G4cout << aPath << " is not found in " << pathName << G4endl;
148     }                                             158     }
149     else {                                     << 159     else
                                                   >> 160     {
150       tgtSD->Activate(sensitiveFlag);             161       tgtSD->Activate(sensitiveFlag);
151     }                                             162     }
152   }                                               163   }
153 }                                                 164 }
154                                                   165 
155 G4VSensitiveDetector* G4SDStructure::FindSensi << 166 G4VSensitiveDetector* G4SDStructure::FindSensitiveDetector(G4String aName, G4bool warning)
156 {                                                 167 {
157   G4String aPath = aName;                         168   G4String aPath = aName;
158   aPath.erase(0, pathName.length());           << 169   aPath.remove(0,pathName.length());
159   if (aPath.find('/') != std::string::npos) {  << 170   if( aPath.first('/') != G4int(std::string::npos) )
                                                   >> 171   { // SD exists in sub-directory
160     G4String subD = ExtractDirName(aPath);        172     G4String subD = ExtractDirName(aPath);
161     G4SDStructure* tgtSDS = FindSubDirectory(s    173     G4SDStructure* tgtSDS = FindSubDirectory(subD);
162     if (tgtSDS == nullptr) {  // The subdirect << 174     if( tgtSDS == 0 )
163       if (warning) G4cout << subD << " is not  << 175     {  // The subdirectory is not found
164       return nullptr;                          << 176       if (warning)
                                                   >> 177         G4cout << subD << " is not found in " << pathName << G4endl;
                                                   >> 178       return 0;
                                                   >> 179     }
                                                   >> 180     else
                                                   >> 181     {
                                                   >> 182       return tgtSDS->FindSensitiveDetector(aName);
165     }                                             183     }
166                                                << 
167     return tgtSDS->FindSensitiveDetector(aName << 
168   }                                               184   }
169                                                << 185   else
170   // SD must exist in this directory           << 186   { // SD must exist in this directory
171   G4VSensitiveDetector* tgtSD = GetSD(aPath);  << 187     G4VSensitiveDetector* tgtSD = GetSD(aPath);
172   if (tgtSD == nullptr) {  // The detector is  << 188     if( tgtSD == 0 )
173     if (warning) G4cout << aPath << " is not f << 189     {  // The detector is not found.
                                                   >> 190       if (warning)
                                                   >> 191         G4cout << aPath << " is not found in " << pathName << G4endl;
                                                   >> 192     }
                                                   >> 193     return tgtSD;
174   }                                               194   }
175   return tgtSD;                                << 
176 }                                                 195 }
177                                                   196 
178 void G4SDStructure::Initialize(G4HCofThisEvent << 197 void G4SDStructure::Initialize(G4HCofThisEvent*HCE)
179 {                                                 198 {
                                                   >> 199   size_t i;
180   // Broadcast to subdirectories.                 200   // Broadcast to subdirectories.
181   for (auto st : structure) {                  << 201   for( i=0; i<structure.size(); i++ )
182     st->Initialize(HCE);                       << 202   {
                                                   >> 203     structure[i]->Initialize(HCE);
183   }                                               204   }
184   // Initialize all detectors in this director    205   // Initialize all detectors in this directory.
185   for (auto dt : detector) {                   << 206   for( i=0; i<detector.size(); i++ )
186     if (dt->isActive()) dt->Initialize(HCE);   << 207   {
                                                   >> 208     if(detector[i]->isActive()) detector[i]->Initialize(HCE);
187   }                                               209   }
188 }                                                 210 }
189                                                   211 
190 void G4SDStructure::Terminate(G4HCofThisEvent* << 212 void G4SDStructure::Terminate(G4HCofThisEvent*HCE)
191 {                                                 213 {
                                                   >> 214   size_t i;
192   // Broadcast to subdirectories.                 215   // Broadcast to subdirectories.
193   for (auto st : structure) {                  << 216   for( i=0; i<structure.size(); i++ )
194     st->Terminate(HCE);                        << 217   {
                                                   >> 218     structure[i]->Terminate(HCE);
195   }                                               219   }
196   // Terminate all detectors in this directory << 220   // Initialize all detectors in this directory.
197   for (auto dt : detector) {                   << 221   for( i=0; i<detector.size(); i++ )
198     if (dt->isActive()) dt->EndOfEvent(HCE);   << 222   {
                                                   >> 223     if(detector[i]->isActive()) detector[i]->EndOfEvent(HCE);
199   }                                               224   }
200 }                                                 225 }
201                                                   226 
202 void G4SDStructure::ListTree()                    227 void G4SDStructure::ListTree()
203 {                                                 228 {
204   G4cout << pathName << G4endl;                   229   G4cout << pathName << G4endl;
205   for (auto sd : detector) {                   << 230   for(size_t i=0; i<detector.size(); i++)
                                                   >> 231   {
                                                   >> 232     G4VSensitiveDetector* sd = detector[i];
206     G4cout << pathName << sd->GetName();          233     G4cout << pathName << sd->GetName();
207     if (sd->isActive()) {                      << 234     if( sd->isActive() )
208       G4cout << "   *** Active ";              << 235     { G4cout << "   *** Active "; }
209     }                                          << 236     else
210     else {                                     << 237     { G4cout << "   XXX Inactive "; }
211       G4cout << "   XXX Inactive ";            << 
212     }                                          << 
213     G4cout << G4endl;                             238     G4cout << G4endl;
214   }                                               239   }
215   for (auto st : structure)                    << 240   for(size_t j=0; j<structure.size(); j++)
216     st->ListTree();                            << 241   { structure[j]->ListTree(); }
217 }                                                 242 }
                                                   >> 243         
                                                   >> 244 
218                                                   245