GENIEGenerator
Loading...
Searching...
No Matches
genie::Cache Class Reference

GENIE Cache Memory. More...

#include <Cache.h>

Collaboration diagram for genie::Cache:
[legend]

Classes

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

Public Member Functions

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

Static Public Member Functions

static CacheInstance (void)

Private Member Functions

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

Private Attributes

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

Static Private Attributes

static CachefInstance = 0
 singleton instance

Friends

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

Detailed Description

GENIE Cache Memory.

Author
Costas Andreopoulos <c.andreopoulos \at cern.ch> University of Liverpool
Created:\n November 26, 2004
License:\n Copyright (c) 2003-2025, 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

◆ Cache() [1/2]

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}
static Cache * fInstance
singleton instance
Definition Cache.h:68
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition Cache.h:71
TFile * fCacheFile
Definition Cache.h:72

References fCacheFile, fCacheMap, and fInstance.

Referenced by Cache(), Instance(), and operator<<.

◆ Cache() [2/2]

genie::Cache::Cache ( const Cache & cache)
private

References Cache().

◆ ~Cache()

genie::Cache::~Cache ( )
privatevirtual

Definition at line 44 of file Cache.cxx.

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}
void Save(void)
Definition Cache.cxx:155

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

Member Function Documentation

◆ AddCacheBranch()

◆ CacheBranchKey()

string genie::Cache::CacheBranchKey ( string k0,
string k1 = "",
string k2 = "" ) const

◆ FindCacheBranch()

◆ Instance()

◆ Load()

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}
#define pNOTICE
Definition Messenger.h:61
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96

References fCacheFile, fCacheMap, LOG, and pNOTICE.

Referenced by OpenCacheFile().

◆ OpenCacheFile()

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}
#define pWARN
Definition Messenger.h:60
void Load(void)
load/save
Definition Cache.cxx:133

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

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

◆ Print()

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 |";
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}

References fCacheMap.

Referenced by operator<<.

◆ RmAllCacheBranches()

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) {
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}

References fCacheMap, LOG, and pNOTICE.

◆ RmCacheBranch()

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}

References LOG, and pNOTICE.

◆ RmMatchedCacheBranches()

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}

References LOG, and pNOTICE.

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

◆ Save()

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
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}

References fCacheFile, and fCacheMap.

Referenced by ~Cache().

◆ Cleaner

friend struct Cleaner
friend

Definition at line 89 of file Cache.h.

◆ operator<<

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}

References Cache(), and Print().

Member Data Documentation

◆ fCacheFile

TFile* genie::Cache::fCacheFile
private

Definition at line 72 of file Cache.h.

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

◆ fCacheMap

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(), Load(), Print(), RmAllCacheBranches(), Save(), and ~Cache().

◆ fInstance

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: