FlyWeight< ValueType, UniqueTag > Class Template Reference

#include <FlyWeight.h>

Inheritance diagram for FlyWeight< ValueType, UniqueTag >:
TObject

List of all members.

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

Template Parameters:
ValueType The type of value this flyweight contains
UniqueTag An optional template parameter to make sure the flyweight is unique, such as to separate the flyweight for TAPs from TDPs, even though the ValueType is the same


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)

Detailed Description

template<typename ValueType, typename UniqueTag = int>
class FlyWeight< ValueType, UniqueTag >

Definition at line 55 of file FlyWeight.h.


Member Typedef Documentation

template<typename ValueType, typename UniqueTag = int>
typedef int FlyWeight< ValueType, UniqueTag >::Proxy_t

Definition at line 57 of file FlyWeight.h.


Constructor & Destructor Documentation

template<typename ValueType, typename UniqueTag = int>
FlyWeight< ValueType, UniqueTag >::FlyWeight (  )  [inline]

Definition at line 59 of file FlyWeight.h.

00059 :fProxy(-1){}

template<typename ValueType, typename UniqueTag = int>
FlyWeight< ValueType, UniqueTag >::FlyWeight ( const ValueType &  val  )  [inline]

Definition at line 60 of file FlyWeight.h.

00060                                        :fProxy(-1){
00061             SetValue(val);
00062         }


Member Function Documentation

template<typename ValueType, typename UniqueTag = int>
FlyWeight< ValueType, UniqueTag >::ClassDef ( FlyWeight< ValueType, UniqueTag >  ,
 
) [private]
template<typename ValueType, typename UniqueTag = int>
void FlyWeight< ValueType, UniqueTag >::DumpTable (  )  const [inline]

Definition at line 70 of file FlyWeight.h.

00070 {fProxyList->DumpTable();}

template<typename ValueType , typename UniqueTag >
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 }

template<typename ValueType, typename UniqueTag = int>
static void FlyWeight< ValueType, UniqueTag >::InitProxyList (  )  [inline, static]
template<typename ValueType , typename 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 }

template<typename ValueType, typename UniqueTag = int>
void FlyWeight< ValueType, UniqueTag >::operator= ( const ValueType &  v  )  [inline]

Definition at line 65 of file FlyWeight.h.

00065                                           {
00066             SetValue(v);
00067         }

template<typename ValueType, typename UniqueTag = int>
void FlyWeight< ValueType, UniqueTag >::Reset (  )  [inline]

Definition at line 63 of file FlyWeight.h.

Referenced by TDetectorPulse::Reset().

00063 {fProxy=-1;}

template<typename ValueType , typename UniqueTag >
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 }

template<typename ValueType, typename UniqueTag >
void FlyWeight< ValueType, UniqueTag >::SetValue ( const ValueType &  v  )  [inline]

Member Data Documentation

template<typename ValueType, typename UniqueTag = int>
Proxy_t FlyWeight< ValueType, UniqueTag >::fProxy [private]
template<typename ValueType, typename UniqueTag = int>
FlyWeightLists< ValueType, UniqueTag > * FlyWeight< ValueType, UniqueTag >::fProxyList = NULL [inline, static, private]

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

Generated on 15 Jun 2016 for AlcapDAQ by  doxygen 1.6.1