Geant4_10
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 
41 CCalSensitiveConfiguration * CCalSensitiveConfiguration::instance = 0;
42 
44  if (!instance)
45  instance = new CCalSensitiveConfiguration;
46  return instance;
47 }
48 
49 
51  int flag = -1;
52  CCalSensitiveConfIterator it = theConfiguration.find(n);
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;
67  CCalSensitiveConfIterator it = theConfiguration.find(n);
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 
80 CCalSensitiveConfiguration::CCalSensitiveConfiguration(): theConfiguration() {
81 
83  // Open the file
84  G4String pathName = getenv("CCAL_CONFPATH");
85  G4String fileenv = getenv("CCAL_SENSITIVECONF");
86  if (!pathName || !fileenv) {
87  G4cerr << "ERROR: CCAL_SENSITIVECONF and/or CCAL_CONFPATH not set" << G4endl
88  << " Set them to the sensitive configuration file/path" << G4endl;
89  exit(-2);
90  }
91 
92  G4cout << " ==> Opening file " << fileenv << "..." << G4endl;
93  std::ifstream is;
94  bool ok = openGeomFile(is, pathName, fileenv);
95  if (!ok)
96  exit(-1);
97 
98  G4String name;
99  GCInfo gcinfo;
100 
101  while (is) {
102  readName(is, name);
103  readName(is, gcinfo.FileName);
104  is >> gcinfo.SensitiveFlag >> jump;
105 #ifdef debug
106  G4cout << "CCalSensitiveConfiguration constructor: Read \"" << name
107  << "\" \"" << gcinfo.FileName << "\"" << tab << gcinfo.SensitiveFlag
108  << G4endl;
109 #endif
110  theConfiguration[name] = gcinfo;
111  }
112 
113 
115  // Close the file
116  is.close();
117  G4cout << " <== Closed file " << fileenv << G4endl;
118 }
bool openGeomFile(std::ifstream &is, const G4String &pathname, const G4String &filename)
Definition: CCalutils.cc:116
G4String getFileName(const G4String &n)
const XML_Char * name
Definition: expat.h:151
std::istream & jump(std::istream &)
Definition: CCalutils.cc:95
static CCalSensitiveConfiguration * getInstance()
Char_t n[5]
std::ifstream & readName(std::ifstream &, G4String &)
Definition: CCalutils.cc:53
G4GLOB_DLL std::ostream G4cout
std::ostream & tab(std::ostream &)
Definition: CCalutils.cc:89
int getSensitiveFlag(const G4String &n)
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr