/* Copyright 2008-2010, Technische Universitaet Muenchen, Authors: Christian Hoeppner & Sebastian Neubert This file is part of GENFIT. GENFIT is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. GENFIT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with GENFIT. If not, see . */ #include"GFBookkeeping.h" #include"GFException.h" #include #include"TString.h" #include "TBuffer.h" GFBookkeeping::GFBookkeeping(const GFBookkeeping& bk) : TObject(bk) { fNhits = bk.fNhits; fMatrices = bk.fMatrices; //implicit copy constructor call fNumbers = bk.fNumbers; fPlanes = bk.fPlanes; fFailedHits = bk.fFailedHits; //deep copy std::map*>::const_iterator it; std::map*>::iterator it_here; it = bk.fMatrices.begin(); it_here = fMatrices.begin(); while(it!=bk.fMatrices.end()){ it_here->second = new TMatrixT[fNhits]; for(int i=0;isecond)[i].ResizeTo((it->second)[i]); (it_here->second)[i] = (it->second)[i]; } it++; it_here++; } it = bk.fNumbers.begin(); it_here = fNumbers.begin(); while(it!=bk.fNumbers.end()){ it_here->second = new TMatrixT[fNhits]; for(int i=0;isecond)[i].ResizeTo((it->second)[i]); (it_here->second)[i] = (it->second)[i]; } it++; it_here++; } std::map::const_iterator ip; std::map::iterator ip_here; ip = bk.fPlanes.begin(); ip_here = fPlanes.begin(); while(ip!=bk.fPlanes.end()){ ip_here->second = new GFDetPlane[fNhits]; for(int i=0;isecond)[i] = ((ip->second)[i]); } ip++; ip_here++; } } void GFBookkeeping::Streamer(TBuffer &R__b) { // Stream an object of class GFBookkeeping. if (R__b.IsReading()) { // Version_t R__v = R__b.ReadVersion(); TObject::Streamer(R__b); clearAll(); R__b >> fNhits; TString s; std::string key; unsigned int nkeys; TMatrixT mat; GFDetPlane pl; {//reading matrices R__b >> nkeys; for(unsigned int i=0;i> nkeys; for(unsigned int i=0;i> nkeys; for(unsigned int i=0;i> nFailedHits; unsigned int aFailedHit; for(unsigned int i=0;i> aFailedHit; fFailedHits.push_back(aFailedHit); } }//done reading failed hits } else { // R__b.WriteVersion(GFBookkeeping::IsA()); TObject::Streamer(R__b); //write number of hits R__b << fNhits; std::vector keys; {//save matrices keys = getMatrixKeys(); R__b << (unsigned int)(keys.size()); for(unsigned int i=0;i[fNhits]; } void GFBookkeeping::bookGFDetPlanes(std::string key){ if(fNhits<0){ GFException exc("fNhits not defined",__LINE__,__FILE__); throw exc; } if(fPlanes[key] != NULL){ std::ostringstream ostr; ostr << "The key " << key << " is already occupied in GFBookkeeping::bookGFDetPlanes()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } fPlanes[key] = new GFDetPlane[fNhits]; } //val is default set to 0. void GFBookkeeping::bookNumbers(std::string key,double val){ if(fNhits<0){ GFException exc("fNhits not defined",__LINE__,__FILE__); throw exc; } if(fPlanes[key] != NULL){ std::ostringstream ostr; ostr << "The key " << key << " is already occupied in GFBookkeeping::bookNumbers()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } fNumbers[key] = new TMatrixT[fNhits]; for(int i=0;i& mat){ if(fMatrices[key] == NULL){ std::ostringstream ostr; ostr << "The key " << key << " is unknown in GFBookkeeping::setMatrix()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } if(index>=(unsigned int)fNhits){ std::ostringstream ostr; ostr << "The index " << index << " is out of range in GFBookkeeping::setMatrix()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } (fMatrices[key])[index].ResizeTo(mat); (fMatrices[key])[index] = mat; } void GFBookkeeping::setDetPlane(std::string key, unsigned int index, const GFDetPlane& pl){ if(fPlanes[key] == NULL){ std::ostringstream ostr; ostr << "The key " << key << " is unknown in GFBookkeeping::setGFDetPlane()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } if(index>=(unsigned int)fNhits){ std::ostringstream ostr; ostr << "The index " << index << " is out of range in GFBookkeeping::setGFDetPlane()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } (fPlanes[key])[index] = pl; } void GFBookkeeping::setNumber(std::string key, unsigned int index, const double& num){ if(fNumbers[key] == NULL){ std::ostringstream ostr; ostr << "The key " << key << " is unknown in GFBookkeeping::setNumber()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } if(index>=(unsigned int)fNhits){ std::ostringstream ostr; ostr << "The index " << index << " is out of range in GFBookkeeping::setNumber()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } ((fNumbers[key])[index])[0][0] = num; } bool GFBookkeeping::getMatrix(std::string key, unsigned int index, TMatrixT& mat){ if(fMatrices[key] == NULL){ std::ostringstream ostr; ostr << "The key " << key << " is unknown in GFBookkeeping::getMatrix()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } if(index>=(unsigned int)fNhits){ std::ostringstream ostr; ostr << "The index " << index << " is out of range in GFBookkeeping::getMatrix()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } mat.ResizeTo((fMatrices[key])[index]); mat = (fMatrices[key])[index]; return true; } bool GFBookkeeping::getDetPlane(std::string key, unsigned int index, GFDetPlane& pl) { if(fPlanes[key] == NULL){ std::ostringstream ostr; ostr << "The key " << key << " is unknown in GFBookkeeping::getGFDetPlane()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } if(index>=(unsigned int)fNhits){ std::ostringstream ostr; ostr << "The index " << index << " is out of range in GFBookkeeping::getGFDetPlane()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } pl = (fPlanes[key])[index]; return true; } bool GFBookkeeping::getNumber(std::string key, unsigned int index, double& num) { if(fNumbers[key] == NULL){ std::ostringstream ostr; ostr << "The key " << key << " is unknown in GFBookkeeping::getNumber()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } if(index>=(unsigned int)fNhits){ std::ostringstream ostr; ostr << "The index " << index << " is out of range in GFBookkeeping::getNumber()"; GFException exc(ostr.str(),__LINE__,__FILE__); throw exc; } num = ((fNumbers[key])[index])[0][0]; return true; } void GFBookkeeping::addFailedHit(unsigned int id){ fFailedHits.push_back( id ); } unsigned int GFBookkeeping::getNumFailed(){ return fFailedHits.size(); } unsigned int GFBookkeeping::hitFailed(unsigned int id){ unsigned int retVal = 0; for(unsigned int i=0;i matKeys = getMatrixKeys(); std::vector planeKeys = getGFDetPlaneKeys(); std::vector numKeys = getNumberKeys(); clearAll(); clearFailedHits(); for(unsigned int i=0;i* >::iterator itMat; for(itMat=fMatrices.begin();itMat!=fMatrices.end();itMat++){ if(itMat->second!=NULL) delete [] itMat->second; } std::map::iterator itPl; for(itPl=fPlanes.begin();itPl!=fPlanes.end();itPl++){ if(itPl->second!=NULL) delete [] itPl->second; } std::map* >::iterator itNum; for(itNum=fNumbers.begin();itNum!=fNumbers.end();itNum++){ if(itNum->second!=NULL) delete [] itNum->second; } fMatrices.clear(); fPlanes.clear(); fNumbers.clear(); } std::vector< std::string > GFBookkeeping::getMatrixKeys() { std::vector< std::string > keys; std::map* >::iterator it; for(it=fMatrices.begin();it!=fMatrices.end();it++){ if(it->second!=NULL) keys.push_back(it->first); } return keys; } std::vector< std::string > GFBookkeeping::getGFDetPlaneKeys() { std::vector< std::string > keys; std::map::iterator it; for(it=fPlanes.begin();it!=fPlanes.end();it++){ if(it->second!=NULL) keys.push_back(it->first); } return keys; } std::vector< std::string > GFBookkeeping::getNumberKeys() { std::vector< std::string > keys; std::map* >::iterator it; for(it=fNumbers.begin();it!=fNumbers.end();it++){ if(it->second!=NULL) keys.push_back(it->first); } return keys; } void GFBookkeeping::Print() { std::cout << "=============GFBookkeeping::print()==============" << std::endl; std::cout << "-----printing all matrices:------" << std::endl; std::vector keys = getMatrixKeys(); for(unsigned int i=0;i m; getMatrix(keys.at(i),j,m); m.Print(); } } std::cout << "-----printing all GFDetPlanes:------" << std::endl; keys = getGFDetPlaneKeys(); for(unsigned int i=0;i