// ------------------------------------------------------------------------- // ----- CbmMvdSensorFrameBuffer source file ----- // ----- Created 02.02.2012 by M. Deveaux ----- // ------------------------------------------------------------------------- #include "CbmMvdSensorFrameBuffer.h" #include "TClonesArray.h" #include "TObjArray.h" #include "CbmMvdPoint.h" // ----- Default constructor ------------------------------------------- CbmMvdSensorFrameBuffer::CbmMvdSensorFrameBuffer() { fBuffer = NULL; } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmMvdSensorFrameBuffer::~CbmMvdSensorFrameBuffer() { fBuffer->Delete(); delete fBuffer; } // ------------------------------------------------------------------------- void CbmMvdSensorFrameBuffer::Init (CbmMvdSensor* mySensor) { fSensor=mySensor; fBuffer=new TClonesArray("CbmMvdPoint",1000); fCurrentEvent= new TClonesArray("CbmMvdPoint",1000); }; void CbmMvdSensorFrameBuffer::SendInputEvent (TClonesArray* inputStream) { CbmMvdPoint* point; for(Int_t i=0; iGetEntriesFast(); i++) { point= (CbmMvdPoint*) inputStream->At(i); //check if point belongs to this sensor if (point->GetDetectorID()==fSensor->GetDetectorID()) { //if fulfilled, copy point to local buffer and remove from input stream //Aim: Reduce entries in input stream for next sensor fBuffer->AddLast(inputStream->At(i)); inputStream->RemoveAt(i); }; }; //remove empty slots from input stream to get unfragmented data for next sensor inputStream->Compress(); } void CbmMvdSensorFrameBuffer::BuildMimosaFrame(Int_t frameNumber) { /**Builds a new event in TClonesArray. * Important notes: * * - The previously built event is cleared. As only a pointer on related TClonesArray * is provided by the buffer (not a copy!), this clearing also affects the outside * "non-copies" the previous event. * Make sure you have processed the previous event or (if needed) perform a manual copy * externally. * * - By building a new event, the objects in the local input buffer are not cleared. * To avoid memory leaks, clear them manually with the "ClearFrame" methode. * **/ fCurrentEvent->Clear(); CbmMvdPoint* point; Int_t pointFrameNumber; Double_t position[3]; Int_t pixelX,pixelY; Int_t nPoints; for(Int_t i=0; iGetEntriesFast(); i++){ point=(CbmMvdPoint*)fBuffer->At(i); //compute pixel number related to the frameNumber position[0]=point->GetX(); position[1]=point->GetY(); position[2]=point->GetZ(); fSensor->TopToPixel(position, pixelX, pixelY); //Get frame number from the CbmMvdSensor according to assumed position of the //rolling shutter. pointFrameNumber = fSensor->GetFrameNumber(pixelY, point->GetTime()); // if it belongs to the frame, copy it to the event buffer if(pointFrameNumber==frameNumber){ nPoints=fCurrentEvent->GetEntriesFast(); new ((*fCurrentEvent)[nPoints]) CbmMvdPoint (*point); }; }; }; void CbmMvdSensorFrameBuffer::ClearFrame(Int_t frameNumber) { /**Builds a new event in TClonesArray. * * Removes objects related to a frame from the internal buffer * **/ CbmMvdPoint* point; Int_t pointFrameNumber; Double_t position[3]; Int_t pixelX,pixelY; Int_t nPoints; for(Int_t i=0; iGetEntriesFast(); i++){ //compute pixel number related to the frameNumber point=(CbmMvdPoint*)fBuffer->At(i); position[0]=point->GetX(); position[1]=point->GetY(); position[2]=point->GetZ(); fSensor->TopToPixel(position, pixelX, pixelY); //Get frame number from the CbmMvdSensor according to assumed position of the //rolling shutter. pointFrameNumber = fSensor->GetFrameNumber(pixelY, point->GetTime()); // if it belongs to the frame, delete it from the internal buffer if(pointFrameNumber==frameNumber){fBuffer->RemoveAt(i);}; }; fBuffer->Compress(); //defrag buffer }; void CbmMvdSensorFrameBuffer::ClearTimeSlice (Double_t tStart, Double_t tStop) { CbmMvdPoint* point; for (Int_t i=0; iGetEntriesFast(); i++){ point=(CbmMvdPoint*)fBuffer->At(i); if((point->GetTime()>tStart) && (point->GetTime()RemoveAt(i);} }; fBuffer->Compress(); // defrag }; ClassImp(CbmMvdSensorFrameBuffer)