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: CCalutils.cc
0028 // Description: General utilities.
0029 ///////////////////////////////////////////////////////////////////////////////
0030 #include "CCalutils.hh"
0031 #include "G4ios.hh"
0032 #include "G4UnitsTable.hh"
0033 
0034 #include <sstream>
0035 
0036 
0037 G4String operator+(const G4String& str, const G4int i) {
0038   std::ostringstream os;
0039   os << str << i <<'\0';
0040   G4String back = os.str();  
0041   return back;
0042 }
0043 
0044 
0045 G4String operator+(const G4String& str, const G4double i) {
0046   std::ostringstream os;
0047   os << str << i <<'\0';
0048   G4String back = os.str();  
0049   return back;
0050 }
0051 
0052 
0053 std::ifstream& readName(std::ifstream& is, G4String& name){
0054   is >> name;
0055   if ( name != "*ENDDO" ) {
0056     while ( name.find("#.") != G4String::npos ) { // It is a comment. Skip line.
0057       is.ignore(999,'\n');
0058       is >> name;
0059     };
0060     while ( name.rfind('\"') != name.length()-1 ) {
0061       G4String other;
0062       is >> other;
0063       name += " ";
0064       name += other;
0065     };
0066     G4StrUtil::strip(name, '\"');
0067   }  
0068   return is;
0069 }
0070 
0071 
0072 std::ifstream& findDO(std::ifstream& is, const G4String& str){
0073   // Loop until *DO str is found
0074   G4String firstwd, dowhat;
0075   dowhat = "";
0076   while (dowhat != str && is) {
0077     is >> firstwd;
0078     while (firstwd != "*DO" && is) {
0079       is.ignore(999,'\n');
0080       is >> firstwd;
0081     };
0082     is >> dowhat;
0083   };
0084   is.ignore(999,'\n');
0085   return is;
0086 }
0087 
0088 
0089 std::ostream& tab(std::ostream& os) {
0090   os << '\t';
0091   return os;
0092 }
0093 
0094 
0095 std::istream& jump(std::istream& is) {
0096   char first = ' ';
0097   char second = ' ';
0098   is.ignore(999,'\n');
0099   do {
0100     is.get(first);
0101     second = is.peek();
0102     if (first == '#' && second =='.') {
0103       is.ignore(999,'\n');
0104     }
0105     else if (first == '\n'); //it was already picked
0106     else {
0107       is.putback(first);
0108       return is;
0109     }
0110   }
0111   while (is);
0112   return is;
0113 }
0114 
0115 
0116 G4bool openGeomFile(std::ifstream& is, 
0117                     const G4String& pathname, const G4String& filename) {
0118   G4String fullname = pathname+"/"+filename;
0119   is.open( fullname.c_str() );
0120   if (!is) {
0121     G4cerr << "ERROR: Could not open file " << filename << G4endl;
0122     return false;
0123   }
0124   return true;
0125 }