#include <FlyWeight.h>
Public Types | |||||||
typedef int | Proxy_t | ||||||
Public Member Functions | |||||||
FlyWeight () | |||||||
FlyWeight (const ValueType &val) | |||||||
void | Reset () | ||||||
void | operator= (const ValueType &v) | ||||||
void | DumpTable () const | ||||||
Static Public Member Functions | |||||||
static void | InitProxyList () | ||||||
Private Member Functions | |||||||
ClassDef (FlyWeight, 2) | |||||||
Private Attributes | |||||||
Proxy_t | fProxy | ||||||
FlyWeight | |||||||
A generic flyweight to store relatively bulky objects that are massively re-used, such as the source IDs in each TAP / TDP. Objects such as TAPs and TDPs often contain largely repeated data such as the source ID for all pulses coming from the same algorithm applied to the same detector channel. To reduce the redundancy and therefore save memory and some processing time, this class implements a simple version of the flyweight pattern, which replaces each different value with an int, but provides a similar interface to the object that it wraps. When we want to store a new value, it is searched for in the ProxyToValueMap and the index identifying where it is is saved is used instead. If the value has not been used already, it is added to the list of values
| |||||||
static FlyWeightLists < ValueType, UniqueTag > * | fProxyList = NULL | ||||||
void | SetValue (const ValueType &) | ||||||
const ValueType & | GetValue () const | ||||||
static int | LoadProxyList (TDirectory *file, const std::string &name) | ||||||
static int | SaveProxyList (TDirectory *file, const std::string &name) |
Definition at line 55 of file FlyWeight.h.
typedef int FlyWeight< ValueType, UniqueTag >::Proxy_t |
Definition at line 57 of file FlyWeight.h.
FlyWeight< ValueType, UniqueTag >::FlyWeight | ( | ) | [inline] |
Definition at line 59 of file FlyWeight.h.
00059 :fProxy(-1){}
FlyWeight< ValueType, UniqueTag >::FlyWeight | ( | const ValueType & | val | ) | [inline] |
Definition at line 60 of file FlyWeight.h.
FlyWeight< ValueType, UniqueTag >::ClassDef | ( | FlyWeight< ValueType, UniqueTag > | , | |
2 | ||||
) | [private] |
void FlyWeight< ValueType, UniqueTag >::DumpTable | ( | ) | const [inline] |
Definition at line 70 of file FlyWeight.h.
00070 {fProxyList->DumpTable();}
const ValueType & FlyWeight< ValueType, UniqueTag >::GetValue | ( | ) | const [inline] |
Definition at line 85 of file FlyWeight.h.
References FlyWeight< ValueType, UniqueTag >::fProxy, and FlyWeight< ValueType, UniqueTag >::fProxyList.
Referenced by TDetectorPulse::GetSource(), and TAnalysedPulse::GetSource().
00085 { 00086 if(fProxy<0) std::cerr<<"Trying to get a value " 00087 "from an unitialized flyweight"<<std::endl; 00088 return fProxyList->GetValue(fProxy); 00089 }
static void FlyWeight< ValueType, UniqueTag >::InitProxyList | ( | ) | [inline, static] |
Definition at line 74 of file FlyWeight.h.
Referenced by FlyWeight< ValueType, UniqueTag >::SetValue().
00074 {fProxyList=new FlyWeightLists<ValueType,UniqueTag>();};
int FlyWeight< ValueType, UniqueTag >::LoadProxyList | ( | TDirectory * | file, | |
const std::string & | name | |||
) | [inline, static] |
Definition at line 98 of file FlyWeight.h.
References FlyWeight< ValueType, UniqueTag >::fProxyList.
00099 { 00100 if(fProxyList && !fProxyList->empty()){ 00101 std::cout<<"FlyWeight: Error: Proxy list is not empty but was asked to load the list from a file"<<std::endl; 00102 return 1; 00103 } 00104 if(!file) { 00105 std::cout<<"FlyWeight: Error: Cannot load a proxy list from a NULL file"<<std::endl; 00106 return 2; 00107 } 00108 file->GetObject(name.c_str(),fProxyList); 00109 if(!fProxyList){ 00110 std::cout<<"FlyWeight: Error: Couldn't find proxy list '"<<name 00111 <<"' in file '"<<file->GetName()<<"'"<<std::endl; 00112 return 3; 00113 } 00114 return 0; 00115 }
void FlyWeight< ValueType, UniqueTag >::operator= | ( | const ValueType & | v | ) | [inline] |
Definition at line 65 of file FlyWeight.h.
00065 { 00066 SetValue(v); 00067 }
void FlyWeight< ValueType, UniqueTag >::Reset | ( | ) | [inline] |
Definition at line 63 of file FlyWeight.h.
Referenced by TDetectorPulse::Reset().
00063 {fProxy=-1;}
int FlyWeight< ValueType, UniqueTag >::SaveProxyList | ( | TDirectory * | file, | |
const std::string & | name | |||
) | [inline, static] |
Definition at line 118 of file FlyWeight.h.
References FlyWeight< ValueType, UniqueTag >::fProxyList.
00119 { 00120 if(!file) { 00121 std::cout<<"FlyWeight: Error: Cannot save a proxy list from a NULL file"<<std::endl; 00122 return 1; 00123 } 00124 file->WriteObject(fProxyList,name.c_str()); 00125 return 0; 00126 }
void FlyWeight< ValueType, UniqueTag >::SetValue | ( | const ValueType & | v | ) | [inline] |
Definition at line 92 of file FlyWeight.h.
References FlyWeight< ValueType, UniqueTag >::fProxy, FlyWeight< ValueType, UniqueTag >::fProxyList, and FlyWeight< ValueType, UniqueTag >::InitProxyList().
Referenced by FlyWeight< IDs::source, TAnalysedPulse::Tag >::FlyWeight(), and FlyWeight< IDs::source, TAnalysedPulse::Tag >::operator=().
00092 { 00093 if(!fProxyList)InitProxyList(); 00094 fProxy=fProxyList->GetProxy(v); 00095 }
Proxy_t FlyWeight< ValueType, UniqueTag >::fProxy [private] |
Definition at line 74 of file FlyWeight.h.
Referenced by FlyWeight< ValueType, UniqueTag >::GetValue(), FlyWeight< IDs::source, TAnalysedPulse::Tag >::Reset(), and FlyWeight< ValueType, UniqueTag >::SetValue().
FlyWeightLists< ValueType, UniqueTag > * FlyWeight< ValueType, UniqueTag >::fProxyList = NULL [inline, static, private] |
Definition at line 79 of file FlyWeight.h.
Referenced by FlyWeight< IDs::source, TAnalysedPulse::Tag >::DumpTable(), FlyWeight< ValueType, UniqueTag >::GetValue(), FlyWeight< IDs::source, TAnalysedPulse::Tag >::InitProxyList(), FlyWeight< ValueType, UniqueTag >::LoadProxyList(), FlyWeight< ValueType, UniqueTag >::SaveProxyList(), and FlyWeight< ValueType, UniqueTag >::SetValue().