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 // G4PersistencyCenter 27 // 28 // Class Description: 29 // 30 // Class to handle loading of the G4PersistencyManager. 31 32 // Author: Youhei Morita, 10.08.2001 33 // -------------------------------------------------------------------- 34 #ifndef G4PERSISTENCYCENTER_HH 35 #define G4PERSISTENCYCENTER_HH 1 36 37 #include <vector> 38 #include <map> 39 40 #include "G4Types.hh" 41 #include "G4HCIOcatalog.hh" 42 #include "G4DCIOcatalog.hh" 43 44 #ifndef WIN32 45 # include "G4FileUtilities.hh" 46 #endif 47 48 // Forward Declarations 49 class G4PersistencyManager; 50 class G4PersistencyCenterMessenger; 51 52 using PMap = std::map<G4String, G4PersistencyManager*, std::less<G4String>>; 53 using ObjMap = std::map<G4int, G4String, std::less<G4int>>; 54 using FileMap = std::map<G4String, G4String, std::less<G4String>>; 55 56 enum StoreMode 57 { 58 kOn, 59 kOff, 60 kRecycle 61 }; 62 63 using StoreMap = std::map<G4String, StoreMode, std::less<G4String>>; 64 using BoolMap = std::map<G4String, G4bool, std::less<G4String>>; 65 66 class G4PersistencyCenter 67 { 68 public: 69 70 static G4PersistencyCenter* GetPersistencyCenter(); 71 // Returns the pointer of singleton G4PersistencyCenter 72 73 void SelectSystem(const G4String& systemName); 74 // Select the persistency package 75 76 const G4String& CurrentSystem() { return f_currentSystemName; } 77 // Returns the current persistent package name 78 79 void SetHepMCObjyReaderFile(const G4String& file); 80 // Sets the name of HepMCObjyReader file name. To be called by generator 81 82 G4String CurrentHepMCObjyReaderFile(); 83 // Sets the name of HepMCObjyReader file name. To be called by generator 84 85 void SetStoreMode(const G4String& objName, StoreMode mode); 86 // Sets the object store mode. Modes are kOn, kOff or kRecycle 87 88 void SetRetrieveMode(const G4String& objName, G4bool mode); 89 // Sets the object retrieve mode. Modes are true or false 90 91 StoreMode CurrentStoreMode(const G4String& objName); 92 // Returns the current object store mode 93 94 G4bool CurrentRetrieveMode(const G4String& objName); 95 // Returns the current object store mode 96 97 G4bool SetWriteFile(const G4String& objName, const G4String& writeFileName); 98 // Sets the output filename 99 100 G4bool SetReadFile(const G4String& objName, const G4String& readFileName); 101 // Sets the input filename 102 103 G4String CurrentWriteFile(const G4String& objName); 104 // Returns the current output filename 105 106 G4String CurrentReadFile(const G4String& objName); 107 // Returns the current input filename 108 109 G4String CurrentObject(const G4String& file); 110 // Returns the current object type 111 112 void AddHCIOmanager(const G4String& detName, const G4String& colName); 113 // Adds a hits colleciton I/O manager to the catalog 114 115 G4String CurrentHCIOmanager(); 116 // Returns a list of registered hits colleciton I/O managers 117 118 void AddDCIOmanager(const G4String& detName); 119 // Adds a digits colleciton I/O manager to the catalog 120 121 G4String CurrentDCIOmanager(); 122 // Returns a list of registered digits collection I/O managers 123 124 void PrintAll(); 125 // Prints the current G4PersistencyCenter settings 126 127 G4PersistencyManager* CurrentPersistencyManager() 128 { 129 return f_currentManager; 130 } 131 // Returns the pointer of the current G4PersistencyManager 132 133 void SetPersistencyManager(G4PersistencyManager* pm, const G4String& name); 134 // Returns the pointer of the current G4PersistencyManager 135 136 G4PersistencyManager* GetPersistencyManager(const G4String& nam); 137 // Returns the pointer of the current G4PersistencyManager with name 138 139 void RegisterPersistencyManager(G4PersistencyManager* pm); 140 // Registers the persistency manager to the runtime catalog 141 142 void DeletePersistencyManager(); 143 // Deletes the current G4PersistencyManager 144 145 void SetVerboseLevel(G4int v); 146 // Sets verbose level 147 148 G4int VerboseLevel() { return m_verbose; } 149 // Returns verbose level 150 151 private: 152 153 G4PersistencyCenter(); 154 // Constructor 155 156 ~G4PersistencyCenter(); 157 // Destructor 158 159 G4String PadString(const G4String& name, unsigned int width); 160 // Truncates or pad a string up to the width 161 162 private: 163 164 G4PersistencyCenterMessenger* f_theMessenger = nullptr; 165 static G4ThreadLocal G4PersistencyCenter* f_thePointer; 166 G4PersistencyManager* f_currentManager = nullptr; 167 G4String f_currentSystemName; 168 PMap f_theCatalog; 169 ObjMap f_wrObj; 170 ObjMap f_rdObj; 171 FileMap f_writeFileName; 172 FileMap f_readFileName; 173 StoreMap f_writeFileMode; 174 BoolMap f_readFileMode; 175 G4int m_verbose = 0; 176 #ifndef WIN32 177 G4FileUtilities f_ut; 178 #endif 179 }; 180 181 #endif 182