source: trunk/source/persistency/mctruth/src/G4PersistencyCenter.cc@ 1256

Last change on this file since 1256 was 818, checked in by garnier, 17 years ago

import all except CVS

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