Geant4  10.02.p01
CCalDetector.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
27 // File: CCalDetector.cc
28 // Description: CCalDetector is a detector factory class
30 
31 #include "CCalDetector.hh"
32 
33 #include <fstream>
35 #include "CCalutils.hh"
36 
37 //Comment/Uncomment to hide/show some debug information
38 //#define debug
39 //Comment/Uncomment to hide/show some more debug information
40 //#define ddebug
41 
42 
43 
44 CCalDetector::CCalDetector(const G4String &name): detectorName(name)
45 {
46  if (getenv("CCAL_GEOMPATH"))
47  pathName = getenv("CCAL_GEOMPATH");
48  else
49  G4Exception("CCalDetector::CCalDetector","ccal001",
51  "Environment variable CCAL_GEOMPATH not defined");
52 
53 #ifdef ddebug
54  G4cout << "CCAL_GEOMPATH=" << pathName << G4endl;
55 #endif
56  fileName =
58  constructFlag =
60 }
61 
63  CCalDetectorTable::iterator ite;
64  for (ite=theDetectorsInside.begin(); ite !=theDetectorsInside.end(); ite++) {
65  delete *ite;
66  }
67  theDetectorsInside.clear();
68 }
69 
71 #ifdef debug
72  G4cout << "===> Entering CCalDetector::construct() for " << Name() << G4endl;
73 #endif
74  int isgood = 0;
75 
76  //If constructFlag is unset we don't go into all this bussines
77  if (constructFlag!=0) {
78 
79  if (!isgood)
80  isgood = buildFromFile();
81 
82  if (isgood) {
84  for (unsigned int i=0; i < theDetectorsInside.size(); i++) {
85  theDetectorsInside[i]->constructHierarchy();
86  }
87  }
88  }
89 #ifdef debug
90  G4cout << "===> Exiting CCalDetector::construct() for " << Name() << G4endl;
91 #endif
92 }
93 
94 
96  theDetectorsInside.push_back(det);
97 }
98 
99 
100 
101 //========================================================================
102 //Protected and private methods.
104  return readFile();
105 }
106 
107 
108 
109 //========================================================================
110 //Global operators
111 std::ostream& operator<<(std::ostream& os, const CCalDetector& det) {
112  os << "Detector \"" << det.detectorName
113  << "\" read from " << det.fileName << "." << G4endl;
114 
115  os << "With " << det.theDetectorsInside.size()
116  << " detectors inside { "<< G4endl;
117 
118  for (unsigned int i=0; i<det.theDetectorsInside.size(); i++)
119  os << det.theDetectorsInside[i] << G4endl;
120 
121  os << "}" << G4endl;
122 
123  return os;
124 }
125 
126 
127 
128 
129 
130 
131 
virtual void constructDaughters()=0
void addDetector(CCalDetector *)
Definition: CCalDetector.cc:95
CCalDetector(const G4String &name)
Definition: CCalDetector.cc:44
G4String name
Definition: TRTMaterials.hh:40
G4String Name() const
Definition: CCalDetector.hh:77
virtual ~CCalDetector()
Definition: CCalDetector.cc:62
void construct()
Definition: CCalDetector.cc:70
G4String getFileName(const G4String &n)
G4GLOB_DLL std::ostream G4cout
int buildFromFile()
G4String pathName
G4String fileName
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static CCalGeometryConfiguration * getInstance()
G4String detectorName
virtual int readFile()=0
CCalDetectorTable theDetectorsInside
#define G4endl
Definition: G4ios.hh:61
int getConstructFlag(const G4String &n)
std::ostream & operator<<(std::ostream &os, const CCalDetector &det)