Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:19:40

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 ///////////////////////////////////////////////////////////////////////////////
0027 // File: CCalSensitiveConfiguration.cc
0028 // Description: CCalSensitiveConfiguration handles the declaration of
0029 //              sensitive detectors and visibilities
0030 ///////////////////////////////////////////////////////////////////////////////
0031 #include "CCalSensitiveConfiguration.hh"
0032 
0033 #include <fstream>
0034 #include <stdlib.h>
0035 
0036 
0037 //Comment/Uncomment next line to hide/show debug information
0038 //#define debug
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) /*const*/
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) /*const*/
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   // Open the file
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   // Close the file  
0129   is.close();
0130   G4cout << " <== Closed file " << fileenv << G4endl;
0131 }