RecArrayAllocator Class Reference

#include <RecArrayAllocator.h>

List of all members.

Public Types

typedef std::map< TClonesArray *,
bool >::iterator 
ArrayMapItr
typedef std::map< TClonesArray *,
bool >::const_iterator 
ArrayMapConstItr

Public Member Functions

UInt_t GetNumArray () const
std::ostream & Print (std::ostream &s) const
TClonesArray * GetArray (const char *className)
void ReleaseArray (TClonesArray *array)

Static Public Member Functions

static RecArrayAllocatorInstance ()

Protected Member Functions

 RecArrayAllocator ()
virtual ~RecArrayAllocator ()

Private Member Functions

 RecArrayAllocator (RecArrayAllocator &rlm)
RecArrayAllocatoroperator= (const RecArrayAllocator &rlm)

Private Attributes

std::map< TClonesArray *,
bool > 
fArrayMap

Static Private Attributes

static RecArrayAllocatorfgInstance = 0

Friends

struct Cleaner

Classes

struct  Cleaner


Detailed Description

Definition at line 45 of file RecArrayAllocator.h.


Member Typedef Documentation

typedef std::map<TClonesArray*,bool>::const_iterator RecArrayAllocator::ArrayMapConstItr

Definition at line 51 of file RecArrayAllocator.h.

typedef std::map<TClonesArray*,bool>::iterator RecArrayAllocator::ArrayMapItr

Definition at line 50 of file RecArrayAllocator.h.


Constructor & Destructor Documentation

RecArrayAllocator::RecArrayAllocator (  )  [protected]

Definition at line 162 of file RecArrayAllocator.cxx.

Referenced by Instance().

00162                                       {
00163   // Purpose: Default constructor.
00164   //
00165   // Arguments: none.
00166   //
00167   // Return: n/a.
00168   //
00169   // Contact:  S. Kasahara
00170   //
00171   // Notes: Not called directly, use RecArrayAllocator::Instance() instead.
00172 
00173 }

RecArrayAllocator::~RecArrayAllocator (  )  [protected, virtual]

Definition at line 175 of file RecArrayAllocator.cxx.

References EVD::Clear(), fArrayMap, Msg::kDebug, Msg::kWarning, and MSG.

00175                                       {
00176   //  Purpose:  Destructor.
00177   //
00178   //  Arguments: none.
00179   //
00180   //  Return:  none.
00181   //
00182   //  Contact:   S. Kasahara
00183   //
00184   
00185   // Close all managed arrays and retrieve allocated memory
00186   MSG("Rec",Msg::kDebug) << "RecArrayAllocator destructor for addr " 
00187                          << this << endl;
00188   
00189   for( ArrayMapItr itr = fArrayMap.begin(); itr != fArrayMap.end(); itr++ ) {
00190     TClonesArray* array = itr -> first;
00191     if ( array ) {
00192       if ( !(itr->second) ) {
00193         MSG("Rec",Msg::kWarning) << "RecArrayAllocator dtor deleting array "
00194                                  << array->GetClass()->GetName() 
00195                                  << " which has not been released!" << endl;
00196       }
00197       else {
00198         MSG("Rec",Msg::kDebug) << "Clearing and Deleting array of type " 
00199                                << array->GetClass()->GetName() << endl;
00200       }
00201       array -> Clear("C");
00202       delete array; array = 0;
00203     }
00204     fArrayMap.erase(itr);
00205   }
00206   
00207 }

RecArrayAllocator::RecArrayAllocator ( RecArrayAllocator rlm  )  [private]


Member Function Documentation

TClonesArray * RecArrayAllocator::GetArray ( const char *  className  ) 

Definition at line 42 of file RecArrayAllocator.cxx.

References Msg::kVerbose, and MSG.

Referenced by UberRecordLite::Init(), UberRecord::Init(), NtpTHRecord::Init(), NtpStRecord::Init(), NtpSRRecord::Init(), NtpMRRecord::Init(), NtpMCRecord::Init(), NtpFitSARecord::Init(), NtpEMRecord::Init(), NtpCluster3DRecord::Init(), NtpCandRecord::Init(), NtpAlignmentRecord::Init(), DemoNtupleRecord::Init(), CandRecordSRNtuple::Init(), and RecValidate::TestArrayAllocator().

