Geant4  10.01.p02
CCalSensitiveConfiguration.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: CCalSensitiveConfiguration.cc
28 // Description: CCalSensitiveConfiguration handles the declaration of
29 // sensitive detectors and visibilities
32 
33 #include <fstream>
34 #include <stdlib.h>
35 
36 
37 //Comment/Uncomment next line to hide/show debug information
38 //#define debug
39 
40 
42 
44  if (!instance)
46  return instance;
47 }
48 
49 
51  int flag = -1;
53 
54  if (it != theConfiguration.end())
55  flag = (*it).second.SensitiveFlag;
56  else {
57  G4cerr << "ERROR: In CCalSensitiveConfiguration::getSensitiveFlag(const "
58  << "G4String& n)" << G4endl
59  << " " << n << " not found in configuration file" << G4endl;
60  }
61 
62  return flag;
63 }
64 
66  G4String fn;
68 
69  if (it != theConfiguration.end())
70  fn = (*it).second.FileName;
71  else {
72  G4cerr << "ERROR: In CCalSensitiveConfiguration::getFileName(const "
73  << "G4String& n)" << G4endl
74  << " " << n << " not found in configuration file" << G4endl;
75  }
76 
77  return fn;
78 }
79 
81 
83  // Open the file
84  G4String pathName = getenv("CCAL_CONFPATH");
85  G4String fileenv = getenv("CCAL_SENSITIVECONF");
86  if (!pathName || !fileenv) {
88  ed << "ERROR: CCAL_SENSITIVECONF and/or CCAL_CONFPATH not set" << G4endl
89  << " Set them to the sensitive configuration file/path" << G4endl;
90  G4Exception("CCalSensitiveConfiguration::CCalSensitiveConfiguration()",
91  "ccal005",
92  FatalException,ed);
93  }
94 
95  G4cout << " ==> Opening file " << fileenv << "..." << G4endl;
96  std::ifstream is;
97  bool ok = openGeomFile(is, pathName, fileenv);
98  if (!ok)
99  {
100  G4Exception("CCalSensitiveConfiguration::CCalSensitiveConfiguration()",
101  "ccal006",
103  "Unable to open sensitive input file");
104  }
105 
106 
107 
108  G4String name;
109  GCInfo gcinfo;
110 
111  while (is) {
112  readName(is, name);
113  readName(is, gcinfo.FileName);
114  is >> gcinfo.SensitiveFlag >> jump;
115 #ifdef debug
116  G4cout << "CCalSensitiveConfiguration constructor: Read \"" << name
117  << "\" \"" << gcinfo.FileName << "\"" << tab << gcinfo.SensitiveFlag
118  << G4endl;
119 #endif
120  theConfiguration[name] = gcinfo;
121  }
122 
123 
125  // Close the file
126  is.close();
127  G4cout << " <== Closed file " << fileenv << G4endl;
128 }
bool openGeomFile(std::ifstream &is, const G4String &pathname, const G4String &filename)
Definition: CCalutils.cc:116
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4String name
Definition: TRTMaterials.hh:40
G4String getFileName(const G4String &n)
std::istream & jump(std::istream &)
Definition: CCalutils.cc:95
CCalSensitiveConfTable theConfiguration
static CCalSensitiveConfiguration * getInstance()
std::ifstream & readName(std::ifstream &, G4String &)
Definition: CCalutils.cc:53
G4GLOB_DLL std::ostream G4cout
std::ostream & tab(std::ostream &)
Definition: CCalutils.cc:89
const G4int n
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
int getSensitiveFlag(const G4String &n)
static CCalSensitiveConfiguration * instance
#define G4endl
Definition: G4ios.hh:61
std::map< G4String, GCInfo, std::less< G4String > >::iterator CCalSensitiveConfIterator
G4GLOB_DLL std::ostream G4cerr