File indexing completed on 2025-02-23 09:19:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #include "CCalDetector.hh"
0032
0033 #include <fstream>
0034 #include "CCalGeometryConfiguration.hh"
0035 #include "CCalutils.hh"
0036
0037
0038
0039
0040
0041
0042 CCalDetector::CCalDetector(const G4String &name): detectorName(name)
0043 {
0044 if (std::getenv("CCAL_GEOMPATH"))
0045 pathName = std::getenv("CCAL_GEOMPATH");
0046 else
0047 G4Exception("CCalDetector::CCalDetector","ccal001",
0048 FatalException,
0049 "Environment variable CCAL_GEOMPATH not defined");
0050
0051 #ifdef debug
0052 G4cout << "CCAL_GEOMPATH=" << pathName << G4endl;
0053 #endif
0054 fileName =
0055 CCalGeometryConfiguration::getInstance()->getFileName(name);
0056 constructFlag =
0057 CCalGeometryConfiguration::getInstance()->getConstructFlag(name);
0058 }
0059
0060 CCalDetector::~CCalDetector() {
0061 for (auto ite=theDetectorsInside.begin(); ite !=theDetectorsInside.end(); ++ite) {
0062 delete *ite;
0063 }
0064 theDetectorsInside.clear();
0065 }
0066
0067 void CCalDetector::construct() {
0068 #ifdef debug
0069 G4cout << "===> Entering CCalDetector::construct() for " << Name() << G4endl;
0070 #endif
0071 G4int isgood = 0;
0072
0073
0074 if (constructFlag!=0) {
0075
0076 if (!isgood)
0077 isgood = buildFromFile();
0078
0079 if (isgood) {
0080 constructDaughters();
0081 for (std::size_t i=0; i < theDetectorsInside.size(); ++i) {
0082 theDetectorsInside[i]->constructHierarchy();
0083 }
0084 }
0085 }
0086 #ifdef debug
0087 G4cout << "===> Exiting CCalDetector::construct() for " << Name() << G4endl;
0088 #endif
0089 }
0090
0091 void CCalDetector::addDetector(CCalDetector* det) {
0092 theDetectorsInside.push_back(det);
0093 }
0094
0095
0096
0097 G4int CCalDetector::buildFromFile() {
0098 return readFile();
0099 }
0100
0101
0102
0103 std::ostream& operator<<(std::ostream& os, const CCalDetector& det) {
0104 os << "Detector \"" << det.detectorName
0105 << "\" read from " << det.fileName << "." << G4endl;
0106
0107 os << "With " << det.theDetectorsInside.size()
0108 << " detectors inside { "<< G4endl;
0109
0110 for (std::size_t i=0; i<det.theDetectorsInside.size(); ++i)
0111 os << det.theDetectorsInside[i] << G4endl;
0112
0113 os << "}" << G4endl;
0114
0115 return os;
0116 }