#include "PndSsdEventMerger.h" #include "TFile.h" #include "TTree.h" #include #include "PndMvdMCPoint.h" #include "PndMvdDigiStrip.h" #include "PndMvdDigiPixel.h" #include "PndTpcCluster.h" #include "PndTpcPoint.h" using std::cout; using std::endl; PndSsdEventMerger::PndSsdEventMerger() { //fBuffer = 0; //fBuffer = new TObjArray(); } PndSsdEventMerger::PndSsdEventMerger(TString fileName, TString branchName, Int_t nEvents, Int_t nMerged) { // fBuffer = new TObjArray(); if ( ! FillBuffer(fileName, branchName, nEvents, nMerged) ) cout << "-E- PndSsdEventMerger: Error in filling buffer"; } PndSsdEventMerger::~PndSsdEventMerger() { //fBuffer->Delete(); //delete fBuffer; //fBuffer = 0; } TClonesArray* PndSsdEventMerger::GetEvent(Int_t iEvent) { //if ( !fBuffer) // std::cout << "-E- CbmSsdPileupManager::GetEvent: No event buffer!"; if (iEvent > fBuffer.size()) { cout << "-W- CbmSsdPileupManager::GetEvent: Event " << iEvent << " not present in buffer! " << endl; cout << " Returning NULL pointer! " << endl; return NULL; } TClonesArray* pArray = (TClonesArray*) fBuffer.at(iEvent); if ( !pArray) { cout << "-W CbmSsdPileupManager::GetEvent: Returning NULL pointer!" << endl; return NULL; } return pArray; } Int_t PndSsdEventMerger::FillBuffer(TString fileName, TString branchName, Int_t nEvents, Int_t nMerged) { //if ( !fBuffer) // cout << "-E- Fill Buffer: No event buffer!"; //fBuffer->Delete(); TClonesArray* pointArray= NULL; TClonesArray* mergedPointsArray = NULL; //TFile* saveGFile = gFile; TFile* bgfile = new TFile(fileName); if ( !bgfile) { cout << "-W- CbmSsdPileupManager::FillBuffer: Background file " << fileName << " could noy be opened! " << endl; return 0; } cout << "-I- CbmSsdPileupManager::FillBuffer: Opening file " << endl; cout << fileName << endl; TTree* bgtree = (TTree*) bgfile->Get("cbmsim"); if ( !bgtree) { cout << "-W- CbmSsdPileupManager::FillBuffer: " << "Could not find cbmsim tree in background file " << endl; return 0; } Int_t nEventsInFile = bgtree->GetEntries(); cout << "-I- CbmSsdPileupManager::FillBuffer: " << nEventsInFile << " events in file" << endl; Int_t nBuffer = TMath::Min(nEvents, nEventsInFile); cout << "-I- CbmSsdPileupManager::FillBuffer: Buffering " << nBuffer << " events" << endl; Int_t nMergedBuffer = TMath::Min(nMerged, nEventsInFile); bgtree->SetBranchAddress(branchName, &pointArray); for (Int_t iEvent=0; iEventGetEntry(iEvent); if (iEvent == 0) mergedPointsArray = (TClonesArray*)pointArray->Clone(); else { std::cout << "New size of mergedPointsArray: " << AddTClonesArray(mergedPointsArray, pointArray) << std::endl; } } //fBuffer = new TObjArray(nBuffer,0); for (Int_t iEvent=0; iEventGetEntriesFast() << std::endl; //std::cout << fBuffer << std::endl; fBuffer.push_back((TClonesArray*)mergedPointsArray); } // delete bgtree; bgfile->Close(); // delete bgfile; // saveGFile->cd(); return nBuffer; } Int_t PndSsdEventMerger::AddTClonesArray(TClonesArray* target, TClonesArray* source) { Int_t origSize = target->GetEntriesFast(); for (int i = 0; i < source->GetEntriesFast(); i++){ std::cout << source->GetClass()->GetName() << std::endl; TString myClassName(source->GetClass()->GetName()); if(myClassName.Contains("PndMvdMCPoint")) new ((*target)[origSize + i])PndMvdMCPoint(*(PndMvdMCPoint*)(source->At(i))); else if (myClassName.Contains("PndMvdDigiPixel")) new ((*target)[origSize + i])PndMvdDigiPixel(*(PndMvdDigiPixel*)(source->At(i))); else if (myClassName.Contains("PndMvdDigiStrip")) new ((*target)[origSize + i])PndMvdDigiStrip(*(PndMvdDigiStrip*)(source->At(i))); else if (myClassName.Contains("PndTpcPoint")) new ((*target)[origSize + i])PndTpcPoint(*(PndTpcPoint*)(source->At(i))); else if (myClassName.Contains("PndTpcCluster")) new ((*target)[origSize + i])PndTpcCluster(*(PndTpcCluster*)(source->At(i))); else std::cout << "The Class: " << myClassName << " is unknown!" << std::endl; } return target->GetEntriesFast(); } ClassImp(PndSsdEventMerger);