[818] | 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 | // File: G4PersistencyCenter.cc |
---|
| 27 | // |
---|
| 28 | // History: |
---|
| 29 | // '01.08.10 Youhei Morita Initial creation (with "fadsclass3") |
---|
| 30 | |
---|
| 31 | #include "G4PersistencyCenter.hh" |
---|
| 32 | |
---|
| 33 | // Forward Declarations: |
---|
| 34 | #include "G4PersistencyCenterMessenger.hh" |
---|
| 35 | |
---|
| 36 | // Addtional Include: |
---|
| 37 | #include "G4UImanager.hh" |
---|
| 38 | #include "G4PersistencyManager.hh" |
---|
[1347] | 39 | #include "G4VHCIOentry.hh" |
---|
| 40 | #include "G4VDCIOentry.hh" |
---|
[818] | 41 | |
---|
| 42 | G4PersistencyCenter* G4PersistencyCenter::f_thePointer=G4PersistencyCenter::GetPersistencyCenter(); |
---|
| 43 | |
---|
| 44 | // Implementation of Constructor #1 |
---|
| 45 | G4PersistencyCenter::G4PersistencyCenter() |
---|
| 46 | : m_verbose(0) |
---|
| 47 | { |
---|
| 48 | f_wrObj[0] = "HepMC"; |
---|
| 49 | f_wrObj[1] = "MCTruth"; |
---|
| 50 | f_wrObj[2] = "Hits"; |
---|
| 51 | f_wrObj[3] = "Digits"; |
---|
| 52 | |
---|
| 53 | f_rdObj[0] = "Hits"; |
---|
| 54 | f_rdObj[1] = "HitsBG"; |
---|
| 55 | |
---|
| 56 | ObjMap::iterator itr; |
---|
| 57 | |
---|
| 58 | for ( itr = f_wrObj.begin(); itr != f_wrObj.end(); itr++ ) { |
---|
| 59 | f_writeFileName[(*itr).second] = "G4defaultOutput"; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | for ( itr = f_rdObj.begin(); itr != f_rdObj.end(); itr++ ) { |
---|
| 63 | f_readFileName[(*itr).second] = "G4defaultInput"; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | f_writeFileMode["HepMC"] = kRecycle; |
---|
| 67 | f_writeFileMode["MCTruth"] = kOn; |
---|
| 68 | f_writeFileMode["Hits"] = kOn; |
---|
| 69 | f_writeFileMode["Digits"] = kOff; |
---|
| 70 | |
---|
| 71 | f_readFileMode["Hits"] = false; |
---|
| 72 | f_readFileMode["HitsBG"] = false; |
---|
| 73 | |
---|
| 74 | f_theMessenger = new G4PersistencyCenterMessenger(this); |
---|
| 75 | f_currentManager = new G4PersistencyManager(this, "Default"); |
---|
| 76 | } |
---|
| 77 | |
---|
[1347] | 78 | // Fake implementation of Copy Constructor |
---|
| 79 | G4PersistencyCenter::G4PersistencyCenter(const G4PersistencyCenter& c) |
---|
| 80 | : f_theMessenger(0), f_currentManager(0), m_verbose(0) |
---|
| 81 | { |
---|
| 82 | *this = c; |
---|
| 83 | } |
---|
[818] | 84 | |
---|
| 85 | // Implementation of Destructor #1 |
---|
| 86 | G4PersistencyCenter::~G4PersistencyCenter() |
---|
| 87 | { |
---|
| 88 | delete f_theMessenger; |
---|
| 89 | delete f_currentManager; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | // Implementation of GetPersistencyCenter |
---|
| 93 | G4PersistencyCenter* G4PersistencyCenter::GetPersistencyCenter() |
---|
| 94 | { |
---|
| 95 | if ( f_thePointer == 0 ) f_thePointer = new G4PersistencyCenter; |
---|
| 96 | return f_thePointer; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | // Implementation of SelectSystem |
---|
| 101 | void G4PersistencyCenter::SelectSystem(std::string systemName) |
---|
| 102 | { |
---|
[1347] | 103 | G4int st = 0; |
---|
[818] | 104 | |
---|
| 105 | if (f_currentManager!=0) delete f_currentManager; |
---|
| 106 | |
---|
| 107 | G4PersistencyManager* pm = 0; |
---|
| 108 | |
---|
[1347] | 109 | if (systemName=="ROOT") |
---|
[818] | 110 | { |
---|
| 111 | G4cout<<" G4PersistencyCenter: \"ROOT\" Persistency Package is selected." |
---|
| 112 | <<G4endl; |
---|
| 113 | // G4UImanager *man=G4UImanager::GetUIpointer(); |
---|
| 114 | // std::string libs="Cint:Core:Tree:Rint:Matrix:Physics:fadsROOT"; |
---|
| 115 | // st = man->ApplyCommand("/load "+libs); |
---|
| 116 | if ( st == 0 ) { |
---|
| 117 | pm = GetPersistencyManager("ROOT"); |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | else if (systemName=="ODBMS") |
---|
| 121 | { |
---|
| 122 | G4cout<<" G4PersistencyCenter: \"ODBMS\" package is selected."<<G4endl; |
---|
| 123 | // G4UImanager *man=G4UImanager::GetUIpointer(); |
---|
| 124 | // std::string libs="fadsODBMS"; |
---|
| 125 | // st = man->ApplyCommand("/load "+libs); |
---|
| 126 | if ( st == 0 ) { |
---|
| 127 | pm = GetPersistencyManager("ODBMS"); |
---|
| 128 | } |
---|
| 129 | } |
---|
[1347] | 130 | else |
---|
| 131 | { |
---|
| 132 | G4cout<<" G4PersistencyCenter: Default is selected."<< G4endl; |
---|
| 133 | pm = new G4PersistencyManager(this, "Default"); |
---|
| 134 | } |
---|
| 135 | |
---|
[818] | 136 | if ( st == 0 ) { |
---|
| 137 | f_currentManager = pm->Create(); |
---|
| 138 | if (f_currentManager!=0) f_currentManager->SetVerboseLevel(m_verbose); |
---|
| 139 | f_currentSystemName = systemName; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | // Implementation of SetHepMCObjyReaderFile |
---|
| 144 | void G4PersistencyCenter::SetHepMCObjyReaderFile(std::string file) |
---|
| 145 | { |
---|
| 146 | if ( SetReadFile("HepMC", file) ) { |
---|
| 147 | SetRetrieveMode("HepMC", true); |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | // Implementation of CurrentHepMCObjyReaderFile |
---|
| 152 | std::string G4PersistencyCenter::CurrentHepMCObjyReaderFile() |
---|
| 153 | { |
---|
| 154 | if ( CurrentRetrieveMode("HepMC") ) { |
---|
| 155 | return CurrentReadFile("HepMC"); |
---|
| 156 | } else { |
---|
| 157 | return ""; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | // Implementation of SetStoreMode |
---|
| 162 | void G4PersistencyCenter::SetStoreMode(std::string objName, StoreMode mode) |
---|
| 163 | { |
---|
| 164 | if ( (*(f_writeFileName.find(objName))).second != "" ) { |
---|
| 165 | f_writeFileMode[objName] = mode; |
---|
| 166 | } else { |
---|
| 167 | G4cerr << "!! unknown object type " << objName << " for output." |
---|
| 168 | << G4endl; |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | // Implementation of SetRetrieveMode |
---|
| 173 | void G4PersistencyCenter::SetRetrieveMode(std::string objName, G4bool mode) |
---|
| 174 | { |
---|
| 175 | if ( (*(f_readFileName.find(objName))).second != "" ) { |
---|
| 176 | f_readFileMode[objName] = mode; |
---|
| 177 | } else { |
---|
| 178 | G4cerr << "!! unknown object type " << objName << " for input." |
---|
| 179 | << G4endl; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | // Implementation of CurrentStoreMode |
---|
| 184 | StoreMode G4PersistencyCenter::CurrentStoreMode(std::string objName) |
---|
| 185 | { |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | if ( (*(f_writeFileName.find(objName))).second != "" ) { |
---|
| 189 | return f_writeFileMode[objName]; |
---|
| 190 | } else { |
---|
| 191 | return kOff; |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | // Implementation of CurrentRetrieveMode |
---|
| 196 | G4bool G4PersistencyCenter::CurrentRetrieveMode(std::string objName) |
---|
| 197 | { |
---|
| 198 | if ( (*(f_readFileName.find(objName))).second != "" ) { |
---|
| 199 | return f_readFileMode[objName]; |
---|
| 200 | } else { |
---|
| 201 | return false; |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | // Implementation of SetWriteFile |
---|
| 206 | G4bool G4PersistencyCenter::SetWriteFile(std::string objName, std::string writeFileName) |
---|
| 207 | { |
---|
| 208 | if ( (*(f_writeFileName.find(objName))).second != "" ) { |
---|
| 209 | f_writeFileName[objName] = writeFileName; |
---|
| 210 | } else { |
---|
| 211 | G4cerr << "!! unknown object type " << objName << " for output." |
---|
| 212 | << G4endl; |
---|
| 213 | return false; |
---|
| 214 | } |
---|
| 215 | return true; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | // Implementation of SetReadFile |
---|
| 219 | G4bool G4PersistencyCenter::SetReadFile(std::string objName, std::string readFileName) |
---|
| 220 | { |
---|
| 221 | #ifndef WIN32 |
---|
| 222 | if ( f_ut.FileExists(readFileName) ) |
---|
| 223 | { |
---|
| 224 | f_readFileName[objName] = readFileName; |
---|
| 225 | } |
---|
| 226 | else |
---|
| 227 | { |
---|
| 228 | G4cerr << "!! File \"" << objName << "\" does not exist." |
---|
| 229 | << G4endl; |
---|
| 230 | return false; |
---|
| 231 | } |
---|
| 232 | #endif |
---|
| 233 | return true; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | // Implementation of CurrentWriteFile |
---|
| 237 | std::string G4PersistencyCenter::CurrentWriteFile(std::string objName) |
---|
| 238 | { |
---|
| 239 | if ( (*(f_writeFileName.find(objName))).second != "" ) { |
---|
| 240 | return f_writeFileName[objName]; |
---|
| 241 | } else { |
---|
| 242 | return "?????"; |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | // Implementation of CurrentReadFile |
---|
| 247 | std::string G4PersistencyCenter::CurrentReadFile(std::string objName) |
---|
| 248 | { |
---|
| 249 | if ( (*(f_readFileName.find(objName))).second != "" ) { |
---|
| 250 | return f_readFileName[objName]; |
---|
| 251 | } else { |
---|
| 252 | return "?????"; |
---|
| 253 | } |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | // Implementation of CurrentObject |
---|
| 257 | std::string G4PersistencyCenter::CurrentObject(std::string file) |
---|
| 258 | { |
---|
| 259 | FileMap::iterator itr; |
---|
| 260 | for ( itr = f_readFileName.begin(); itr != f_readFileName.end(); itr++ ) { |
---|
| 261 | if ( file == (*itr).second ) return (*itr).first; |
---|
| 262 | } |
---|
| 263 | for ( itr = f_writeFileName.begin(); itr != f_writeFileName.end(); itr++ ) { |
---|
| 264 | if ( file == (*itr).second ) return (*itr).first; |
---|
| 265 | } |
---|
| 266 | return "?????"; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | // Implementation of AddHCIOmanager |
---|
| 270 | void G4PersistencyCenter::AddHCIOmanager(std::string detName, std::string colName) |
---|
| 271 | { |
---|
| 272 | G4HCIOcatalog* ioc = G4HCIOcatalog::GetHCIOcatalog(); |
---|
| 273 | |
---|
| 274 | G4VHCIOentry* ioe = ioc->GetEntry(detName); |
---|
| 275 | if ( ioe != 0 ) { |
---|
| 276 | ioe->CreateHCIOmanager(detName, colName); |
---|
| 277 | } else { |
---|
| 278 | G4cerr << "Error! -- HCIO assignment failed for detector " << detName |
---|
| 279 | << ", collection " << colName << G4endl; |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | // Implementation of CurrentHCIOmanager |
---|
| 284 | std::string G4PersistencyCenter::CurrentHCIOmanager() |
---|
| 285 | { |
---|
| 286 | G4HCIOcatalog* ioc = G4HCIOcatalog::GetHCIOcatalog(); |
---|
| 287 | return ioc->CurrentHCIOmanager(); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | // Implementation of AddDCIOmanager |
---|
| 291 | void G4PersistencyCenter::AddDCIOmanager(std::string detName) |
---|
| 292 | { |
---|
| 293 | G4DCIOcatalog* ioc = G4DCIOcatalog::GetDCIOcatalog(); |
---|
| 294 | |
---|
| 295 | std::string colName = ""; |
---|
| 296 | G4VDCIOentry* ioe = ioc->GetEntry(detName); |
---|
| 297 | if ( ioe != 0 ) { |
---|
| 298 | ioe->CreateDCIOmanager(detName, colName); |
---|
| 299 | } else { |
---|
| 300 | G4cerr << "Error! -- DCIO assignment failed for detector " << detName |
---|
| 301 | << ", collection " << colName << G4endl; |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | // Implementation of CurrentDCIOmanager |
---|
| 306 | std::string G4PersistencyCenter::CurrentDCIOmanager() |
---|
| 307 | { |
---|
| 308 | G4DCIOcatalog* ioc = G4DCIOcatalog::GetDCIOcatalog(); |
---|
| 309 | return ioc->CurrentDCIOmanager(); |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | // Implementation of PrintAll |
---|
| 313 | void G4PersistencyCenter::PrintAll() |
---|
| 314 | { |
---|
| 315 | G4cout << "Persistency Package: " << CurrentSystem() << G4endl; |
---|
| 316 | G4cout << G4endl; |
---|
| 317 | |
---|
| 318 | ObjMap::iterator itr; |
---|
| 319 | std::string name; |
---|
| 320 | std::string file; |
---|
| 321 | StoreMode mode; |
---|
| 322 | |
---|
| 323 | G4cout << "Output object types and file names:" << G4endl; |
---|
| 324 | for ( itr = f_wrObj.begin(); itr != f_wrObj.end(); itr++ ) { |
---|
| 325 | name = (*itr).second; |
---|
| 326 | // disabled HepMC and MCTruth for now |
---|
| 327 | if ( name != "HepMC" && name != "MCTruth" ) { |
---|
| 328 | G4cout << " Object: " << PadString(name, 9); |
---|
| 329 | mode = CurrentStoreMode(name); |
---|
| 330 | if ( mode == kOn ) { |
---|
| 331 | G4cout << " <on> "; |
---|
| 332 | } else if ( mode == kOff ) { |
---|
| 333 | G4cout << " <off> "; |
---|
| 334 | } else if ( mode == kRecycle ) { |
---|
| 335 | G4cout << "<recycle>"; |
---|
| 336 | } |
---|
| 337 | file = CurrentWriteFile(name); |
---|
| 338 | if ( file == "" ) file = " <N/A>"; |
---|
| 339 | G4cout << " File: " << file << G4endl; |
---|
| 340 | } |
---|
| 341 | } |
---|
| 342 | G4cout << G4endl; |
---|
| 343 | |
---|
| 344 | G4cout << "Input object types and file names:" << G4endl; |
---|
| 345 | for ( itr = f_rdObj.begin(); itr != f_rdObj.end(); itr++ ) { |
---|
| 346 | name = (*itr).second; |
---|
| 347 | // disabled HepMC and MCTruth for now |
---|
| 348 | if ( name != "HepMC" && name != "MCTruth" ) { |
---|
| 349 | G4cout << " Object: " << PadString(name, 9); |
---|
| 350 | if ( CurrentRetrieveMode(name) ) { |
---|
| 351 | G4cout << " <on> "; |
---|
| 352 | } else { |
---|
| 353 | G4cout << " <off> "; |
---|
| 354 | } |
---|
| 355 | file = CurrentReadFile(name); |
---|
| 356 | if ( file == "" ) file = " <N/A>"; |
---|
| 357 | G4cout << " File: " << CurrentReadFile(name) << G4endl; |
---|
| 358 | } |
---|
| 359 | } |
---|
| 360 | G4cout << G4endl; |
---|
| 361 | |
---|
| 362 | G4HCIOcatalog* hioc = G4HCIOcatalog::GetHCIOcatalog(); |
---|
| 363 | if ( hioc != 0 ) { |
---|
| 364 | G4cout << "Hit IO Managers:" << G4endl; |
---|
| 365 | hioc->PrintEntries(); |
---|
| 366 | hioc->PrintHCIOmanager(); |
---|
| 367 | G4cout << G4endl; |
---|
| 368 | } else { |
---|
| 369 | G4cout << "Hit IO Manager catalog is not registered." << G4endl; |
---|
| 370 | } |
---|
| 371 | |
---|
| 372 | G4DCIOcatalog* dioc = G4DCIOcatalog::GetDCIOcatalog(); |
---|
| 373 | if ( dioc != 0 ) { |
---|
| 374 | G4cout << "Digit IO Managers:" << G4endl; |
---|
| 375 | dioc->PrintEntries(); |
---|
| 376 | dioc->PrintDCIOmanager(); |
---|
| 377 | G4cout << G4endl; |
---|
| 378 | } else { |
---|
| 379 | G4cout << "Digit IO Manager catalog is not registered." << G4endl; |
---|
| 380 | } |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | // Implementation of SetPersistencyManager |
---|
| 384 | void G4PersistencyCenter::SetPersistencyManager(G4PersistencyManager* pm, |
---|
| 385 | std::string name) |
---|
| 386 | { |
---|
| 387 | f_currentManager=pm; |
---|
| 388 | f_currentSystemName=name; |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | // Implementation of GetPersistencyManager |
---|
| 392 | G4PersistencyManager* G4PersistencyCenter::GetPersistencyManager(std::string nam) |
---|
| 393 | { |
---|
| 394 | if (f_theCatalog.find(nam)!=f_theCatalog.end()) |
---|
| 395 | return f_theCatalog[nam]; |
---|
| 396 | return 0; |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | // Implementation of RegisterPersistencyManager |
---|
| 400 | void G4PersistencyCenter::RegisterPersistencyManager(G4PersistencyManager* pm) |
---|
| 401 | { |
---|
| 402 | f_theCatalog[pm->GetName()]=pm; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | // Implementation of DeletePersistencyManager |
---|
| 406 | void G4PersistencyCenter::DeletePersistencyManager() |
---|
| 407 | { |
---|
| 408 | if (f_currentManager!=0) delete f_currentManager; |
---|
| 409 | f_currentManager=0; |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | // Implementation of SetVerboseLevel |
---|
| 413 | void G4PersistencyCenter::SetVerboseLevel(int v) |
---|
| 414 | { |
---|
| 415 | m_verbose = v; |
---|
| 416 | if ( f_currentManager != 0 ) f_currentManager->SetVerboseLevel(m_verbose); |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | // Implementation of PadString |
---|
| 420 | std::string G4PersistencyCenter::PadString(std::string name, unsigned int width) |
---|
| 421 | { |
---|
| 422 | if ( name.length() > width ) { |
---|
| 423 | return name.substr(0,width-1) + "#"; |
---|
| 424 | } else { |
---|
| 425 | std::string wname = name; |
---|
| 426 | for ( unsigned int i=0; i < width-name.length(); i++) wname = wname + " "; |
---|
| 427 | return wname; |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | // End of G4PersistencyCenter.cc |
---|
| 432 | |
---|