Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
Link.cxx
1/*
2 * HalLink.cxx
3 *
4 * Created on: 22 lut 2018
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "Link.h"
10
11namespace Hal {
12
13 Link::Link(Int_t i) : TObject(), fActiveSize(i), fSize(i) {
14 fLinks = new Int_t[i];
15 fLinks[0] = 0;
16 }
17
18 Link::Link(const Link& link) : TObject(link), fActiveSize(link.fActiveSize), fSize(link.fSize) {
19 fLinks = new Int_t[fSize];
20 for (int i = 0; i < fSize; i++)
21 fLinks[i] = link.fLinks[i];
22 }
23
24 Link Link::operator=(const Link& link) {
25 if (this != &link) {
26 if (fSize < link.fActiveSize) {
27 delete[] fLinks;
28 fSize = link.fSize;
29 fLinks = new Int_t[fSize];
30 }
31 fActiveSize = link.fActiveSize;
32 for (int i = 0; i < fActiveSize; i++) {
33 fLinks[i] = link.fLinks[i];
34 }
35 }
36 return *this;
37 }
38
39 Link::~Link() { delete[] fLinks; }
40
41 void Link::SetLinkAndExpand(Int_t index, Int_t val) {
42 if (fSize <= index) {
43 Int_t old_size = fActiveSize;
44 Int_t* temp = fLinks;
45 fLinks = new Int_t[index + 1];
46 fSize = index + 1;
47 fActiveSize = index + 1;
48 for (int i = 0; i < old_size; i++)
49 fLinks[i] = temp[i];
50 delete[] temp;
51 fLinks[index] = val;
52 } else {
53 if (fActiveSize < index) fActiveSize = index;
54 fLinks[index] = val;
55 }
56 }
57
58 void Link::SetNextLink(Int_t i) {
59 if (fActiveSize < fSize) {
60 fLinks[fActiveSize++] = i;
61 } else {
62 SetLinkAndExpand(fActiveSize, i);
63 }
64 }
65
66 void Link::Clear(Option_t* /*opt*/) {
67 fActiveSize = 1;
68 fLinks[0] = 0;
69 }
70
71 void Link::ExpandFast(Int_t size) {
72 if (size < fSize) {
73 fActiveSize = size;
74 } else {
75 Int_t old_size = fActiveSize;
76 Int_t* temp = fLinks;
77 fLinks = new Int_t[size];
78 fSize = size;
79 fActiveSize = size;
80 for (int i = 0; i < old_size; i++)
81 fLinks[i] = temp[i];
82 delete[] temp;
83 }
84 }
85
86 void Link::ClearLinks() {
87 for (int i = 0; i < fActiveSize; i++)
88 fLinks[i] = -1;
89 }
90} // namespace Hal