Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4PersistencyManager implementation << 26 // File: G4PersistencyManager.cc 27 // 27 // 28 // Author: Youhei Morita, 17.07.2001 << 28 // History: 29 // ------------------------------------------- << 29 // 01.07.17 Youhei Morita Initial creation (with "fadsclass") 30 30 31 #include "G4PersistencyManager.hh" 31 #include "G4PersistencyManager.hh" 32 32 >> 33 // Addtional Include: 33 #include <iomanip> 34 #include <iomanip> 34 #include "G4PersistencyCenter.hh" 35 #include "G4PersistencyCenter.hh" 35 36 36 // ------------------------------------------- << 37 // Implementation of Constructor #1 37 G4PersistencyManager::G4PersistencyManager(G4P << 38 G4PersistencyManager::G4PersistencyManager(G4PersistencyCenter* pc, std::string n) 38 con << 39 : f_pc(pc), nameMgr(n), f_is_initialized(false) 39 : f_pc(ptc) << 40 , nameMgr(n) << 41 { 40 { 42 m_verbose = f_pc->VerboseLevel(); 41 m_verbose = f_pc->VerboseLevel(); 43 } 42 } 44 43 45 // ------------------------------------------- << 44 // Implementation of Destructor #1 46 G4PersistencyManager::~G4PersistencyManager() 45 G4PersistencyManager::~G4PersistencyManager() 47 { << 46 {} 48 } << 49 47 50 // ------------------------------------------- << 48 // Implementation of GetPersistencyManager 51 G4PersistencyManager* G4PersistencyManager::Ge 49 G4PersistencyManager* G4PersistencyManager::GetPersistencyManager() 52 { 50 { 53 return G4PersistencyCenter::GetPersistencyCe << 51 return G4PersistencyCenter::GetPersistencyCenter()->CurrentPersistencyManager(); 54 ->CurrentPersistencyManager(); << 55 } 52 } 56 53 57 // ------------------------------------------- << 54 // Implementation of SetVerboseLevel 58 void G4PersistencyManager::SetVerboseLevel(G4i << 55 void G4PersistencyManager::SetVerboseLevel(int v) 59 { 56 { 60 m_verbose = v; 57 m_verbose = v; 61 if(m_verbose > 2) << 58 if ( m_verbose > 2 ) { 62 { << 63 G4cout << "G4PersistencyManager[\"" << nam 59 G4cout << "G4PersistencyManager[\"" << nameMgr << "\"," << this 64 << "]: verbose level is set to " << << 60 << "]: verbose level is set to " << m_verbose << "." >> 61 << G4endl; 65 } 62 } 66 if(EventIO() != nullptr) << 63 if ( EventIO() != 0 ) EventIO()->SetVerboseLevel(m_verbose); 67 EventIO()->SetVerboseLevel(m_verbose); << 64 if ( MCTruthIO() != 0 ) MCTruthIO()->SetVerboseLevel(m_verbose); 68 if(MCTruthIO() != nullptr) << 65 if ( HitIO() != 0 ) HitIO()->SetVerboseLevel(m_verbose); 69 MCTruthIO()->SetVerboseLevel(m_verbose); << 66 if ( DigitIO() != 0 ) DigitIO()->SetVerboseLevel(m_verbose); 70 if(HitIO() != nullptr) << 67 if (TransactionManager() != 0) TransactionManager()->SetVerboseLevel(m_verbose); 71 HitIO()->SetVerboseLevel(m_verbose); << 72 if(DigitIO() != nullptr) << 73 DigitIO()->SetVerboseLevel(m_verbose); << 74 if(TransactionManager() != nullptr) << 75 TransactionManager()->SetVerboseLevel(m_ve << 76 68 77 G4int i; << 69 size_t i; 78 70 79 G4HCIOcatalog* hcio = G4HCIOcatalog::GetHCIO 71 G4HCIOcatalog* hcio = G4HCIOcatalog::GetHCIOcatalog(); 80 if(hcio != nullptr) << 72 if ( hcio != 0 ) { 81 { << 82 hcio->SetVerboseLevel(m_verbose); 73 hcio->SetVerboseLevel(m_verbose); 83 for(i = 0; i < (G4int)hcio->NumberOfHCIOma << 74 for ( i = 0; i < hcio->NumberOfHCIOmanager(); i++ ) { 84 { << 85 hcio->GetHCIOmanager(i)->SetVerboseLevel 75 hcio->GetHCIOmanager(i)->SetVerboseLevel(m_verbose); 86 } 76 } 87 } 77 } 88 G4DCIOcatalog* dcio = G4DCIOcatalog::GetDCIO 78 G4DCIOcatalog* dcio = G4DCIOcatalog::GetDCIOcatalog(); 89 if(dcio != nullptr) << 79 if ( dcio != 0 ) { 90 { << 91 dcio->SetVerboseLevel(m_verbose); 80 dcio->SetVerboseLevel(m_verbose); 92 for(i = 0; i < (G4int)dcio->NumberOfDCIOma << 81 for ( i = 0; i < dcio->NumberOfDCIOmanager(); i++ ) { 93 { << 94 dcio->GetDCIOmanager(i)->SetVerboseLevel 82 dcio->GetDCIOmanager(i)->SetVerboseLevel(m_verbose); 95 } 83 } 96 } 84 } 97 } 85 } 98 86 99 // ------------------------------------------- << 87 // Implementation of Store 100 G4bool G4PersistencyManager::Store(const G4Eve 88 G4bool G4PersistencyManager::Store(const G4Event* evt) 101 { 89 { 102 if(m_verbose > 2) << 90 if ( m_verbose > 2 ) { 103 { << 104 G4cout << "G4PersistencyManager::Store() i 91 G4cout << "G4PersistencyManager::Store() is called for event# " 105 << evt->GetEventID() << "." << G4en 92 << evt->GetEventID() << "." << G4endl; 106 } 93 } 107 94 108 if(TransactionManager() == nullptr) << 95 if ( TransactionManager() == 0 ) return true; 109 return true; << 110 96 111 G4bool is_store = f_pc->CurrentStoreMode("MC 97 G4bool is_store = f_pc->CurrentStoreMode("MCTruth") != kOff || 112 f_pc->CurrentStoreMode("Hi << 98 f_pc->CurrentStoreMode("Hits") != kOff || 113 f_pc->CurrentStoreMode("Di << 99 f_pc->CurrentStoreMode("Digits") != kOff; 114 100 115 if(!is_store) << 101 if ( ! is_store ) return true; 116 return true; << 117 102 118 // Call package dependent Initialize() 103 // Call package dependent Initialize() 119 // 104 // 120 if(!f_is_initialized) << 105 if ( ! f_is_initialized ) { 121 { << 122 f_is_initialized = true; 106 f_is_initialized = true; 123 if(m_verbose > 1) << 107 if ( m_verbose > 1 ) { 124 { << 125 G4cout << "G4PersistencyManager:: Initia 108 G4cout << "G4PersistencyManager:: Initializing Transaction ... " 126 << G4endl; 109 << G4endl; 127 } 110 } 128 Initialize(); 111 Initialize(); 129 } 112 } 130 113 131 G4bool st1 = true, st2 = true; 114 G4bool st1 = true, st2 = true; 132 115 133 // Start event IO transaction 116 // Start event IO transaction 134 // 117 // 135 if(TransactionManager()->StartUpdate()) << 118 if ( TransactionManager()->StartUpdate() ) { 136 { << 119 if ( m_verbose > 2 ) { 137 if(m_verbose > 2) << 138 { << 139 G4cout << "G4PersistencyManager: Update 120 G4cout << "G4PersistencyManager: Update transaction started for event#" 140 << evt->GetEventID() << "." << G4 121 << evt->GetEventID() << "." << G4endl; 141 } 122 } 142 } << 123 } else { 143 else << 144 { << 145 G4cerr << "TransactionManager::Store(G4Eve 124 G4cerr << "TransactionManager::Store(G4Event) - StartUpdate() failed." 146 << G4endl; 125 << G4endl; 147 return false; 126 return false; 148 } 127 } 149 128 150 G4String file; << 129 std::string file; 151 G4String obj; << 130 std::string obj; 152 131 153 G4bool stmct = true, st3 = true; 132 G4bool stmct = true, st3 = true; 154 133 155 // Store MCTruth event 134 // Store MCTruth event 156 // 135 // 157 obj = "MCTruth"; << 136 obj = "MCTruth"; 158 G4MCTEvent* mctevt = nullptr; << 137 G4MCTEvent* mctevt = 0; 159 if(f_pc->CurrentStoreMode(obj) == kOn) << 138 if ( f_pc->CurrentStoreMode(obj) == kOn ) { 160 { << 139 161 // Note: This part of code will not be ac 140 // Note: This part of code will not be activated until a method 162 // to obtain the current pointer of G4MCT 141 // to obtain the current pointer of G4MCTEvent* become available. 163 142 164 // if ( (mctevt = f_MCTman->GetCurrentEven 143 // if ( (mctevt = f_MCTman->GetCurrentEvent()) != 0 ) { 165 if(mctevt != nullptr) << 144 if ( mctevt != 0 ) { 166 { << 167 file = f_pc->CurrentWriteFile(obj); 145 file = f_pc->CurrentWriteFile(obj); 168 if(TransactionManager()->SelectWriteFile << 146 if ( TransactionManager()->SelectWriteFile(obj, file) ) { 169 { << 170 stmct = MCTruthIO()->Store(mctevt); 147 stmct = MCTruthIO()->Store(mctevt); 171 if(stmct && m_verbose > 1) << 148 if ( stmct && m_verbose > 1 ) { 172 { << 149 G4cout << " -- File : " << file << " -- Event# " 173 G4cout << " -- File : " << file << " << 150 << evt->GetEventID() << " -- G4MCTEvent Stored." << G4endl; 174 << " -- G4MCTEvent Stored." < << 175 } 151 } 176 } << 152 } else { 177 else << 178 { << 179 stmct = false; 153 stmct = false; 180 } 154 } 181 } // end of if ( mctevt != nullptr ) << 155 } // end of if ( mctevt != 0 ) 182 } 156 } 183 157 184 // Store hits collection 158 // Store hits collection 185 // 159 // 186 obj = "Hits"; 160 obj = "Hits"; 187 if(f_pc->CurrentStoreMode(obj) == kOn) << 161 if ( f_pc->CurrentStoreMode(obj) == kOn ) { 188 { << 162 if ( G4HCofThisEvent* hc = evt->GetHCofThisEvent() ) { 189 if(G4HCofThisEvent* hc = evt->GetHCofThisE << 190 { << 191 file = f_pc->CurrentWriteFile(obj); 163 file = f_pc->CurrentWriteFile(obj); 192 if(TransactionManager()->SelectWriteFile << 164 if ( TransactionManager()->SelectWriteFile(obj, file) ) { 193 { << 194 st1 = HitIO()->Store(hc); 165 st1 = HitIO()->Store(hc); 195 if(st1 && m_verbose > 1) << 166 if ( st1 && m_verbose > 1 ) { 196 { << 167 G4cout << " -- File : " << file << " -- Event# " 197 G4cout << " -- File : " << file << " << 168 << evt->GetEventID() 198 << " -- Hit Collections Store 169 << " -- Hit Collections Stored." << G4endl; 199 } 170 } 200 } << 171 } else { 201 else << 202 { << 203 st1 = false; 172 st1 = false; 204 } 173 } 205 } 174 } 206 } 175 } 207 176 208 // Store digits collection 177 // Store digits collection 209 // 178 // 210 obj = "Digits"; 179 obj = "Digits"; 211 if(f_pc->CurrentStoreMode(obj) == kOn) << 180 if ( f_pc->CurrentStoreMode(obj) == kOn ) { 212 { << 181 if ( G4DCofThisEvent* dc = evt->GetDCofThisEvent() ) { 213 if(G4DCofThisEvent* dc = evt->GetDCofThisE << 214 { << 215 file = f_pc->CurrentWriteFile(obj); 182 file = f_pc->CurrentWriteFile(obj); 216 if(TransactionManager()->SelectWriteFile << 183 if ( TransactionManager()->SelectWriteFile(obj, file) ) { 217 { << 218 st2 = DigitIO()->Store(dc); 184 st2 = DigitIO()->Store(dc); 219 if(st2 && m_verbose > 1) << 185 if ( st2 && m_verbose > 1 ) { 220 { << 186 G4cout << " -- File : " << file << " -- Event# " 221 G4cout << " -- File : " << file << " << 187 << evt->GetEventID() 222 << " -- Digit Collections Sto 188 << " -- Digit Collections Stored." << G4endl; 223 } 189 } 224 } << 190 } else { 225 else << 226 { << 227 st2 = false; 191 st2 = false; 228 } 192 } 229 } 193 } 230 } 194 } 231 195 232 // Store this G4EVENT 196 // Store this G4EVENT 233 // 197 // 234 if(mctevt != 0 || evt != 0) << 198 if ( mctevt!=0 || evt!=0 ) { 235 { << 199 obj = "Hits"; 236 obj = "Hits"; << 237 file = f_pc->CurrentWriteFile(obj); 200 file = f_pc->CurrentWriteFile(obj); 238 if(TransactionManager()->SelectWriteFile(o << 201 if ( TransactionManager()->SelectWriteFile(obj, file) ) { 239 { << 240 st3 = EventIO()->Store(evt); 202 st3 = EventIO()->Store(evt); 241 if(st3 && m_verbose > 1) << 203 if ( st3 && m_verbose > 1 ) { 242 { << 243 G4cout << " -- File name: " << f_pc->C 204 G4cout << " -- File name: " << f_pc->CurrentWriteFile("Hits") 244 << " -- Event# " << evt->GetEve << 205 << " -- Event# " << evt->GetEventID() 245 << " -- G4Pevent is Stored." << 206 << " -- G4Pevent is Stored." << G4endl; 246 } 207 } 247 } << 208 } else { 248 else << 249 { << 250 st3 = false; 209 st3 = false; 251 } 210 } 252 } 211 } 253 << 212 254 G4bool st = stmct && st1 && st2 && st3; 213 G4bool st = stmct && st1 && st2 && st3; 255 214 256 if(st) << 215 if ( st ) { 257 { << 258 TransactionManager()->Commit(); 216 TransactionManager()->Commit(); 259 if(m_verbose > 0) << 217 if ( m_verbose > 0 ) 260 G4cout << "G4PersistencyManager: event# << 218 G4cout << "G4PersistencyManager: event# " 261 << " is stored." << G4endl; << 219 << evt->GetEventID() << " is stored." << G4endl; 262 } << 220 } else { 263 else << 264 { << 265 G4cerr << "G4PersistencyManager::Store(G4E 221 G4cerr << "G4PersistencyManager::Store(G4Event) - Transaction aborted." 266 << G4endl; 222 << G4endl; 267 TransactionManager()->Abort(); 223 TransactionManager()->Abort(); 268 } 224 } 269 225 270 return st; 226 return st; 271 } 227 } 272 228 273 // ------------------------------------------- << 229 // Implementation of Retrieve 274 G4bool G4PersistencyManager::Retrieve(G4Event* 230 G4bool G4PersistencyManager::Retrieve(G4Event*& evt) 275 { 231 { 276 if(m_verbose > 2) << 232 if ( m_verbose > 2 ) { 277 { << 233 G4cout << "G4PersistencyManager::Retrieve(G4Event*&) is called." 278 G4cout << "G4PersistencyManager::Retrieve( << 234 << G4endl; 279 } 235 } 280 236 281 if(TransactionManager() == nullptr) << 237 if ( TransactionManager() == 0 ) return true; 282 return true; << 283 238 284 if(f_pc->CurrentRetrieveMode("MCTruth") == f << 239 if ( f_pc->CurrentRetrieveMode("MCTruth") == false && 285 f_pc->CurrentRetrieveMode("Hits") == fals << 240 f_pc->CurrentRetrieveMode("Hits") == false && 286 f_pc->CurrentRetrieveMode("Digits") == fa << 241 f_pc->CurrentRetrieveMode("Digits") == false ) { 287 { << 288 return true; 242 return true; 289 } 243 } 290 244 291 // Call package dependent Initialize() 245 // Call package dependent Initialize() 292 // 246 // 293 if(!f_is_initialized) << 247 if ( ! f_is_initialized ) { 294 { << 295 f_is_initialized = true; 248 f_is_initialized = true; 296 if(m_verbose > 1) << 249 if ( m_verbose > 1 ) { 297 { << 298 G4cout << "G4PersistencyManager:: Initia 250 G4cout << "G4PersistencyManager:: Initializing Transaction ... " 299 << G4endl; 251 << G4endl; 300 } 252 } 301 Initialize(); 253 Initialize(); 302 } 254 } 303 255 304 // Start event IO transaction 256 // Start event IO transaction 305 // 257 // 306 if(TransactionManager()->StartRead()) << 258 if ( TransactionManager()->StartRead() ) { 307 { << 259 if ( m_verbose > 2 ) { 308 if(m_verbose > 2) << 260 G4cout << "G4PersistencyManager: Read transaction started." 309 { << 261 << G4endl; 310 G4cout << "G4PersistencyManager: Read tr << 311 } 262 } 312 } << 263 } else { 313 else << 314 { << 315 G4cerr << "TransactionManager::Retrieve(G4 264 G4cerr << "TransactionManager::Retrieve(G4Event) - StartRead() failed." 316 << G4endl; 265 << G4endl; 317 return false; 266 return false; 318 } 267 } 319 268 320 G4bool st = false; 269 G4bool st = false; 321 G4String file; << 270 std::string file; 322 271 323 // Retrieve a G4EVENT 272 // Retrieve a G4EVENT 324 // 273 // 325 G4String obj = "Hits"; << 274 std::string obj = "Hits"; 326 if(f_pc->CurrentRetrieveMode(obj) == true) << 275 if ( f_pc->CurrentRetrieveMode(obj) == true ) { 327 { << 328 file = f_pc->CurrentReadFile(obj); 276 file = f_pc->CurrentReadFile(obj); 329 if(TransactionManager()->SelectReadFile(ob << 277 if ( TransactionManager()->SelectReadFile(obj, file) ) { 330 { << 331 st = EventIO()->Retrieve(evt); 278 st = EventIO()->Retrieve(evt); 332 if(st && m_verbose > 1) << 279 if ( st && m_verbose > 1 ) { 333 { << 280 G4cout << " -- File : " << file << " -- Event# " 334 G4cout << " -- File : " << file << " - << 281 << evt->GetEventID() 335 << " -- G4Event is Retrieved." 282 << " -- G4Event is Retrieved." << G4endl; 336 } 283 } 337 } << 284 } else { 338 else << 339 { << 340 st = false; 285 st = false; 341 } 286 } 342 } 287 } 343 288 344 if(st) << 289 if ( st ) { 345 { << 346 TransactionManager()->Commit(); 290 TransactionManager()->Commit(); 347 } << 291 } else { 348 else << 349 { << 350 G4cerr << "G4PersistencyManager::Retrieve( 292 G4cerr << "G4PersistencyManager::Retrieve() - Transaction aborted." 351 << G4endl; 293 << G4endl; 352 TransactionManager()->Abort(); 294 TransactionManager()->Abort(); 353 } 295 } 354 296 355 return st; 297 return st; 356 } 298 } >> 299 >> 300 // End of G4PersistencyManager.cc 357 301