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: CCalVisualisable.cc
0028 // Description: Sets visualisable attributes from .vis files
0029 ///////////////////////////////////////////////////////////////////////////////
0030 #include "CCalVisualisable.hh"
0031 
0032 #include <fstream>
0033 #include "CCalutils.hh"
0034 
0035 //Comment/Uncomment next line to unset/set debug information printing
0036 //#define debug
0037 
0038 const char* visEnvName = "CCAL_VISPATH";
0039 const char* CCalVisualisable::pathName=0;
0040 
0041 CCalVisualisable::CCalVisualisable(G4String file):visFile(file) {
0042   if (!pathName)
0043     setPath();
0044   setDefault();
0045   readFile();
0046 }
0047 
0048 G4bool CCalVisualisable::readFile(G4String file) { 
0049   visFile=file;
0050   return readFile();
0051 }
0052 
0053 void CCalVisualisable::setDefault(){
0054   theParameters[Sensitive] = visParameters(true);
0055   theParameters[Electronics] = visParameters(false);
0056   theParameters[Support] = visParameters(false);
0057   theParameters[Cable] = visParameters(false);
0058   theParameters[OtherServices] = visParameters(false);
0059   theParameters[PseudoVolumes] = visParameters(false);
0060 }
0061 
0062 void CCalVisualisable::setColor(visType v, G4double r, G4double g, G4double b){
0063   theParameters[v].rColor=r;
0064   theParameters[v].gColor=g;
0065   theParameters[v].bColor=b;
0066 }
0067 
0068 void CCalVisualisable::setPath() {
0069   pathName = std::getenv(visEnvName);
0070   if (!pathName) {
0071      G4ExceptionDescription ed;
0072      ed << "ERROR: " << visEnvName << " environmental variable not set!" 
0073         << G4endl;
0074      ed << "       Set it and restart." << G4endl;
0075      G4Exception("CCalVisualisable::setPath()","ccal007",
0076                  FatalException,ed);
0077   }
0078 }
0079 
0080 G4bool CCalVisualisable::readFile() {
0081   if (visFile=="") {
0082     G4cerr << "ERROR: No file was specified from which to read Visualisation parameters" 
0083          << G4endl;
0084     return false;
0085   }
0086 
0087   ///////////////////////////////////////////////////////////////
0088   //Let's open the file
0089   G4cout << " ==> Opening file " << visFile 
0090        << " to read visualisation parameters..."
0091        << G4endl;
0092 
0093   G4String pathname(pathName);
0094   std::ifstream is;
0095 #ifdef debug
0096   G4cout << "Viualisable : Path " << pathname << " FIle " << visFile << G4endl;
0097 #endif
0098   G4bool ok = openGeomFile(is, pathname, visFile);
0099   if (!ok) {
0100     G4cout << "WARNING: Could not read " << visFile << G4endl;
0101     G4cout << "         Default visualization parameters will be used." << G4endl;
0102     return false;
0103   }
0104   
0105   while (is) {
0106     G4String viewvol;
0107     readName(is,viewvol);
0108 
0109     visType vt = Undefined;
0110     if (viewvol=="Sensitive")
0111       vt=Sensitive;
0112     else if (viewvol=="Electronics")
0113       vt=Electronics;
0114     else if (viewvol=="Support")
0115       vt=Support;
0116     else if (viewvol=="Absorber")
0117       vt=Absorber;
0118     else if (viewvol=="Cable")
0119       vt=Cable;
0120     else if (viewvol=="OtherServices")
0121       vt=OtherServices;
0122     else if (viewvol=="PseudoVolumes")
0123       vt=PseudoVolumes;
0124     else {
0125       vt=Undefined;
0126       G4cerr << "WARNING: Unknown type of visualisable object \"" << viewvol
0127            << "\"." << G4endl;
0128     }
0129 
0130 
0131     G4int isvisible, wireframe;
0132     G4double r, g, b;
0133     
0134     is >> isvisible >> r >> g >> b >> wireframe >> jump;
0135 
0136     r=checkColorRange(r,'R');
0137     g=checkColorRange(g,'G');
0138     b=checkColorRange(b,'B');
0139 
0140     if (vt!=Undefined) {
0141 #ifdef debug
0142       G4cout << tab << viewvol << tab << isvisible << tab 
0143            << r << " " << g << " "<< b << tab
0144            << wireframe << G4endl;
0145 #endif
0146       theParameters[vt]=visParameters(isvisible, r, g, b, wireframe);
0147     }
0148 
0149   }
0150 
0151   ///////////////////////////////////////////////////////////////
0152   // Close the file
0153   G4cout << " ==> Closing file " << visFile << G4endl;
0154   is.close();
0155 
0156   return true;
0157 }
0158 
0159 G4double CCalVisualisable::checkColorRange(G4double cvalue, char ctype) const {
0160   if (cvalue>1) {
0161     G4cerr << "ERROR: In " << visFile << ". Color " << ctype << "=" 
0162          << cvalue << " > 1" << G4endl;
0163     G4cerr << "       It will be reset to 1." << G4endl;
0164     return 1.;
0165   }
0166   if (cvalue<0) {
0167     G4cerr << "ERROR: In " << visFile << ". Color " << ctype << "=" 
0168          << cvalue << " < 0" << G4endl;
0169     G4cerr << "       It will be reset to 0." << G4endl;
0170     return 0.;
0171   }
0172   return cvalue;
0173 }