00042                                                                {
00043   //  Purpose:  Return TClonesArray of requested type, creating it if
00044   //            necessary.
00045   //
00046   //  Arguments: none.
00047   //
00048   //  Return:  ptr to non-const TClonesArray.
00049   //
00050   //  Contact:   S. Kasahara
00051   //
00052 
00053   for ( ArrayMapItr itr = fArrayMap.begin(); itr != fArrayMap.end(); itr++ ) {
00054     if ( itr->second ) {
00055       // Array is free, check type
00056       TClonesArray* array = itr->first;
00057       if ( !strcmp(array->GetClass()->GetName(),className) ) {
00058         itr->second = false;
00059         MSG("Rec",Msg::kVerbose) 
00060         << "GetArray retrieved existing TClonesArray of type " << className
00061         << endl;
00062         return array;
00063       }
00064     }
00065   } 
00066 
00067   // No existing TClonesArray is available for use, create one here
00068   TClonesArray* array = new TClonesArray(className);
00069   fArrayMap.insert(std::make_pair(array,false));
00070   MSG("Rec",Msg::kVerbose) 
00071     << "GetArray created new TClonesArray to support type " << className
00072     << endl;
00073   return array;
00074    
00075 }

UInt_t RecArrayAllocator::GetNumArray (  )  const [inline]

Definition at line 54 of file RecArrayAllocator.h.

References fArrayMap.

Referenced by RecValidate::TestArrayAllocator().

00054 { return fArrayMap.size(); }

RecArrayAllocator & RecArrayAllocator::Instance (  )  [static]

Definition at line 77 of file RecArrayAllocator.cxx.

References fgInstance, Msg::kDebug, MSG, RecArrayAllocator(), and RecArrayAllocator::Cleaner::UseMe().

Referenced by GfxDigitList::GfxDigitList(), GfxMCVecList::GfxMCVecList(), GfxShowerList::GfxShowerList(), GfxStripList::GfxStripList(), GfxTrackList::GfxTrackList(), UberRecordLite::Init(), UberRecord::Init(), NtpTHRecord::Init(), NtpStRecord::Init(), NtpSRRecord::Init(), NtpMRRecord::Init(), NtpMCRecord::Init(), NtpFitSARecord::Init(), NtpEMRecord::Init(), NtpCluster3DRecord::Init(), NtpCandRecord::Init(), NtpAlignmentRecord::Init(), DemoNtupleRecord::Init(), CandRecordSRNtuple::Init(), RecValidate::TestArrayAllocator(), DemoNtupleRecord::~DemoNtupleRecord(), GfxDigitList::~GfxDigitList(), GfxMCVecList::~GfxMCVecList(), GfxShowerList::~GfxShowerList(), GfxStripList::~GfxStripList(), GfxTrackList::~GfxTrackList(), NtpAlignmentRecord::~NtpAlignmentRecord(), NtpCandRecord::~NtpCandRecord(), NtpCluster3DRecord::~NtpCluster3DRecord(), NtpEMRecord::~NtpEMRecord(), NtpFitSARecord::~NtpFitSARecord(), NtpMCRecord::~NtpMCRecord(), NtpMRRecord::~NtpMRRecord(), NtpSRRecord::~NtpSRRecord(), NtpStRecord::~NtpStRecord(), NtpTHRecord::~NtpTHRecord(), UberRecord::~UberRecord(), and UberRecordLite::~UberRecordLite().

00077                                                {
00078   //  Purpose:  Return unique instance of RecArrayAllocator, creating it
00079   //            if necessary.
00080   //
00081   //  Arguments: none.
00082   //
00083   //  Return:  reference to RecArrayAllocator.
00084   //
00085   //  Contact:   S. Kasahara
00086   //
00087 
00088   static Cleaner cleaner; // Cleaner destructor provides cleanup of singleton
00089   if ( fgInstance == 0 ) {
00090     cleaner.UseMe(); // dummy call to quiet compiler warnings
00091     fgInstance = new RecArrayAllocator();
00092     MSG("Rec",Msg::kDebug) << "Constructed RecArrayAllocator instance "
00093                            << fgInstance << endl;
00094   }
00095   return *fgInstance;
00096 
00097 }

RecArrayAllocator& RecArrayAllocator::operator= ( const RecArrayAllocator rlm  )  [private]

