Cache.h
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \class genie::Cache
5 
6 \brief GENIE Cache Memory
7 
8 \author Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
9  University of Liverpool & STFC Rutherford Appleton Laboratory
10 
11 \created November 26, 2004
12 
13 \cpright Copyright (c) 2003-2020, The GENIE Collaboration
14  For the full text of the license visit http://copyright.genie-mc.org
15 */
16 //____________________________________________________________________________
17 
18 #ifndef _CACHE_H_
19 #define _CACHE_H_
20 
21 #include <map>
22 #include <string>
23 #include <ostream>
24 
25 #include <TFile.h>
26 
27 using std::map;
28 using std::string;
29 using std::ostream;
30 
31 namespace genie {
32 
33 class Cache;
34 class CacheBranchI;
35 
36 ostream & operator << (ostream & stream, const Cache & cache);
37 
38 class Cache
39 {
40 public:
41 
42  static Cache * Instance(void);
43 
44  //! cache file
45  void OpenCacheFile (string filename);
46 
47  //! finding/adding cache branches
48  CacheBranchI * FindCacheBranch (string key);
49  void AddCacheBranch (string key, CacheBranchI * branch);
50  string CacheBranchKey (string k0, string k1="", string k2="") const;
51 
52  //! removing cache branches
53  void RmCacheBranch (string key);
54  void RmAllCacheBranches (void);
55  void RmMatchedCacheBranches(string key_substring);
56 
57  //! print cache buffers
58  void Print (ostream & stream) const;
59  friend ostream & operator << (ostream & stream, const Cache & cache);
60 
61 private:
62 
63  //! load/save
64  void Load (void);
65  void Save (void);
66 
67  //! singleton instance
68  static Cache * fInstance;
69 
70  //! map of cache buffers & cache file
71  map<string, CacheBranchI * > * fCacheMap;
72  TFile * fCacheFile;
73 
74  //! singleton class: constructors are private
75  Cache();
76  Cache(const Cache & cache);
77  virtual ~Cache();
78 
79  //! proper de-allocation of the singleton object
80  struct Cleaner {
83  if (Cache::fInstance !=0) {
84  delete Cache::fInstance;
85  Cache::fInstance = 0;
86  }
87  }
88  };
89  friend struct Cleaner;
90 };
91 
92 } // genie namespace
93 #endif // _CACHE_H_
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
std::string string
Definition: nybbler.cc:12
void Load(void)
load/save
Definition: Cache.cxx:133
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:71
string filename
Definition: train.py:213
void RmAllCacheBranches(void)
Definition: Cache.cxx:110
void AddCacheBranch(string key, CacheBranchI *branch)
Definition: Cache.cxx:88
void DummyMethodAndSilentCompiler()
Definition: Cache.h:81
def key(type, name=None)
Definition: graph.py:13
void OpenCacheFile(string filename)
cache file
Definition: Cache.cxx:183
void Print(ostream &stream) const
print cache buffers
Definition: Cache.cxx:206
string CacheBranchKey(string k0, string k1="", string k2="") const
Definition: Cache.cxx:93
void Save(void)
Definition: Cache.cxx:155
CacheBranchI * FindCacheBranch(string key)
finding/adding cache branches
Definition: Cache.cxx:80
GENIE Cache Memory.
Definition: Cache.h:38
virtual ~Cache()
Definition: Cache.cxx:44
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
friend ostream & operator<<(ostream &stream, const Cache &cache)
Definition: Cache.cxx:29
static Cache * fInstance
singleton instance
Definition: Cache.h:68
Cache()
singleton class: constructors are private
Definition: Cache.cxx:37
TFile * fCacheFile
Definition: Cache.h:72
proper de-allocation of the singleton object
Definition: Cache.h:80
void RmMatchedCacheBranches(string key_substring)
Definition: Cache.cxx:127
static Cache * Instance(void)
Definition: Cache.cxx:67
The TObject at the root of concrete cache branches.
Definition: CacheBranchI.h:25
void RmCacheBranch(string key)
removing cache branches
Definition: Cache.cxx:104