ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PersistencyManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4PersistencyManager.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: G4PersistencyManager.cc
27 //
28 // History:
29 // 01.07.17 Youhei Morita Initial creation (with "fadsclass")
30 
31 #include "G4PersistencyManager.hh"
32 
33 // Addtional Include:
34 #include <iomanip>
35 #include "G4PersistencyCenter.hh"
36 
37 // Implementation of Constructor #1
39  : f_pc(ptc), nameMgr(n), f_is_initialized(false)
40 {
42 }
43 
44 // Implementation of Destructor #1
46 {}
47 
48 // Implementation of GetPersistencyManager
50 {
52 }
53 
54 // Implementation of SetVerboseLevel
56 {
57  m_verbose = v;
58  if ( m_verbose > 2 ) {
59  G4cout << "G4PersistencyManager[\"" << nameMgr << "\"," << this
60  << "]: verbose level is set to " << m_verbose << "."
61  << G4endl;
62  }
63  if ( EventIO() != 0 ) EventIO()->SetVerboseLevel(m_verbose);
64  if ( MCTruthIO() != 0 ) MCTruthIO()->SetVerboseLevel(m_verbose);
65  if ( HitIO() != 0 ) HitIO()->SetVerboseLevel(m_verbose);
66  if ( DigitIO() != 0 ) DigitIO()->SetVerboseLevel(m_verbose);
68 
69  size_t i;
70 
72  if ( hcio != 0 ) {
74  for ( i = 0; i < hcio->NumberOfHCIOmanager(); i++ ) {
76  }
77  }
79  if ( dcio != 0 ) {
81  for ( i = 0; i < dcio->NumberOfDCIOmanager(); i++ ) {
83  }
84  }
85 }
86 
87 // Implementation of Store
89 {
90  if ( m_verbose > 2 ) {
91  G4cout << "G4PersistencyManager::Store() is called for event# "
92  << evt->GetEventID() << "." << G4endl;
93  }
94 
95  if ( TransactionManager() == 0 ) return true;
96 
97  G4bool is_store = f_pc->CurrentStoreMode("MCTruth") != kOff ||
98  f_pc->CurrentStoreMode("Hits") != kOff ||
99  f_pc->CurrentStoreMode("Digits") != kOff;
100 
101  if ( ! is_store ) return true;
102 
103  // Call package dependent Initialize()
104  //
105  if ( ! f_is_initialized ) {
106  f_is_initialized = true;
107  if ( m_verbose > 1 ) {
108  G4cout << "G4PersistencyManager:: Initializing Transaction ... "
109  << G4endl;
110  }
111  Initialize();
112  }
113 
114  G4bool st1 = true, st2 = true;
115 
116  // Start event IO transaction
117  //
118  if ( TransactionManager()->StartUpdate() ) {
119  if ( m_verbose > 2 ) {
120  G4cout << "G4PersistencyManager: Update transaction started for event#"
121  << evt->GetEventID() << "." << G4endl;
122  }
123  } else {
124  G4cerr << "TransactionManager::Store(G4Event) - StartUpdate() failed."
125  << G4endl;
126  return false;
127  }
128 
129  std::string file;
130  std::string obj;
131 
132  G4bool stmct = true, st3 = true;
133 
134  // Store MCTruth event
135  //
136  obj = "MCTruth";
137  G4MCTEvent* mctevt = 0;
138  if ( f_pc->CurrentStoreMode(obj) == kOn ) {
139 
140  // Note: This part of code will not be activated until a method
141  // to obtain the current pointer of G4MCTEvent* become available.
142 
143  // if ( (mctevt = f_MCTman->GetCurrentEvent()) != 0 ) {
144  if ( mctevt != 0 ) {
145  file = f_pc->CurrentWriteFile(obj);
146  if ( TransactionManager()->SelectWriteFile(obj, file) ) {
147  stmct = MCTruthIO()->Store(mctevt);
148  if ( stmct && m_verbose > 1 ) {
149  G4cout << " -- File : " << file << " -- Event# "
150  << evt->GetEventID() << " -- G4MCTEvent Stored." << G4endl;
151  }
152  } else {
153  stmct = false;
154  }
155  } // end of if ( mctevt != 0 )
156  }
157 
158  // Store hits collection
159  //
160  obj = "Hits";
161  if ( f_pc->CurrentStoreMode(obj) == kOn ) {
162  if ( G4HCofThisEvent* hc = evt->GetHCofThisEvent() ) {
163  file = f_pc->CurrentWriteFile(obj);
164  if ( TransactionManager()->SelectWriteFile(obj, file) ) {
165  st1 = HitIO()->Store(hc);
166  if ( st1 && m_verbose > 1 ) {
167  G4cout << " -- File : " << file << " -- Event# "
168  << evt->GetEventID()
169  << " -- Hit Collections Stored." << G4endl;
170  }
171  } else {
172  st1 = false;
173  }
174  }
175  }
176 
177  // Store digits collection
178  //
179  obj = "Digits";
180  if ( f_pc->CurrentStoreMode(obj) == kOn ) {
181  if ( G4DCofThisEvent* dc = evt->GetDCofThisEvent() ) {
182  file = f_pc->CurrentWriteFile(obj);
183  if ( TransactionManager()->SelectWriteFile(obj, file) ) {
184  st2 = DigitIO()->Store(dc);
185  if ( st2 && m_verbose > 1 ) {
186  G4cout << " -- File : " << file << " -- Event# "
187  << evt->GetEventID()
188  << " -- Digit Collections Stored." << G4endl;
189  }
190  } else {
191  st2 = false;
192  }
193  }
194  }
195 
196  // Store this G4EVENT
197  //
198  if ( mctevt!=0 || evt!=0 ) {
199  obj = "Hits";
200  file = f_pc->CurrentWriteFile(obj);
201  if ( TransactionManager()->SelectWriteFile(obj, file) ) {
202  st3 = EventIO()->Store(evt);
203  if ( st3 && m_verbose > 1 ) {
204  G4cout << " -- File name: " << f_pc->CurrentWriteFile("Hits")
205  << " -- Event# " << evt->GetEventID()
206  << " -- G4Pevent is Stored." << G4endl;
207  }
208  } else {
209  st3 = false;
210  }
211  }
212 
213  G4bool st = stmct && st1 && st2 && st3;
214 
215  if ( st ) {
217  if ( m_verbose > 0 )
218  G4cout << "G4PersistencyManager: event# "
219  << evt->GetEventID() << " is stored." << G4endl;
220  } else {
221  G4cerr << "G4PersistencyManager::Store(G4Event) - Transaction aborted."
222  << G4endl;
224  }
225 
226  return st;
227 }
228 
229 // Implementation of Retrieve
231 {
232  if ( m_verbose > 2 ) {
233  G4cout << "G4PersistencyManager::Retrieve(G4Event*&) is called."
234  << G4endl;
235  }
236 
237  if ( TransactionManager() == 0 ) return true;
238 
239  if ( f_pc->CurrentRetrieveMode("MCTruth") == false &&
240  f_pc->CurrentRetrieveMode("Hits") == false &&
241  f_pc->CurrentRetrieveMode("Digits") == false ) {
242  return true;
243  }
244 
245  // Call package dependent Initialize()
246  //
247  if ( ! f_is_initialized ) {
248  f_is_initialized = true;
249  if ( m_verbose > 1 ) {
250  G4cout << "G4PersistencyManager:: Initializing Transaction ... "
251  << G4endl;
252  }
253  Initialize();
254  }
255 
256  // Start event IO transaction
257  //
258  if ( TransactionManager()->StartRead() ) {
259  if ( m_verbose > 2 ) {
260  G4cout << "G4PersistencyManager: Read transaction started."
261  << G4endl;
262  }
263  } else {
264  G4cerr << "TransactionManager::Retrieve(G4Event) - StartRead() failed."
265  << G4endl;
266  return false;
267  }
268 
269  G4bool st = false;
270  std::string file;
271 
272  // Retrieve a G4EVENT
273  //
274  std::string obj = "Hits";
275  if ( f_pc->CurrentRetrieveMode(obj) == true ) {
276  file = f_pc->CurrentReadFile(obj);
277  if ( TransactionManager()->SelectReadFile(obj, file) ) {
278  st = EventIO()->Retrieve(evt);
279  if ( st && m_verbose > 1 ) {
280  G4cout << " -- File : " << file << " -- Event# "
281  << evt->GetEventID()
282  << " -- G4Event is Retrieved." << G4endl;
283  }
284  } else {
285  st = false;
286  }
287  }
288 
289  if ( st ) {
291  } else {
292  G4cerr << "G4PersistencyManager::Retrieve() - Transaction aborted."
293  << G4endl;
295  }
296 
297  return st;
298 }
299 
300 // End of G4PersistencyManager.cc