Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
genie::Cache Class Reference

GENIE Cache Memory. More...

#include <Cache.h>

Classes

struct  Cleaner
 proper de-allocation of the singleton object More...
 

Public Member Functions

void OpenCacheFile (string filename)
 cache file More...
 
CacheBranchIFindCacheBranch (string key)
 finding/adding cache branches More...
 
void AddCacheBranch (string key, CacheBranchI *branch)
 
string CacheBranchKey (string k0, string k1="", string k2="") const
 
void RmCacheBranch (string key)
 removing cache branches More...
 
void RmAllCacheBranches (void)
 
void RmMatchedCacheBranches (string key_substring)
 
void Print (ostream &stream) const
 print cache buffers More...
 

Static Public Member Functions

static CacheInstance (void)
 

Private Member Functions

void Load (void)
 load/save More...
 
void Save (void)
 
 Cache ()
 singleton class: constructors are private More...
 
 Cache (const Cache &cache)
 
virtual ~Cache ()
 

Private Attributes

map< string, CacheBranchI * > * fCacheMap
 map of cache buffers & cache file More...
 
TFile * fCacheFile
 

Static Private Attributes

static CachefInstance = 0
 singleton instance More...
 

Friends

struct Cleaner
 
ostream & operator<< (ostream &stream, const Cache &cache)
 

Detailed Description

GENIE Cache Memory.

Author
Costas Andreopoulos <constantinos.andreopoulos cern.ch> University of Liverpool & STFC Rutherford Appleton Laboratory

November 26, 2004

Copyright (c) 2003-2020, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 38 of file Cache.h.

Constructor & Destructor Documentation

genie::Cache::Cache ( )
private

singleton class: constructors are private

Definition at line 37 of file Cache.cxx.

