ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PersistencyCenter.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4PersistencyCenter.cc
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:
35 
36 // Addtional Include:
37 #include "G4UImanager.hh"
38 #include "G4PersistencyManager.hh"
39 #include "G4VHCIOentry.hh"
40 #include "G4VDCIOentry.hh"
41 
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 
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 {
89  return f_thePointer;
90 }
91 
92 
93 // Implementation of SelectSystem
94 void G4PersistencyCenter::SelectSystem(std::string systemName)
95 {
96  G4int st = 0;
97 
98  if (f_currentManager!=0) delete f_currentManager;
99 
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();
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
155 void 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
166 void 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  if ( (*(f_writeFileName.find(objName))).second != "" ) {
180  return f_writeFileMode[objName];
181  } else {
182  return kOff;
183  }
184 }
185 
186 // Implementation of CurrentRetrieveMode
188 {
189  if ( (*(f_readFileName.find(objName))).second != "" ) {
190  return f_readFileMode[objName];
191  } else {
192  return false;
193  }
194 }
195 
196 // Implementation of SetWriteFile
197 G4bool G4PersistencyCenter::SetWriteFile(std::string objName, std::string writeFileName)
198 {
199  if ( (*(f_writeFileName.find(objName))).second != "" ) {
200  f_writeFileName[objName] = writeFileName;
201  } else {
202  G4cerr << "!! unknown object type " << objName << " for output."
203  << G4endl;
204  return false;
205  }
206  return true;
207 }
208 
209 // Implementation of SetReadFile
210 G4bool G4PersistencyCenter::SetReadFile(std::string objName, std::string readFileName)
211 {
212 #ifndef WIN32
213  if ( f_ut.FileExists(readFileName) )
214  {
215  f_readFileName[objName] = readFileName;
216  }
217  else
218  {
219  G4cerr << "!! File \"" << objName << "\" does not exist."
220  << G4endl;
221  return false;
222  }
223 #endif
224  return true;
225 }
226 
227 // Implementation of CurrentWriteFile
228 std::string G4PersistencyCenter::CurrentWriteFile(std::string objName)
229 {
230  if ( (*(f_writeFileName.find(objName))).second != "" ) {
231  return f_writeFileName[objName];
232  } else {
233  return "?????";
234  }
235 }
236 
237 // Implementation of CurrentReadFile
238 std::string G4PersistencyCenter::CurrentReadFile(std::string objName)
239 {
240  if ( (*(f_readFileName.find(objName))).second != "" ) {
241  return f_readFileName[objName];
242  } else {
243  return "?????";
244  }
245 }
246 
247 // Implementation of CurrentObject
248 std::string G4PersistencyCenter::CurrentObject(std::string file)
249 {
250  FileMap::iterator itr;
251  for ( itr = f_readFileName.begin(); itr != f_readFileName.end(); itr++ ) {
252  if ( file == (*itr).second ) return (*itr).first;
253  }
254  for ( itr = f_writeFileName.begin(); itr != f_writeFileName.end(); itr++ ) {
255  if ( file == (*itr).second ) return (*itr).first;
256  }
257  return "?????";
258 }
259 
260 // Implementation of AddHCIOmanager
261 void G4PersistencyCenter::AddHCIOmanager(std::string detName, std::string colName)
262 {
264 
265  G4VHCIOentry* ioe = ioc->GetEntry(detName);
266  if ( ioe != 0 ) {
267  ioe->CreateHCIOmanager(detName, colName);
268  } else {
269  G4cerr << "Error! -- HCIO assignment failed for detector " << detName
270  << ", collection " << colName << G4endl;
271  }
272 }
273 
274 // Implementation of CurrentHCIOmanager
276 {
278  return ioc->CurrentHCIOmanager();
279 }
280 
281 // Implementation of AddDCIOmanager
282 void G4PersistencyCenter::AddDCIOmanager(std::string detName)
283 {
285 
286  std::string colName = "";
287  G4VDCIOentry* ioe = ioc->GetEntry(detName);
288  if ( ioe != 0 ) {
289  ioe->CreateDCIOmanager(detName, colName);
290  } else {
291  G4cerr << "Error! -- DCIO assignment failed for detector " << detName
292  << ", collection " << colName << G4endl;
293  }
294 }
295 
296 // Implementation of CurrentDCIOmanager
298 {
300  return ioc->CurrentDCIOmanager();
301 }
302 
303 // Implementation of PrintAll
305 {
306  G4cout << "Persistency Package: " << CurrentSystem() << G4endl;
307  G4cout << G4endl;
308 
309  ObjMap::iterator itr;
310  std::string name;
311  std::string file;
312  StoreMode mode;
313 
314  G4cout << "Output object types and file names:" << G4endl;
315  for ( itr = f_wrObj.begin(); itr != f_wrObj.end(); itr++ ) {
316  name = (*itr).second;
317  // disabled HepMC and MCTruth for now
318  if ( name != "HepMC" && name != "MCTruth" ) {
319  G4cout << " Object: " << PadString(name, 9);
320  mode = CurrentStoreMode(name);
321  if ( mode == kOn ) {
322  G4cout << " <on> ";
323  } else if ( mode == kOff ) {
324  G4cout << " <off> ";
325  } else if ( mode == kRecycle ) {
326  G4cout << "<recycle>";
327  }
328  file = CurrentWriteFile(name);
329  if ( file == "" ) file = " <N/A>";
330  G4cout << " File: " << file << G4endl;
331  }
332  }
333  G4cout << G4endl;
334 
335  G4cout << "Input object types and file names:" << G4endl;
336  for ( itr = f_rdObj.begin(); itr != f_rdObj.end(); itr++ ) {
337  name = (*itr).second;
338  // disabled HepMC and MCTruth for now
339  if ( name != "HepMC" && name != "MCTruth" ) {
340  G4cout << " Object: " << PadString(name, 9);
341  if ( CurrentRetrieveMode(name) ) {
342  G4cout << " <on> ";
343  } else {
344  G4cout << " <off> ";
345  }
346  file = CurrentReadFile(name);
347  if ( file == "" ) file = " <N/A>";
348  G4cout << " File: " << CurrentReadFile(name) << G4endl;
349  }
350  }
351  G4cout << G4endl;
352 
354  if ( hioc != 0 ) {
355  G4cout << "Hit IO Managers:" << G4endl;
356  hioc->PrintEntries();
357  hioc->PrintHCIOmanager();
358  G4cout << G4endl;
359  } else {
360  G4cout << "Hit IO Manager catalog is not registered." << G4endl;
361  }
362 
364  if ( dioc != 0 ) {
365  G4cout << "Digit IO Managers:" << G4endl;
366  dioc->PrintEntries();
367  dioc->PrintDCIOmanager();
368  G4cout << G4endl;
369  } else {
370  G4cout << "Digit IO Manager catalog is not registered." << G4endl;
371  }
372 }
373 
374 // Implementation of SetPersistencyManager
376  std::string name)
377 {
380 }
381 
382 // Implementation of GetPersistencyManager
384 {
385  if (f_theCatalog.find(nam)!=f_theCatalog.end())
386  return f_theCatalog[nam];
387  return 0;
388 }
389 
390 // Implementation of RegisterPersistencyManager
392 {
393  f_theCatalog[pm->GetName()]=pm;
394 }
395 
396 // Implementation of DeletePersistencyManager
398 {
399  if (f_currentManager!=0) delete f_currentManager;
401 }
402 
403 // Implementation of SetVerboseLevel
405 {
406  m_verbose = v;
408 }
409 
410 // Implementation of PadString
411 std::string G4PersistencyCenter::PadString(std::string name, unsigned int width)
412 {
413  if ( name.length() > width ) {
414  return name.substr(0,width-1) + "#";
415  } else {
416  std::string wname = name;
417  for ( unsigned int i=0; i < width-name.length(); i++) wname = wname + " ";
418  return wname;
419  }
420 }
421 
422 // End of G4PersistencyCenter.cc