GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>

Collaboration diagram for genie::Cache:
Collaboration graph
[legend]

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 <c.andreopoulos cern.ch> University of Liverpool
Created:
November 26, 2004
License:
Copyright (c) 2003-2024, 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.

References fCacheFile, fCacheMap, and fInstance.

Referenced by Instance().

38 {
39  fInstance = 0;
40  fCacheMap = 0;
41  fCacheFile = 0;
42 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers &amp; 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.

References fCacheFile, fCacheMap, fInstance, and Save().

45 {
46  this->Save();
47 
48  if(fCacheMap) {
49  map<string, CacheBranchI * >::iterator citer;
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 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers &amp; 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 
)
string genie::Cache::CacheBranchKey ( string  k0,
string  k1 = "",
string  k2 = "" 
) const

Definition at line 93 of file Cache.cxx.

Referenced by genie::KineGeneratorWithCache::AccessCacheBranch(), genie::ReinSehgalRESXSecWithCache::CacheBranchName(), genie::DISXSec::CacheBranchName(), genie::DMDISXSec::CacheBranchName(), genie::SPPXSecWithCache::CacheBranchName(), genie::ReinSehgalRESXSecWithCacheFast::CacheBranchName(), and genie::KNOTunedQPMDISPXSec::DISRESJoinSuppressionFactor().

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 }
CacheBranchI * genie::Cache::FindCacheBranch ( string  key)
Cache * genie::Cache::Instance ( void  )
static

Definition at line 67 of file Cache.cxx.

References Cache(), genie::Cache::Cleaner::DummyMethodAndSilentCompiler(), fCacheMap, and fInstance.

Referenced by genie::KineGeneratorWithCache::AccessCacheBranch(), genie::DISXSec::CacheBranchName(), genie::ReinSehgalRESXSecWithCache::CacheBranchName(), genie::DMDISXSec::CacheBranchName(), genie::ReinSehgalRESXSecWithCacheFast::CacheBranchName(), genie::SPPXSecWithCache::CacheBranchName(), genie::utils::app_init::CacheFile(), genie::DISXSec::CacheFreeNucleonXSec(), genie::DMDISXSec::CacheFreeNucleonXSec(), genie::ReinSehgalRESXSecWithCache::CacheResExcitationXSec(), genie::ReinSehgalRESXSecWithCacheFast::CacheResExcitationXSec(), genie::SPPXSecWithCache::CacheResExcitationXSec(), genie::KNOTunedQPMDISPXSec::DISRESJoinSuppressionFactor(), genie::DISXSec::Integrate(), genie::DMDISXSec::Integrate(), genie::SPPXSec::Integrate(), genie::ReinSehgalRESXSec::Integrate(), genie::ReinSehgalSPPXSec::Integrate(), genie::ReinSehgalRESXSecFast::Integrate(), genie::QPMDISPXSec::LoadConfig(), and genie::QPMDMDISPXSec::LoadConfig().

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 &amp; 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.

References fCacheFile, fCacheMap, LOG, and pNOTICE.

Referenced by OpenCacheFile().

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 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers &amp; 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
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.

References fCacheFile, Load(), LOG, pNOTICE, and pWARN.

Referenced by genie::utils::app_init::CacheFile().

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
#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.

References fCacheMap.

Referenced by genie::operator<<().

207 {
208  stream << "\n [-] GENIE Cache Buffers:";
209  stream << "\n |";
210  map<string, CacheBranchI * >::iterator citer;
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 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers &amp; cache file
Definition: Cache.h:71
void genie::Cache::RmAllCacheBranches ( void  )

Definition at line 110 of file Cache.cxx.

References fCacheMap, LOG, and pNOTICE.

111 {
112  LOG("Cache", pNOTICE) << "Removing cache branches";
113 
114  if(fCacheMap) {
115  map<string, CacheBranchI * >::iterator citer;
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 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers &amp; 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.

References LOG, and pNOTICE.

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
#define pNOTICE
Definition: Messenger.h:61
void genie::Cache::RmMatchedCacheBranches ( string  key_substring)

Definition at line 127 of file Cache.cxx.

References LOG, and pNOTICE.

Referenced by genie::QPMDISPXSec::LoadConfig(), and genie::QPMDMDISPXSec::LoadConfig().

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.

References fCacheFile, and fCacheMap.

Referenced by ~Cache().

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 
166  map<string, CacheBranchI * >::iterator citer;
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 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers &amp; cache file
Definition: Cache.h:71
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.

Referenced by Cache(), Load(), OpenCacheFile(), Save(), and ~Cache().

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

map of cache buffers & cache file

Definition at line 71 of file Cache.h.

Referenced by AddCacheBranch(), Cache(), FindCacheBranch(), Instance(), Load(), Print(), RmAllCacheBranches(), Save(), and ~Cache().

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

singleton instance

Definition at line 68 of file Cache.h.

Referenced by Cache(), Instance(), ~Cache(), and genie::Cache::Cleaner::~Cleaner().


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