/** * \file CbmMatch2.cxx * \author Andrey Lebedev * \date 2013 **/ #include "CbmMatch2.h" #include using std::make_pair; using std::stringstream; CbmMatch2::CbmMatch2() : fLinks(), fTotalWeight(0.), fMatchedIndex(-1) { } string CbmMatch2::ToString() const { stringstream ss; ss << "CbmMatch: "; Int_t nofLinks = GetNofLinks(); ss << "nofLinks=" << nofLinks << "\n"; for (Int_t i = 0; i < nofLinks; i++) { CbmLink* link = GetLink(i); ss << link->ToString(); } ss << " totalWeight=" << fTotalWeight << ", matchedIndex=" << fMatchedIndex << std::endl; return ss.str(); } void CbmMatch2::AddLinks(const CbmMatch2& match) { Int_t nofLinks = match.GetNofLinks(); for (Int_t i = 0; i < nofLinks; i++) { AddLink(match.GetLink(i)); } } void CbmMatch2::AddLink(CbmLink* newLink) { Int_t addedIndex = -1; Int_t nofLinks = GetNofLinks(); for (Int_t i = 0; i < nofLinks; i++) { CbmLink* link = GetLink(i); if (*link == *newLink) { link->AddWeight(newLink->GetWeight()); addedIndex = i; break; } } if (addedIndex < 0) { fLinks.Add(newLink); addedIndex = fLinks.GetSize() - 1; } fTotalWeight += newLink->GetWeight(); if (fMatchedIndex < 0) { fMatchedIndex = addedIndex; } else { if (GetLink(addedIndex)->GetWeight() > GetMatchedLink()->GetWeight()) { fMatchedIndex = addedIndex; } } } void CbmMatch2::AddLink(Double_t weight, Int_t index, Int_t entry, Int_t file) { CbmLink* link = new CbmLink(weight, index, entry, file); AddLink(link); } void CbmMatch2::ClearLinks() { fLinks.Delete(); fTotalWeight = 0.; fMatchedIndex = -1; } ClassImp(CbmMatch2);