/* * PndEventCombinerTask.cxx * * Created on: May 3, 2017 * Author: Steinschaden * */ #include "PndEventCombinerTask.h" #include // Root includes #include "TROOT.h" #include "TString.h" //#include "TVector3.h" //#include "TMath.h" // framework includes #include "FairRootManager.h" PndEventCombinerTask::PndEventCombinerTask() : FairTask("PndEventCombiner") { fPersistence = kTRUE; fNEvents = 2; //fInBranches } PndEventCombinerTask::~PndEventCombinerTask() { } // ----- Public method Init -------------------------------------------- InitStatus PndEventCombinerTask::Init() { FairRootManager* ioman = FairRootManager::Instance(); if ( ! ioman ) { std::cout << "-E- PndSolCorrTask::Init: " << "RootManager not instantiated!" << std::endl; return kFATAL; } if(fInBranches.size()==0) { std::cout << "kERROR ------ no inputBranch for PndEventCombiner -------" << std::endl; return kERROR; } TString inputName = "none"; TString outputName; TString outputFolder; for (size_t i = 0; i < fInBranches.size(); i++){ inputName = fInBranches[i]; fInArrays.push_back((TClonesArray*)ioman->GetObject(inputName.Data())); if ( ! fInArrays[i]){ std::cout << " Input Array not found for PndSolCorrTask: "<< inputName << std::endl; return kERROR; } outputFolder = TString::Format("comb_%d",fNEvents); outputName = outputFolder+"_" + inputName; fOutArrays.push_back(ioman->Register(outputName.Data(), fInArrays[i]->GetClass()->GetName(), outputFolder, fPersistence)); fTmpArrays.push_back(new TClonesArray(fInArrays[i]->GetClass()->GetName())); } return kSUCCESS; } // ----- Public method Exec -------------------------------------------- void PndEventCombinerTask::Exec(Option_t*) { FairRootManager* ioman = FairRootManager::Instance(); TClonesArray* veryTmpArray; for (size_t i = 0; i < fInArrays.size(); i++) { fOutArrays[i]->Delete(); // make sure written out data from old events are deleted veryTmpArray = new TClonesArray(*fInArrays[i]); // copy the input data befor absorbing them! fTmpArrays[i]->AbsorbObjects(veryTmpArray); //fill the tmp array with the data of the new events delete veryTmpArray; veryTmpArray = NULL; if(ioman->GetEntryNr() % fNEvents == fNEvents - 1) { //if enough data is collected : fOutArrays[i]->AbsorbObjects(fTmpArrays[i]); // prepare write out of the data fTmpArrays[i]->Delete(); // reset the tmp data container } } } ClassImp(PndEventCombinerTask);