Back to home page

EIC code displayed by LXR

 
 

    


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

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: CCalDetector.cc
0028 // Description: CCalDetector is a detector factory class
0029 ///////////////////////////////////////////////////////////////////////////////
0030 
0031 #include "CCalDetector.hh"
0032 
0033 #include <fstream>
0034 #include "CCalGeometryConfiguration.hh"
0035 #include "CCalutils.hh"
0036 
0037 //Comment/Uncomment to hide/show some debug information
0038 //#define debug
0039 //Comment/Uncomment to hide/show some more debug information
0040 //#define ddebug
0041 
0042 CCalDetector::CCalDetector(const G4String &name): detectorName(name) 
0043 {
0044   if (std::getenv("CCAL_GEOMPATH"))    
0045       pathName = std::getenv("CCAL_GEOMPATH");
0046   else
0047     G4Exception("CCalDetector::CCalDetector","ccal001",
0048                 FatalException,
0049                 "Environment variable CCAL_GEOMPATH not defined");
0050       
0051 #ifdef debug
0052     G4cout << "CCAL_GEOMPATH=" << pathName << G4endl;
0053 #endif
0054     fileName      = 
0055       CCalGeometryConfiguration::getInstance()->getFileName(name);
0056     constructFlag = 
0057       CCalGeometryConfiguration::getInstance()->getConstructFlag(name);
0058 }
0059 
0060 CCalDetector::~CCalDetector() {
0061   for (auto ite=theDetectorsInside.begin(); ite !=theDetectorsInside.end(); ++ite) {
0062     delete *ite;
0063   }
0064   theDetectorsInside.clear();
0065 }
0066 
0067 void CCalDetector::construct() {
0068 #ifdef debug
0069   G4cout << "===> Entering CCalDetector::construct() for " << Name() << G4endl;
0070 #endif
0071   G4int isgood = 0;
0072 
0073   //If constructFlag is unset we don't go into all this bussines
0074   if (constructFlag!=0) {
0075     
0076     if (!isgood)
0077       isgood = buildFromFile();
0078     
0079     if (isgood) {
0080       constructDaughters();
0081       for (std::size_t i=0; i < theDetectorsInside.size(); ++i) {
0082         theDetectorsInside[i]->constructHierarchy();
0083       }
0084     }
0085   }
0086 #ifdef debug
0087   G4cout << "===> Exiting CCalDetector::construct() for " << Name() << G4endl;
0088 #endif
0089 }
0090 
0091 void CCalDetector::addDetector(CCalDetector* det) {
0092   theDetectorsInside.push_back(det);
0093 }
0094 
0095 //========================================================================
0096 //Protected and private methods.
0097 G4int CCalDetector::buildFromFile() {
0098   return readFile();
0099 }
0100 
0101 //========================================================================
0102 //Global operators
0103 std::ostream& operator<<(std::ostream& os, const CCalDetector& det) {
0104   os << "Detector \"" << det.detectorName 
0105      << "\" read from " << det.fileName << "." << G4endl;
0106 
0107   os << "With " << det.theDetectorsInside.size() 
0108      << " detectors inside { "<< G4endl;
0109 
0110   for (std::size_t i=0; i<det.theDetectorsInside.size(); ++i)
0111     os << det.theDetectorsInside[i] << G4endl;
0112 
0113   os << "}" << G4endl;
0114 
0115   return os;
0116 }