Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 27 // Author: Ivana Hrivnacova, 04/07/2012 (ivana@ipno.in2p3.fr) 28 29 #ifndef G4AnalysisUtilities_h 30 #define G4AnalysisUtilities_h 1 31 32 #include "G4Exception.hh" 33 #include "globals.hh" 34 35 #include <vector> 36 #include <memory> 37 #include <string_view> 38 39 // Enumeration for definition of available output types 40 41 enum class G4AnalysisOutput { 42 kCsv, 43 kHdf5, 44 kRoot, 45 kXml, 46 kNone 47 }; 48 49 namespace G4Analysis 50 { 51 52 // Constant expressions 53 // 54 constexpr G4int kX { 0 }; 55 constexpr G4int kY { 1 }; 56 constexpr G4int kZ { 2 }; 57 constexpr G4int kInvalidId { -1 }; 58 constexpr G4int kVL0 { 0 }; 59 constexpr G4int kVL1 { 1 }; 60 constexpr G4int kVL2 { 2 }; 61 constexpr G4int kVL3 { 3 }; 62 constexpr G4int kVL4 { 4 }; 63 constexpr unsigned int kDim1 { 1 }; 64 constexpr unsigned int kDim2 { 2 }; 65 constexpr unsigned int kDim3 { 3 }; 66 constexpr unsigned int kMaxDim { kDim3 }; 67 constexpr unsigned int kDefaultBasketSize { 32000 }; 68 constexpr unsigned int kDefaultBasketEntries {4000 }; 69 constexpr std::string_view kNamespaceName { "G4Analysis" }; 70 71 // Warning 72 // 73 void Warn(const G4String& message, 74 const std::string_view inClass, 75 const std::string_view inFunction); 76 77 // Get unit value with added handling of "none" 78 G4double GetUnitValue(const G4String& unit); 79 80 // Tokenizer with taking into account composed strings within "" 81 void Tokenize(const G4String& line, std::vector<G4String>& tokens); 82 83 // Get output type from name 84 G4AnalysisOutput GetOutput(const G4String& outputName, G4bool warn = true); 85 size_t GetOutputId(const G4String& outputName, G4bool warn = true); 86 G4String GetOutputName(G4AnalysisOutput outputType); 87 88 // Get short hnType from the tools object 89 template <typename HT> 90 G4String GetHnType() 91 { 92 // tools::histo::h1d etc. 93 G4String hnTypeLong = HT::s_class(); 94 95 // tools::histo::h1d -> h1 etc. 96 return hnTypeLong.substr(14, 2); 97 } 98 99 template <typename HT> 100 G4bool IsProfile() 101 { 102 // tools::histo::h1d etc. 103 G4String hnTypeLong = HT::s_class(); 104 105 // tools::histo::h1d -> h1 etc. 106 return hnTypeLong[14] == 'p'; 107 } 108 109 // String conversion 110 template <typename T> 111 inline 112 std::string ToString(const T& value) 113 { return std::to_string(value); } 114 115 template <> 116 inline 117 std::string ToString<std::string>(const std::string& value) 118 { return value; } 119 120 // File names utilities 121 122 // Get file base name (without dot) 123 G4String GetBaseName(const G4String& fileName); 124 125 // Get file base extension (without dot) 126 G4String GetExtension(const G4String& fileName, 127 const G4String& defaultExtension = ""); 128 129 // Compose and return the histogram or profile specific file name: 130 // - add _hn_hnName suffix to the file base name 131 // - add file extension if not present 132 G4String GetHnFileName( 133 const G4String& fileName, 134 const G4String& fileType, 135 const G4String& hnType, 136 const G4String& hnName); 137 138 // Update Hn file name: 139 // - add _vN suffix to the base namer if cycle > 0 140 G4String GetHnFileName( 141 const G4String& fileName, 142 const G4String& fileType, 143 G4int cycle = 0); 144 145 // Compose and return the ntuple specific file name: 146 // - add _nt_ntupleName suffix to the file base name 147 // - add _vN suffix if cycle > 0 148 // - add _tN suffix if called on thread worker 149 // - add file extension if not present 150 G4String GetNtupleFileName( 151 const G4String& fileName, 152 const G4String& fileType, 153 const G4String& ntupleName, 154 G4int cycle = 0); 155 156 // Compose and return the ntuple specific file name: 157 // - add _mFN suffix to the file base name where FN = ntupleFileNumber 158 // - add _vN suffix if cycle > 0 159 // - add file extension if not present 160 G4String GetNtupleFileName( 161 const G4String& fileName, 162 const G4String& fileType, 163 G4int ntupleFileNumber, 164 G4int cycle = 0); 165 166 // Update file base name with the thread suffix: 167 // - add _vN suffix if cycle > 0 168 // - add _tN suffix if called on thread worker 169 // - add file extension if not present 170 G4String GetTnFileName( 171 const G4String& fileName, 172 const G4String& fileType, 173 G4int cycle = 0); 174 175 // Generate plot file name for an output file name 176 G4String GetPlotFileName(const G4String& fileName); 177 178 } 179 180 /* 181 // make possible to print enumerators in class enum as integer 182 template <typename Enumeration> 183 auto as_integer(Enumeration const value) 184 -> typename std::underlying_type<Enumeration>::type 185 { 186 return static_cast<typename std::underlying_type<Enumeration>::type>(value); 187 } 188 */ 189 190 #endif 191 192