/** @file CbmMCPointBuffer.h ** @author Volker Friese ** @date 13 February 2012 **/ #ifndef CBMMCPOINTBUFFER_H #define CBMMCPOINTBUFFER_H 1 #include #include "TClonesArray.h" #include "FairLogger.h" #include "FairMCPoint.h" #include "CbmDetectorList.h" using namespace std; /** @class IsBefore ** @author Volker Friese ** @date 10 February 2012 ** @brief Template comparison class for objects derived from FairTimeStamp. ** ** This template class provides a weak ordering for objects derived ** from FairTimeStamp. The comparison is based on the member variable ** fTimeStamp. **/ template class IsBefore { public: Bool_t operator() (Point point1, Point point2) const { return ( point1.GetTime() < point2.GetTime() ); } }; /** @class CbmMCPointBuffer ** @author Volker Friese ** @date 13 February 2012 ** @brief Buffer class for the MCPoints of a detector ** ** MCPoints are read in from a TClonesArray and stored in a time-ordered ** manner using the STL set container. They can be sequentially accessed ** by the method GetNextPoint, which will deliver pointers to the MCPoints ** with absolute times up to a specified time. The method Clear deletes all ** points accessed by GetNextPoint so far. **/ template class CbmMCPointBuffer { public: /** Default constructor **/ CbmMCPointBuffer() { fBufferIt = fBuffer.begin(); }; /** Destructor **/ ~CbmMCPointBuffer() { fBuffer.clear(); }; /** Removes all points from the beginning to the current position of the ** iterator (all those accessed by GetNextPoint before). **/ void Clear() { fBuffer.erase(fBuffer.begin(), fBufferIt); fBufferIt = fBuffer.begin(); }; /** Fill the buffer with the content of a TClonesArray ** @param array Pointer to TClonesArray ** @param eventTime Time to be added to the MCPoint time to get the abolute time **/ Int_t Fill(TClonesArray* array, Double_t eventTime, Int_t eventId) { if ( ! array ) return 0; Int_t nPoints = array->GetEntriesFast(); for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) { T* point = (T*) array->At(iPoint); point->SetEventID(eventId); point->SetTime(eventTime + point->GetTime()); fBuffer.insert(*point); } fBufferIt = fBuffer.begin(); return nPoints; }; /** Get the size of the buffer in MB ** @value Buffer size [MB] **/ Double_t GetSize() const { return 1.e-6 * sizeof(T) * Double_t(fBuffer.size()); } /** Get the next (w.r.t. abolute time) MCPoint from the buffer. ** Only points up to the specified time are delivered. If there is none ** left, the method returns NULL. ** The point will stay in memory, but is marked for deletion by Clear(). ** @param time Time up to which the points will be delivered ** @value Pointer to the FairMCPoint. NULL is there are no points left. **/ const FairMCPoint* GetNextPoint(Double_t time) { const FairMCPoint* point = NULL; if ( (*fBufferIt).GetTime() < time ) point = &(*fBufferIt++); return point; }; /** Output to screen. Gives number of points in buffer and memory used. ** @param det System identifier (e.g. kSTS) ** @param logger Pointer to FairLogger singleton **/ void Print(DetectorId det, FairLogger* logger) { Int_t nPoints = fBuffer.size(); TString sysName; CbmDetectorList::GetSystemNameCaps(det, sysName); logger->Info(MESSAGE_ORIGIN, "%-4s: %8d ( %8.2f MB )", sysName.Data(), nPoints, GetSize()); }; private: multiset > fBuffer; typename multiset >::iterator fBufferIt; }; #endif