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