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 "/cvmfs/nova.opensciencegrid.org/externals/genie/v3_00_06_p01/Linux64bit+2.6-2.12-e17-debug/GENIE-Generator/src/Framework/Utils/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 <costas.andreopoulos stfc.ac.uk> University of Liverpool & STFC Rutherford Appleton Lab

November 26, 2004

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

Definition at line 39 of file Cache.h.

Constructor & Destructor Documentation

genie::Cache::Cache ( )
private

singleton class: constructors are private

Definition at line 46 of file Cache.cxx.

References fCacheFile, fCacheMap, and fInstance.

Referenced by Instance().

47 {
48  fInstance = 0;
49  fCacheMap = 0;
50  fCacheFile = 0;
51 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:72
static Cache * fInstance
singleton instance
Definition: Cache.h:69
TFile * fCacheFile
Definition: Cache.h:73
genie::Cache::Cache ( const Cache cache)
private
genie::Cache::~Cache ( )
privatevirtual

Definition at line 53 of file Cache.cxx.

References compare_h5_caf::branch, fCacheFile, fCacheMap, fInstance, and Save().

54 {
55  this->Save();
56 
57  if(fCacheMap) {
58  map<string, CacheBranchI * >::iterator citer;
59  for(citer = fCacheMap->begin(); citer != fCacheMap->end(); ++citer) {
60  CacheBranchI * branch = citer->second;
61  if(branch) {
62  delete branch;
63  branch = 0;
64  }
65  }
66  fCacheMap->clear();
67  delete fCacheMap;
68  }
69  if(fCacheFile) {
70  fCacheFile->Close();
71  delete fCacheFile;
72  }
73  fInstance = 0;
74 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:72
void Save(void)
Definition: Cache.cxx:164
static Cache * fInstance
singleton instance
Definition: Cache.h:69
TFile * fCacheFile
Definition: Cache.h:73

Member Function Documentation

void genie::Cache::AddCacheBranch ( string  key,
CacheBranchI branch 
)
string genie::Cache::CacheBranchKey ( string  k0,
string  k1 = "",
string  k2 = "" 
) const
CacheBranchI * genie::Cache::FindCacheBranch ( string  key)
Cache * genie::Cache::Instance ( void  )
static

Definition at line 76 of file Cache.cxx.

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

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

77 {
78  if(fInstance == 0) {
79  static Cache::Cleaner cleaner;
80  cleaner.DummyMethodAndSilentCompiler();
81 
82  fInstance = new Cache;
83 
84  fInstance->fCacheMap = new map<string, CacheBranchI * >;
85  }
86  return fInstance;
87 }
friend struct Cleaner
Definition: Cache.h:90
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:72
static Cache * fInstance
singleton instance
Definition: Cache.h:69
Cache()
singleton class: constructors are private
Definition: Cache.cxx:46
void genie::Cache::Load ( void  )
private

load/save

Definition at line 142 of file Cache.cxx.

References fCacheFile, fCacheMap, findDuplicateFiles::key, caf_analysis::keys, LOG, pNOTICE, and string.

Referenced by OpenCacheFile().

143 {
144  LOG("Cache", pNOTICE) << "Loading cache";
145 
146  if(!fCacheFile) return;
147  TList * keys = (TList*) fCacheFile->Get("key_list");
148  TIter kiter(keys);
149  TObjString * keyobj = 0;
150  int ib=0;
151  while ((keyobj = (TObjString *)kiter.Next())) {
152  string key = string(keyobj->GetString().Data());
153  ostringstream bname;
154  bname << "buffer_" << ib++;
155  CacheBranchI * buffer = (CacheBranchI*) fCacheFile->Get(bname.str().c_str());
156  if(buffer) {
157  fCacheMap->insert( map<string, CacheBranchI *>::value_type(key,buffer) );
158  }
159  }
160  LOG("Cache", pNOTICE) << "Cache loaded...";
161  LOG("Cache", pNOTICE) << *this;
162 }
keys
Reco plots.
Definition: caf_analysis.py:46
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:72
::xsd::cxx::tree::buffer< char > buffer
Definition: Database.h:179
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
TFile * fCacheFile
Definition: Cache.h:73
#define pNOTICE
Definition: Messenger.h:62
enum BeamMode string
void genie::Cache::OpenCacheFile ( string  filename)

cache file

Definition at line 192 of file Cache.cxx.

References fCacheFile, shutoffs::filename, Load(), LOG, pNOTICE, and pWARN.

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

193 {
194  if(filename.size() == 0) return;
195 
196  if(fCacheFile) {
197  if(fCacheFile->IsOpen()) {
198  delete fCacheFile;
199  fCacheFile = 0;
200  }
201  }
202 
203  LOG("Cache", pNOTICE) << "Using cache file: " << filename;
204 
205  fCacheFile = new TFile(filename.c_str(),"update");
206  if(!fCacheFile->IsOpen()) {
207  delete fCacheFile;
208  fCacheFile = 0;
209  LOG("Cache", pWARN) << "Could not open cache file: " << filename;
210  }
211 
212  this->Load();
213 }
void Load(void)
load/save
Definition: Cache.cxx:142
string filename
Definition: shutoffs.py:106
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
#define pWARN
Definition: Messenger.h:61
TFile * fCacheFile
Definition: Cache.h:73
#define pNOTICE
Definition: Messenger.h:62
void genie::Cache::Print ( ostream &  stream) const

print cache buffers

Definition at line 215 of file Cache.cxx.

References compare_h5_caf::branch, fCacheMap, and findDuplicateFiles::key.

Referenced by genie::operator<<().

216 {
217  stream << "\n [-] GENIE Cache Buffers:";
218  stream << "\n |";
219  map<string, CacheBranchI * >::iterator citer;
220  for(citer = fCacheMap->begin(); citer != fCacheMap->end(); ++citer) {
221  string key = citer->first;
222  CacheBranchI * branch = citer->second;
223  stream << "\n |--o " << key;
224  if(!branch) {
225  stream << " *** NULL *** ";
226  }
227  }
228  stream << "\n";
229 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:72
void genie::Cache::RmAllCacheBranches ( void  )

Definition at line 119 of file Cache.cxx.

References compare_h5_caf::branch, fCacheMap, LOG, and pNOTICE.

120 {
121  LOG("Cache", pNOTICE) << "Removing cache branches";
122 
123  if(fCacheMap) {
124  map<string, CacheBranchI * >::iterator citer;
125  for(citer = fCacheMap->begin(); citer != fCacheMap->end(); ++citer) {
126  CacheBranchI * branch = citer->second;
127  if(branch) {
128  delete branch;
129  branch = 0;
130  }
131  }
132  fCacheMap->clear();
133  }
134 }
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:72
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
#define pNOTICE
Definition: Messenger.h:62
void genie::Cache::RmCacheBranch ( string  key)

removing cache branches

Definition at line 113 of file Cache.cxx.

References findDuplicateFiles::key, LOG, and pNOTICE.

114 {
115  LOG("Cache", pNOTICE) << "Removing cache branch: " << key;
116 
117 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
#define pNOTICE
Definition: Messenger.h:62
void genie::Cache::RmMatchedCacheBranches ( string  key_substring)

Definition at line 136 of file Cache.cxx.

References LOG, and pNOTICE.

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

137 {
138  LOG("Cache", pNOTICE) << "Removing cache branches: *"<< key_substring<< "*";
139 
140 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
#define pNOTICE
Definition: Messenger.h:62
void genie::Cache::Save ( void  )
private

Definition at line 164 of file Cache.cxx.

References compare_h5_caf::branch, fCacheFile, fCacheMap, findDuplicateFiles::key, and caf_analysis::keys.

Referenced by ~Cache().

165 {
166  if(!fCacheFile) {
167  return;
168  }
169  fCacheFile->cd();
170 
171  int ib=0;
172  TList * keys = new TList;
173  keys->SetOwner(true);
174 
175  map<string, CacheBranchI * >::iterator citer;
176  for(citer = fCacheMap->begin(); citer != fCacheMap->end(); ++citer) {
177  string key = citer->first;
178  CacheBranchI * branch = citer->second;
179  if(branch) {
180  ostringstream bname;
181  bname << "buffer_" << ib++;
182  keys->Add(new TObjString(key.c_str()));
183  branch->Write(bname.str().c_str(), TObject::kOverwrite);
184  }
185  }
186  keys->Write("key_list", TObject::kSingleKey | TObject::kOverwrite );
187 
188  keys->Clear();
189  delete keys;
190 }
keys
Reco plots.
Definition: caf_analysis.py:46
map< string, CacheBranchI * > * fCacheMap
map of cache buffers & cache file
Definition: Cache.h:72
TFile * fCacheFile
Definition: Cache.h:73

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 90 of file Cache.h.

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

Definition at line 38 of file Cache.cxx.

39 {
40  cache.Print(stream);
41  return stream;
42 }

Member Data Documentation

TFile* genie::Cache::fCacheFile
private

Definition at line 73 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 72 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 69 of file Cache.h.

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


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