Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CompressionMap.cxx
1/*
2 * CompressionMap.cxx
3 *
4 * Created on: 10 wrz 2022
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "CompressionMap.h"
10
11#include <iostream>
12
13namespace Hal {
14
15 CompressionMap::CompressionMap() : fSize(0), fAllocatedSize(0), fCounter(0), fOldToNewIndex(nullptr), fNewToOldIndex(nullptr) {}
16
17 CompressionMap::CompressionMap(const CompressionMap& other) :
18 TObject(other), fSize(other.fSize), fAllocatedSize(other.fAllocatedSize), fCounter(other.fCounter), fOldToNewIndex(nullptr) {
19 if (fAllocatedSize > 0) {
20 fOldToNewIndex = new Int_t[fAllocatedSize];
21 fNewToOldIndex = new Int_t[fAllocatedSize];
22 }
23 std::cout << "WARNING COPY MAP" << std::endl;
24 }
25
26 void CompressionMap::Reset(Int_t size) {
27 CheckSize(size);
28 fSize = size;
29 fCounter = 0;
30 for (int i = 0; i < fSize; i++) {
31 fOldToNewIndex[i] = -1;
32 }
33 }
34
35 void CompressionMap::Recalculate() {
36 for (int i = 0; i < fSize; i++) {
37 if (fOldToNewIndex[i] == 0) {
38 fOldToNewIndex[i] = fCounter;
39 fNewToOldIndex[fCounter] = i;
40 fCounter++;
41 }
42 }
43 }
44
45 void CompressionMap::CheckSize(Int_t size) {
46 if (fAllocatedSize <= size) {
47 Int_t newSize = size * 2;
48 if (fOldToNewIndex) delete[] fOldToNewIndex;
49 if (fNewToOldIndex) delete[] fNewToOldIndex;
50 fOldToNewIndex = new Int_t[newSize];
51 fNewToOldIndex = new Int_t[newSize];
52 fAllocatedSize = newSize;
53 }
54 }
55
56 CompressionMap::~CompressionMap() {
57 if (fOldToNewIndex) delete[] fOldToNewIndex;
58 if (fNewToOldIndex) delete[] fNewToOldIndex;
59 }
60
61} /* namespace Hal */