std::ostream & RecArrayAllocator::Print ( std::ostream &  s  )  const

Definition at line 131 of file RecArrayAllocator.cxx.

References fArrayMap.

Referenced by operator<<().

00131                                                          {
00132   //  Purpose:  Print current map of arrays maintained by array allocator on
00133   //            ostream.
00134   //
00135   //  Arguments: ms ostream to display on.
00136   //
00137   //  Return:  ostream reference.
00138   //
00139   //  Contact:   S. Kasahara
00140   //
00141 
00142   int size = fArrayMap.size();
00143   if ( size <= 0 ) {
00144     os << "RecArrayAllocator is currently not managing any arrays." << endl;
00145     return os;
00146   }
00147 
00148   os << "RecArrayAllocator is currently managing " << size 
00149      << " array" << ((size > 1) ? "s:" : ":") << endl;
00150   
00151   int i=0; 
00152   for( ArrayMapConstItr itr = fArrayMap.begin();itr != fArrayMap.end();itr++) {
00153     os << " " << i << ")Serves class " << itr->first->GetClass()->GetName() 
00154        << ((itr->second) ? " and is available." : 
00155        " and is in use.") << endl;
00156     i++;   
00157   }
00158   return os;
00159 
00160 }

void RecArrayAllocator::ReleaseArray ( TClonesArray *  array  ) 

Definition at line 99 of file RecArrayAllocator.cxx.

References EVD::Clear(), fArrayMap, Msg::kVerbose, Msg::kWarning, and MSG.

Referenced by CandRecordSRNtuple::Init(), RecValidate::TestArrayAllocator(), DemoNtupleRecord::~DemoNtupleRecord(), NtpAlignmentRecord::~NtpAlignmentRecord(), NtpCandRecord::~NtpCandRecord(), NtpCluster3DRecord::~NtpCluster3DRecord(), NtpEMRecord::~NtpEMRecord(), NtpFitSARecord::~NtpFitSARecord(), NtpMCRecord::~NtpMCRecord(), NtpMRRecord::~NtpMRRecord(), NtpSRRecord::~NtpSRRecord(), NtpStRecord::~NtpStRecord(), NtpTHRecord::~NtpTHRecord(), UberRecord::~UberRecord(), and UberRecordLite::~UberRecordLite().

00099                                                         {
00100   //  Purpose:  Dereference use of TClonesArray, freeing it for reuse.
00101   //
00102   //  Arguments: ptr to TClonesArray to be dereferenced.
00103   //
00104   //  Return:  none.
00105   //
00106   //  Contact:   S. Kasahara
00107   //
00108 
00109   // clears array.  The user has the responsibility of i)calling 
00110   // TClonesArray::Delete() before releasing array if the stored objects 
00111   // allocate memory, or ii)alternatively implementing a Clear method for these
00112   // objects that frees up any allocated memory. This method will be called
00113   // by the array->Clear("C") call below.
00114   if ( array ) { 
00115     ArrayMapItr itr = fArrayMap.find(array);
00116     if ( itr != fArrayMap.end() ) {
00117       MSG("Rec",Msg::kVerbose) << "ReleaseArray of type " 
00118                                << array->GetClass()->GetName() << endl; 
00119       array -> Clear("C");
00120       itr->second = true;
00121     }
00122     else {
00123       MSG("Rec",Msg::kWarning) << "Release array request for type " 
00124                                << array->GetClass()->GetName() << " ptr "
00125                                << array << " is not in array map! Ignored." 
00126                                << endl;
00127     } 
00128   }
00129 }


Friends And Related Function Documentation

friend struct Cleaner [friend]

Definition at line 85 of file RecArrayAllocator.h.


Member Data Documentation

std::map<TClonesArray*,bool> RecArrayAllocator::fArrayMap [private]

Definition at line 74 of file RecArrayAllocator.h.

Referenced by GetNumArray(), Print(), ReleaseArray(), and ~RecArrayAllocator().

RecArrayAllocator * RecArrayAllocator::fgInstance = 0 [static, private]

Definition at line 86 of file RecArrayAllocator.h.

Referenced by Instance(), and RecArrayAllocator::Cleaner::~Cleaner().


The documentation for this class was generated from the following files:
Generated on Wed Dec 10 22:50:26 2014 for loon by  doxygen 1.4.7