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 <costas.andreopoulos \at stfc.ac.uk>
9  University of Liverpool & STFC Rutherford Appleton Lab
10 
11 \created November 26, 2004
12 
13 \cpright Copyright (c) 2003-2019, The GENIE Collaboration
14  For the full text of the license visit http://copyright.genie-mc.org
15  or see $GENIE/LICENSE
16 */
17 //____________________________________________________________________________
18 
19 #ifndef _CACHE_H_
20 #define _CACHE_H_
21 
22 #include <map>
23 #include <string>
24 #include <ostream>
25 
26 #include <TFile.h>
27 
28 using std::map;
29 using std::string;
30 using std::ostream;
31 
32 namespace genie {
33 
34 class Cache;
35 class CacheBranchI;
36 
37 ostream & operator << (ostream & stream, const Cache & cache);
38 
39 class Cache
40 {
41 public:
42 
43  static Cache * Instance(void);
44 
45  //! cache file
46  void OpenCacheFile (string filename);
47 
48  //! finding/adding cache branches
49  CacheBranchI * FindCacheBranch (string key);
50  void AddCacheBranch (string key, CacheBranchI * branch);
51  string CacheBranchKey (string k0, string k1="", string k2="") const;
52 
53  //! removing cache branches
54  void RmCacheBranch (string key);
55  void RmAllCacheBranches (void);
56  void RmMatchedCacheBranches(string key_substring);
57 
58  //! print cache buffers
59  void Print (ostream & stream) const;
60  friend ostream & operator << (ostream & stream, const Cache & cache);
61 
62 private:
63 
64  //! load/save
65  void Load (void);
66  void Save (void);
67 
68  //! singleton instance
69  static Cache * fInstance;
70 
71  //! map of cache buffers & cache file
72  map<string, CacheBranchI * > * fCacheMap;
73  TFile * fCacheFile;
74 
75  //! singleton class: constructors are private
76  Cache();
77  Cache(const Cache & cache);
78  virtual ~Cache();
79 
80  //! proper de-allocation of the singleton object
81  struct Cleaner {
84  if (Cache::fInstance !=0) {
85  delete Cache::fInstance;
86  Cache::fInstance = 0;
87  }
88  }
89  };
90  friend struct Cleaner;
91 };
92 
93 } // genie namespace
94 #endif // _CACHE_H_
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
void Load(void)
load/save
Definition: Cache.cxx:142
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:72
string filename
Definition: shutoffs.py:106
void RmAllCacheBranches(void)
Definition: Cache.cxx:119
void AddCacheBranch(string key, CacheBranchI *branch)
Definition: Cache.cxx:97
void DummyMethodAndSilentCompiler()
Definition: Cache.h:82
void OpenCacheFile(string filename)
cache file
Definition: Cache.cxx:192
void Print(ostream &stream) const
print cache buffers
Definition: Cache.cxx:215
string CacheBranchKey(string k0, string k1="", string k2="") const
Definition: Cache.cxx:102
void Save(void)
Definition: Cache.cxx:164
CacheBranchI * FindCacheBranch(string key)
finding/adding cache branches
Definition: Cache.cxx:89
GENIE Cache Memory.
Definition: Cache.h:39
virtual ~Cache()
Definition: Cache.cxx:53
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
friend ostream & operator<<(ostream &stream, const Cache &cache)
Definition: Cache.cxx:38
static Cache * fInstance
singleton instance
Definition: Cache.h:69
Cache()
singleton class: constructors are private
Definition: Cache.cxx:46
TFile * fCacheFile
Definition: Cache.h:73
proper de-allocation of the singleton object
Definition: Cache.h:81
void RmMatchedCacheBranches(string key_substring)
Definition: Cache.cxx:136
static Cache * Instance(void)
Definition: Cache.cxx:76
The TObject at the root of concrete cache branches.
Definition: CacheBranchI.h:26
void RmCacheBranch(string key)
removing cache branches
Definition: Cache.cxx:113
enum BeamMode string