File indexing completed on 2025-02-23 09:19:39
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 "CCalGeometryConfiguration.hh"
0032
0033 #include <fstream>
0034
0035
0036
0037
0038
0039 CCalGeometryConfiguration * CCalGeometryConfiguration::instance = 0;
0040
0041 CCalGeometryConfiguration* CCalGeometryConfiguration::getInstance(){
0042 if (!instance)
0043 instance = new CCalGeometryConfiguration;
0044 return instance;
0045 }
0046
0047
0048 G4int CCalGeometryConfiguration::getConstructFlag(const G4String& n) {
0049 G4int flag = -1;
0050 auto it = theConfiguration.find(n);
0051
0052 if (it != theConfiguration.cend())
0053 flag = (*it).second.ConstructFlag;
0054 else {
0055 G4cerr << "ERROR: In CCalGeometryConfiguration::getConstructFlag(const G4String& n)"
0056 << G4endl
0057 << " " << n << " not found in configuration file" << G4endl;
0058 }
0059
0060 return flag;
0061 }
0062
0063 G4String CCalGeometryConfiguration::getFileName(const G4String& n) {
0064 G4String fn;
0065 auto it = theConfiguration.find(n);
0066
0067 if (it != theConfiguration.cend())
0068 fn = (*it).second.FileName;
0069 else {
0070 G4cerr << "ERROR: In CCalGeometryConfiguration::getFileName(const G4String& n)"
0071 << G4endl
0072 << " " << n << " not found in configuration file" << G4endl;
0073 }
0074
0075 return fn;
0076 }
0077
0078 CCalGeometryConfiguration::CCalGeometryConfiguration():
0079 theConfiguration() {
0080
0081
0082
0083 G4String pathName = std::getenv("CCAL_CONFPATH");
0084 G4String fileenv = std::getenv("CCAL_GEOMETRYCONF");
0085 if (!pathName || !fileenv) {
0086 G4ExceptionDescription ed;
0087 ed << "ERROR: CCAL_GEOMETRYCONF and/or CCAL_CONFPATH not set" << G4endl
0088 << " Set them to the geometry configuration file/path" << G4endl;
0089 G4Exception("CCalGeometryConfiguration::CCalGeometryConfiguration()",
0090 "ccal003",
0091 FatalException,ed);
0092 }
0093
0094 G4cout << " ==> Opening file " << fileenv << "..." << G4endl;
0095 std::ifstream is;
0096 G4bool ok = openGeomFile(is, pathName, fileenv);
0097 if (!ok)
0098 {
0099 G4Exception("CCalGeometryConfiguration::CCalGeometryConfiguration()",
0100 "ccal004",
0101 FatalException,"Unable to open input data file");
0102 }
0103
0104
0105 G4String name;
0106 GCInfo gcinfo;
0107
0108 while (is) {
0109 readName(is, name);
0110 readName(is, gcinfo.FileName);
0111 is >> gcinfo.ConstructFlag >> jump;
0112 #ifdef debug
0113 G4cout << "CCalGeometryConfiguration constructor: Read \"" << name
0114 << " \"" << gcinfo.FileName << "\"" << tab << gcinfo.ConstructFlag
0115 << G4endl;
0116 #endif
0117 theConfiguration[name] = gcinfo;
0118 }
0119
0120
0121
0122
0123
0124 is.close();
0125 G4cout << " <== Closed file " << fileenv << G4endl;
0126 }