ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataCont/interface/StackArrayBasic.h
Revision: 1.10
Committed: Mon Mar 23 22:15:10 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_011, Mit_010a, Mit_010, Mit_009c, Mit_009b, Mit_009a, Mit_009, Mit_008, HEAD
Branch point for: Mit_025c_branch
Changes since 1.9: +2 -2 lines
Log Message:
Cosmetics

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: StackArrayBasic.h,v 1.9 2009/03/23 13:07:18 loizides Exp $
3 //
4 // StackArrayBasic
5 //
6 // Implementation of an array on the stack as opposed to on the heap
7 // memory. For various reasons, the array cannot be written in split
8 // mode. Maximum size is set by template parameter. Array is meant to
9 // store basic data types as opposed to StackArray which can hold
10 // classes. Note that this array as opposed to the others does not
11 // derive from the templated Collection interface.
12 //
13 // Authors: C.Loizides, J.Bendavid
14 //--------------------------------------------------------------------------------------------------
15
16 #ifndef MITANA_DATACONT_STACKARRAYBASIC_H
17 #define MITANA_DATACONT_STACKARRAYBASIC_H
18
19 #include <TObject.h>
20 #include "MitAna/DataCont/interface/BaseCollection.h"
21
22 namespace mithep
23 {
24 template<class ArrayElement, UInt_t N>
25 class StackArrayBasic : public BaseCollection
26 {
27 public:
28 StackArrayBasic();
29 StackArrayBasic(const StackArrayBasic &a);
30
31 void Add(const ArrayElement &ae);
32 ArrayElement At(UInt_t idx);
33 const ArrayElement At(UInt_t idx) const;
34 UInt_t Entries() const { return fSize; }
35 UInt_t GetEntries() const { return fSize; }
36 UInt_t GetSize() const { return N; }
37 Bool_t IsOwner() const { return kTRUE; }
38 TObject *ObjAt(UInt_t idx) { return 0; }
39 const TObject *ObjAt(UInt_t idx) const { return 0; }
40 void Reset();
41 void Trim() {}
42 ArrayElement UncheckedAt(UInt_t idx);
43 const ArrayElement UncheckedAt(UInt_t idx) const;
44 ArrayElement operator[](UInt_t idx);
45 const ArrayElement operator[](UInt_t idx) const;
46
47 protected:
48 UShort_t fSize; //size of array
49 ArrayElement fArray[N]; //storage for basic types
50
51 ClassDef(StackArrayBasic, 1) // Array on stack for basic types
52 };
53 }
54
55 //--------------------------------------------------------------------------------------------------
56 template<class ArrayElement, UInt_t N>
57 inline mithep::StackArrayBasic<ArrayElement, N>::StackArrayBasic() :
58 fSize(0)
59 {
60 // Default constructor.
61 }
62
63 //--------------------------------------------------------------------------------------------------
64 template<class ArrayElement, UInt_t N>
65 inline mithep::StackArrayBasic<ArrayElement, N>::StackArrayBasic(const StackArrayBasic &a) :
66 fSize(a.fSize)
67 {
68 // Copy constructor. Copy only elements which are used.
69
70 for (UInt_t i=0; i<fSize; ++i)
71 fArray[i] = a.fArray[i];
72 }
73
74 //--------------------------------------------------------------------------------------------------
75 template<class ArrayElement, UInt_t N>
76 void mithep::StackArrayBasic<ArrayElement, N>::Add(const ArrayElement &ae)
77 {
78 // Add element to array.
79
80 if (fSize>=N) {
81 TObject::Fatal("Add", "Maximum number of slots reached (%d>=%d): "
82 "To support more requires a different template!", fSize, N);
83 return;
84 }
85
86 fArray[fSize] = ae;
87 ++fSize;
88 BaseCollection::Clear();
89 }
90
91 //--------------------------------------------------------------------------------------------------
92 template<class ArrayElement, UInt_t N>
93 inline ArrayElement mithep::StackArrayBasic<ArrayElement, N>::At(UInt_t idx)
94 {
95 // Return entry at given index.
96
97 if (idx<fSize)
98 return fArray[idx];
99
100 ArrayElement tmp;
101 TObject::Fatal("At","Index too large: (%u < %u violated) for %s containing %s",
102 idx, fSize, GetName(), typeid(tmp).name());
103 return 0;
104 }
105
106 //--------------------------------------------------------------------------------------------------
107 template<class ArrayElement, UInt_t N>
108 inline const ArrayElement mithep::StackArrayBasic<ArrayElement, N>::At(UInt_t idx) const
109 {
110 // Return entry at given index.
111
112 if (idx<fSize)
113 return fArray[idx];
114
115 ArrayElement tmp;
116 TObject::Fatal("At","Index too large: (%u < %u violated) for %s containing %s",
117 idx, fSize, GetName(), typeid(tmp).name());
118 return 0;
119 }
120
121 //-------------------------------------------------------------------------------------------------
122 template<class ArrayElement, UInt_t N>
123 void mithep::StackArrayBasic<ArrayElement, N>::Reset()
124 {
125 // Reset this array.
126
127 fSize = 0;
128 BaseCollection::Clear();
129 }
130
131 //-------------------------------------------------------------------------------------------------
132 template<class ArrayElement, UInt_t N>
133 void mithep::StackArrayBasic<ArrayElement, N>::Streamer(TBuffer &b)
134 {
135 // Stream all objects in the array to or from the I/O buffer.
136
137 if (b.IsReading()) {
138 b >> fSize;
139 if (fSize) {
140 b.ReadFastArray(fArray,fSize);
141 }
142 } else { /*writing*/
143 b << fSize;
144 if (fSize) {
145 b.WriteFastArray(fArray,fSize);
146 }
147 }
148 }
149
150 //--------------------------------------------------------------------------------------------------
151 template<class ArrayElement, UInt_t N>
152 inline ArrayElement mithep::StackArrayBasic<ArrayElement, N>::UncheckedAt(UInt_t idx)
153 {
154 // Return entry at given index.
155
156 return fArray[idx];
157 }
158
159 //--------------------------------------------------------------------------------------------------
160 template<class ArrayElement, UInt_t N>
161 inline const ArrayElement mithep::StackArrayBasic<ArrayElement, N>::UncheckedAt(UInt_t idx) const
162 {
163 // Return entry at given index.
164
165 return fArray[idx];
166 }
167
168 //--------------------------------------------------------------------------------------------------
169 template<class ArrayElement, UInt_t N>
170 inline const ArrayElement mithep::StackArrayBasic<ArrayElement, N>::operator[](UInt_t idx) const
171 {
172 // Return entry at given index.
173
174 return At(idx);
175 }
176
177 //--------------------------------------------------------------------------------------------------
178 template<class ArrayElement, UInt_t N>
179 inline ArrayElement mithep::StackArrayBasic<ArrayElement, N>::operator[](UInt_t idx)
180 {
181 // Return entry at given index.
182
183 return At(idx);
184 }
185 #endif