Back to home page

EIC code displayed by LXR

 
 

    


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

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: CCalGeometryConfiguration.cc
0028 // Description: Handles geometry configuration to be constructed
0029 ///////////////////////////////////////////////////////////////////////////////
0030 
0031 #include "CCalGeometryConfiguration.hh"
0032 
0033 #include <fstream>
0034 
0035 //Comment/Uncomment next line to hide/show debug information
0036 //#define debug
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) /*const*/ {
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) /*const*/ {
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   // Open the file
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   // Close the file  
0124   is.close();
0125   G4cout << " <== Closed file " << fileenv << G4endl;
0126 }