]>
Commit | Line | Data |
---|---|---|
b28acb03 | 1 | // $Header$ |
2 | ||
3 | #include "Plex.h" | |
4 | ||
5 | using namespace Reve; | |
6 | ||
7 | //______________________________________________________________________ | |
8 | // Plex | |
9 | // | |
10 | // A group of containers with chunked memory allocation. | |
11 | // | |
12 | ||
9e1efcba | 13 | |
b28acb03 | 14 | //______________________________________________________________________ |
15 | // VoidCPlex | |
16 | // | |
9e1efcba | 17 | // Non-structured (Void) Complete Plex. |
18 | // Allocation chunk can accommodate fN atoms of byte-size fS each. | |
19 | // The chunks themselves are TArrayCs and are stored in a std::vector<TArrayC*>. | |
20 | // Holes in the structure are not supported, neither is removal of atoms. | |
21 | // The structure can be Refit() to occupy a single contiguous array. | |
22 | // | |
b28acb03 | 23 | |
24 | void VoidCPlex::ReleaseChunks() | |
25 | { | |
26 | for (Int_t i=0; i<fVecSize; ++i) | |
27 | delete fChunks[i]; | |
28 | fChunks.clear(); | |
29 | } | |
30 | ||
31 | VoidCPlex::VoidCPlex() : | |
32 | fS(0), fN(0), | |
33 | fSize(0), fVecSize(0), fCapacity(0) | |
34 | {} | |
35 | ||
36 | VoidCPlex::VoidCPlex(Int_t atom_size, Int_t chunk_size) : | |
37 | fS(atom_size), fN(chunk_size), | |
38 | fSize(0), fVecSize(0), fCapacity(0) | |
39 | {} | |
40 | ||
41 | VoidCPlex::~VoidCPlex() | |
42 | { | |
43 | ReleaseChunks(); | |
44 | } | |
45 | ||
46 | /**************************************************************************/ | |
47 | ||
48 | void VoidCPlex::Reset(Int_t atom_size, Int_t chunk_size) | |
49 | { | |
50 | ReleaseChunks(); | |
51 | fS = atom_size; | |
52 | fN = chunk_size; | |
53 | fSize = fVecSize = fCapacity = 0; | |
54 | } | |
55 | ||
56 | void VoidCPlex::Refit() | |
57 | { | |
58 | if (fSize == 0 || (fVecSize == 1 && fSize == fCapacity)) | |
59 | return; | |
60 | ||
61 | TArrayC* one = new TArrayC(fS*fSize); | |
62 | Char_t* pos = one->fArray; | |
63 | for (Int_t i=0; i<fVecSize; ++i) | |
64 | { | |
65 | Int_t size = fS * NAtoms(i); | |
66 | memcpy(pos, fChunks[i]->fArray, size); | |
67 | pos += size; | |
68 | } | |
69 | ReleaseChunks(); | |
70 | fN = fCapacity = fSize; | |
71 | fVecSize = 1; | |
72 | fChunks.push_back(one); | |
73 | } | |
74 | ||
75 | /**************************************************************************/ | |
76 | ||
77 | Char_t* VoidCPlex::NewChunk() | |
78 | { | |
79 | fChunks.push_back(new TArrayC(fS*fN)); | |
80 | ++fVecSize; | |
81 | fCapacity += fN; | |
82 | return fChunks.back()->fArray; | |
83 | } | |
84 | ||
85 | /**************************************************************************/ | |
86 | /**************************************************************************/ |