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