/** * \file CbmMatch.cxx * \author Andrey Lebedev * \date 2013 **/ #include "CbmMatch.h" #include using std::make_pair; using std::stringstream; CbmMatch::CbmMatch() : fLinks(), fTotalWeight(0.), fMatchedIndex(-1) { } CbmMatch::~CbmMatch() { } string CbmMatch::ToString() const { stringstream ss; ss << "CbmMatch: "; Int_t nofLinks = GetNofLinks(); ss << "nofLinks=" << nofLinks << "\n"; for (Int_t i = 0; i < nofLinks; i++) { const CbmLink& link = fLinks[i]; ss << link.ToString(); } ss << " totalWeight=" << fTotalWeight << ", matchedIndex=" << fMatchedIndex << std::endl; return ss.str(); } void CbmMatch::AddLink(const CbmMatch& match) { Int_t nofLinks = match.GetNofLinks(); for (Int_t i = 0; i < nofLinks; i++) { AddLink(match.GetLink(i)); } } void CbmMatch::AddLink(const CbmLink& newLink) { Int_t addedIndex = -1; Int_t nofLinks = GetNofLinks(); for (Int_t i = 0; i < nofLinks; i++) { CbmLink& link = fLinks[i]; if (link == newLink) { link.AddWeight(newLink.GetWeight()); addedIndex = i; break; } } if (addedIndex < 0) { fLinks.push_back(newLink); addedIndex = fLinks.size() - 1; } fTotalWeight += newLink.GetWeight(); if (fMatchedIndex < 0) { fMatchedIndex = addedIndex; } else { if (fLinks[addedIndex].GetWeight() > fLinks[fMatchedIndex].GetWeight()) { fMatchedIndex = addedIndex; } } } void CbmMatch::Clear() { fLinks.clear(); fTotalWeight = 0.; fMatchedIndex = -1; } ClassImp(CbmMatch);