CbmRoot
Loading...
Searching...
No Matches
CbmMatch.cxx
Go to the documentation of this file.
1/* Copyright (C) 2013-2020 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
10#include "CbmMatch.h"
11
12#include <sstream> // for operator<<, basic_ostream, stringstream
13#include <string> // for char_traits
14#include <utility> // for make_pair
15
16using std::make_pair;
17using std::string;
18using std::stringstream;
19using std::vector;
20
21CbmMatch::CbmMatch() : fLinks(), fTotalWeight(0.), fMatchedIndex(-1) {}
22
24
25string CbmMatch::ToString() const
26{
27 stringstream ss;
28 ss << "CbmMatch: ";
29 int32_t nofLinks = GetNofLinks();
30 ss << "nofLinks=" << nofLinks << "\n";
31 for (int32_t i = 0; i < nofLinks; i++) {
32 const CbmLink& link = fLinks[i];
33 ss << link.ToString();
34 }
35 ss << " totalWeight=" << fTotalWeight << ", matchedIndex=" << fMatchedIndex << std::endl;
36 return ss.str();
37}
38
39void CbmMatch::AddLinks(const CbmMatch& match)
40{
41 int32_t nofLinks = match.GetNofLinks();
42 for (int32_t i = 0; i < nofLinks; i++) {
43 AddLink(match.GetLink(i));
44 }
45}
46
47void CbmMatch::AddLink(const CbmLink& newLink)
48{
49 int32_t addedIndex = -1;
50 int32_t nofLinks = GetNofLinks();
51 for (int32_t i = 0; i < nofLinks; i++) {
52 CbmLink& link = fLinks[i];
53 if (link == newLink) {
54 link.AddWeight(newLink.GetWeight());
55 addedIndex = i;
56 break;
57 }
58 }
59 if (addedIndex < 0) {
60 fLinks.push_back(newLink);
61 addedIndex = fLinks.size() - 1;
62 }
63
64 fTotalWeight += newLink.GetWeight();
65 if (fMatchedIndex < 0) { fMatchedIndex = addedIndex; }
66 else {
67 if (fLinks[addedIndex].GetWeight() > fLinks[fMatchedIndex].GetWeight()) { fMatchedIndex = addedIndex; }
68 }
69}
70
71void CbmMatch::AddLink(double weight, int32_t index, int32_t entry, int32_t file)
72{
73 CbmLink link(weight, index, entry, file);
74 AddLink(link);
75}
76
77
79{
80 fLinks.clear();
81 fTotalWeight = 0.;
82 fMatchedIndex = -1;
83}
84
ClassImp(CbmMatch)
void AddLinks(const CbmMatch &match)
Definition CbmMatch.cxx:39
const CbmLink & GetLink(int32_t i) const
Definition CbmMatch.h:39
int32_t GetNofLinks() const
Definition CbmMatch.h:42
double fTotalWeight
Definition CbmMatch.h:59
void AddLink(const CbmLink &newLink)
Definition CbmMatch.cxx:47
int32_t fMatchedIndex
Definition CbmMatch.h:60
std::vector< CbmLink > fLinks
Definition CbmMatch.h:58
CbmMatch()
Default constructor.
Definition CbmMatch.cxx:21
virtual ~CbmMatch()
Destructor.
Definition CbmMatch.cxx:23
virtual std::string ToString() const
Return string representation of the object.
Definition CbmMatch.cxx:25
void ClearLinks()
Definition CbmMatch.cxx:78