38 {
39  fInstance = 0;
40  fCacheMap = 0;
41  fCacheFile = 0;
42 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:71
static Cache * fInstance
singleton instance
Definition: Cache.h:68
TFile * fCacheFile
Definition: Cache.h:72
genie::Cache::Cache ( const Cache cache)
private
genie::Cache::~Cache ( )
privatevirtual

Definition at line 44 of file Cache.cxx.

45 {
46  this->Save();
47 
48  if(fCacheMap) {
50  for(citer = fCacheMap->begin(); citer != fCacheMap->end(); ++citer) {
51  CacheBranchI * branch = citer->second;
52  if(branch) {
53  delete branch;
54  branch = 0;
55  }
56  }
57  fCacheMap->clear();
58  delete fCacheMap;
59  }
60  if(fCacheFile) {
61  fCacheFile->Close();
62  delete fCacheFile;
63  }
64  fInstance = 0;
65 }
intermediate_table::iterator iterator
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:71
void Save(void)
Definition: Cache.cxx:155
static Cache * fInstance
singleton instance
Definition: Cache.h:68
TFile * fCacheFile
Definition: Cache.h:72

Member Function Documentation

void genie::Cache::AddCacheBranch ( string  key,
CacheBranchI branch 
)

Definition at line 88 of file Cache.cxx.

89 {
90  fCacheMap->insert( map<string, CacheBranchI *>::value_type(key,branch) );
91 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:71
def key(type, name=None)
Definition: graph.py:13
string genie::Cache::CacheBranchKey ( string  k0,
string  k1 = "",
string  k2 = "" 
) const

Definition at line 93 of file Cache.cxx.

94 {
95  ostringstream key;
96 
97  key << k0;
98  if(k1.size()>0) key << "/" << k1;
99  if(k2.size()>0) key << "/" << k2;
100 
101  return key.str();
102 }
def key(type, name=None)
Definition: graph.py:13
CacheBranchI * genie::Cache::FindCacheBranch ( string  key)

finding/adding cache branches

Definition at line 80 of file Cache.cxx.

81 {
83 
84  if (map_iter == fCacheMap->end()) return 0;
85  return map_iter->second;
86 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:71
intermediate_table::const_iterator const_iterator
def key(type, name=None)
Definition: graph.py:13
Cache * genie::Cache::Instance ( void  )
static

Definition at line 67 of file Cache.cxx.

68 {
69  if(fInstance == 0) {
70  static Cache::Cleaner cleaner;
71  cleaner.DummyMethodAndSilentCompiler();
72 
73  fInstance = new Cache;
74 
75  fInstance->fCacheMap = new map<string, CacheBranchI * >;
76  }
77  return fInstance;
78 }
friend struct Cleaner
Definition: Cache.h:89
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:71
static Cache * fInstance
singleton instance
Definition: Cache.h:68
Cache()
singleton class: constructors are private
Definition: Cache.cxx:37
void genie::Cache::Load ( void  )
private

load/save

Definition at line 133 of file Cache.cxx.

134 {
135  LOG("Cache", pNOTICE) << "Loading cache";
136 
137  if(!fCacheFile) return;
138  TList * keys = (TList*) fCacheFile->Get("key_list");
139  TIter kiter(keys);
140  TObjString * keyobj = 0;
141  int ib=0;
142  while ((keyobj = (TObjString *)kiter.Next())) {
143  string key = string(keyobj->GetString().Data());
144  ostringstream bname;
145  bname << "buffer_" << ib++;
146  CacheBranchI * buffer = (CacheBranchI*) fCacheFile->Get(bname.str().c_str());
147  if(buffer) {
148  fCacheMap->insert( map<string, CacheBranchI *>::value_type(key,buffer) );
149  }
150  }
151  LOG("Cache", pNOTICE) << "Cache loaded...";
152  LOG("Cache", pNOTICE) << *this;
153 }
std::string string
Definition: nybbler.cc:12
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:71
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
def key(type, name=None)
Definition: graph.py:13
TFile * fCacheFile
Definition: Cache.h:72
#define pNOTICE
Definition: Messenger.h:61
void genie::Cache::OpenCacheFile ( string  filename)

cache file

Definition at line 183 of file Cache.cxx.

184 {
185  if(filename.size() == 0) return;
186 
187  if(fCacheFile) {
188  if(fCacheFile->IsOpen()) {
189  delete fCacheFile;
190  fCacheFile = 0;
191  }
192  }
193 
194  LOG("Cache", pNOTICE) << "Using cache file: " << filename;
195 
196  fCacheFile = new TFile(filename.c_str(),"update");
197  if(!fCacheFile->IsOpen()) {
198  delete fCacheFile;
199  fCacheFile = 0;
200  LOG("Cache", pWARN) << "Could not open cache file: " << filename;
201  }
202 
203  this->Load();
204 }
void Load(void)
load/save
Definition: Cache.cxx:133
string filename
Definition: train.py:213
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
TFile * fCacheFile
Definition: Cache.h:72
#define pNOTICE
Definition: Messenger.h:61
void genie::Cache::Print ( ostream &  stream) const

print cache buffers

Definition at line 206 of file Cache.cxx.

207 {
208  stream << "\n [-] GENIE Cache Buffers:";
209  stream << "\n |";
211  for(citer = fCacheMap->begin(); citer != fCacheMap->end(); ++citer) {
212  string key = citer->first;
213  CacheBranchI * branch = citer->second;
214  stream << "\n |--o " << key;
215  if(!branch) {
216  stream << " *** NULL *** ";
217  }
218  }
219  stream << "\n";
220 }
intermediate_table::iterator iterator
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:71
def key(type, name=None)
Definition: graph.py:13
void genie::Cache::RmAllCacheBranches ( void  )

Definition at line 110 of file Cache.cxx.

111 {
112  LOG("Cache", pNOTICE) << "Removing cache branches";
113 
114  if(fCacheMap) {
116  for(citer = fCacheMap->begin(); citer != fCacheMap->end(); ++citer) {
117  CacheBranchI * branch = citer->second;
118  if(branch) {
119  delete branch;
120  branch = 0;
121  }
122  }
123  fCacheMap->clear();
124  }
125 }
intermediate_table::iterator iterator
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:71
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pNOTICE
Definition: Messenger.h:61
void genie::Cache::RmCacheBranch ( string  key)

removing cache branches

Definition at line 104 of file Cache.cxx.

105 {
106  LOG("Cache", pNOTICE) << "Removing cache branch: " << key;
107 
108 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
def key(type, name=None)
Definition: graph.py:13
#define pNOTICE
Definition: Messenger.h:61
void genie::Cache::RmMatchedCacheBranches ( string  key_substring)

Definition at line 127 of file Cache.cxx.

128 {
129  LOG("Cache", pNOTICE) << "Removing cache branches: *"<< key_substring<< "*";
130 
131 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pNOTICE
Definition: Messenger.h:61
void genie::Cache::Save ( void  )
private

Definition at line 155 of file Cache.cxx.

156 {
157  if(!fCacheFile) {
158  return;
159  }
160  fCacheFile->cd();
161 
162  int ib=0;
163  TList * keys = new TList;
164  keys->SetOwner(true);
165 
167  for(citer = fCacheMap->begin(); citer != fCacheMap->end(); ++citer) {
168  string key = citer->first;
169  CacheBranchI * branch = citer->second;
170  if(branch) {
171  ostringstream bname;
172  bname << "buffer_" << ib++;
173  keys->Add(new TObjString(key.c_str()));
174  branch->Write(bname.str().c_str(), TObject::kOverwrite);
175  }
176  }
177  keys->Write("key_list", TObject::kSingleKey | TObject::kOverwrite );
178 
179  keys->Clear();
180  delete keys;
181 }
intermediate_table::iterator iterator
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:71
def key(type, name=None)
Definition: graph.py:13
TFile * fCacheFile
Definition: Cache.h:72

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 89 of file Cache.h.

ostream& operator<< ( ostream &  stream,
const Cache cache 
)
friend

Definition at line 29 of file Cache.cxx.

30 {
31  cache.Print(stream);
32  return stream;
33 }

Member Data Documentation

TFile* genie::Cache::fCacheFile
private

Definition at line 72 of file Cache.h.

map<string, CacheBranchI * >* genie::Cache::fCacheMap
private

map of cache buffers & cache file

Definition at line 71 of file Cache.h.

Cache * genie::Cache::fInstance = 0
staticprivate

singleton instance

Definition at line 68 of file Cache.h.


The documentation for this class was generated from the following files: