ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4RootRFileManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4RootRFileManager.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 
27 // Author: Ivana Hrivnacova, 10/09/2014 (ivana@ipno.in2p3.fr)
28 
29 #include "G4RootRFileManager.hh"
31 
32 #include "tools/rroot/file"
33 #include <tools/zlib>
34 
35 #include <iostream>
36 #include <cstdio>
37 
38 //_____________________________________________________________________________
40  : G4BaseFileManager(state),
41  fRFiles()
42 {
43 }
44 
45 //_____________________________________________________________________________
47 {
48  for (G4int i=0; i<G4int(fRFiles.size()); ++i) {
49  delete fRFiles[i];
50  }
51 }
52 
53 //
54 // public methods
55 //
56 
57 //_____________________________________________________________________________
59  G4bool isPerThread)
60 {
61  // Get full file name
62  G4String name = GetFullFileName(fileName, isPerThread);
63 
64 #ifdef G4VERBOSE
65  if ( fState.GetVerboseL4() )
66  fState.GetVerboseL4()->Message("open", "read analysis file", name);
67 #endif
68 
69  // create new file
70  tools::rroot::file* newFile = new tools::rroot::file(G4cout, name);
71  newFile->add_unziper('Z',tools::decompress_buffer);
72 
73  if ( ! newFile->is_open() ) {
74  G4ExceptionDescription description;
75  description << " " << "Cannot open file " << name;
76  G4Exception("G4RootRFileManager::OpenFile()",
77  "Analysis_WR001", JustWarning, description);
78  delete newFile;
79  return false;
80  }
81 
82  // add file in a map and delete the previous file if it exists
83  std::map<G4String, tools::rroot::file*>::iterator it
84  = fRFiles.find(name);
85  if ( it != fRFiles.end() ) {
86  delete it->second;
87  it->second = newFile;
88  }
89  else {
90  fRFiles[name] = newFile;
91  }
92 
93 #ifdef G4VERBOSE
94  if ( fState.GetVerboseL1() )
96  ->Message("open", "read analysis file", name);
97 #endif
98 
99  return true;
100 }
101 
102 //_____________________________________________________________________________
104  G4bool isPerThread) const
105 {
106  // Get full file name
107  G4String name = GetFullFileName(fileName, isPerThread);
108 
109  std::map<G4String, tools::rroot::file*>::const_iterator it
110  = fRFiles.find(name);
111  if ( it != fRFiles.end() )
112  return it->second;
113  else {
114  return nullptr;
115  }
116 }