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

# User Rev Content
1 bendavid 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.10 // $Id: StackArrayBasic.h,v 1.9 2009/03/23 13:07:18 loizides Exp $
3 bendavid 1.1 //
4     // StackArrayBasic
5     //
6 loizides 1.2 // Implementation of an array on the stack as opposed to on the heap
7 loizides 1.10 // memory. For various reasons, the array cannot be written in split
8 loizides 1.2 // 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 loizides 1.3 // classes. Note that this array as opposed to the others does not
11     // derive from the templated Collection interface.
12 bendavid 1.1 //
13     // Authors: C.Loizides, J.Bendavid
14     //--------------------------------------------------------------------------------------------------
15    
16 loizides 1.6 #ifndef MITANA_DATACONT_STACKARRAYBASIC_H
17     #define MITANA_DATACONT_STACKARRAYBASIC_H
18 bendavid 1.1
19     #include <TObject.h>
20 loizides 1.3 #include "MitAna/DataCont/interface/BaseCollection.h"
21 bendavid 1.1
22     namespace mithep
23     {
24     template<class ArrayElement, UInt_t N>
25 loizides 1.3 class StackArrayBasic : public BaseCollection
26 bendavid 1.1 {
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 loizides 1.7 UInt_t Entries() const { return fSize; }
35 loizides 1.3 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 loizides 1.8 void Reset();
41 bendavid 1.1 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 loizides 1.2 UShort_t fSize; //size of array
49     ArrayElement fArray[N]; //storage for basic types
50 bendavid 1.1
51 loizides 1.3 ClassDef(StackArrayBasic, 1) // Array on stack for basic types
52 bendavid 1.1 };
53     }
54    
55     //--------------------------------------------------------------------------------------------------
56     template<class ArrayElement, UInt_t N>
57     inline mithep::StackArrayBasic<ArrayElement, N>::StackArrayBasic() :
58     fSize(0)
59     {
60 loizides 1.2 // Default constructor.
61 bendavid 1.1 }
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 loizides 1.2 // Copy constructor. Copy only elements which are used.
69    
70 bendavid 1.1 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 loizides 1.2 // Add element to array.
79 bendavid 1.1
80 loizides 1.3 if (fSize>=N) {
81 loizides 1.2 TObject::Fatal("Add", "Maximum number of slots reached (%d>=%d): "
82     "To support more requires a different template!", fSize, N);
83 bendavid 1.1 return;
84     }
85    
86     fArray[fSize] = ae;
87     ++fSize;
88 loizides 1.9 BaseCollection::Clear();
89 bendavid 1.1 }
90    
91     //--------------------------------------------------------------------------------------------------
92     template<class ArrayElement, UInt_t N>
93 loizides 1.2 inline ArrayElement mithep::StackArrayBasic<ArrayElement, N>::At(UInt_t idx)
94 bendavid 1.1 {
95     // Return entry at given index.
96    
97 loizides 1.3 if (idx<fSize)
98 bendavid 1.1 return fArray[idx];
99    
100 loizides 1.2 ArrayElement tmp;
101 loizides 1.4 TObject::Fatal("At","Index too large: (%u < %u violated) for %s containing %s",
102 loizides 1.2 idx, fSize, GetName(), typeid(tmp).name());
103     return 0;
104 bendavid 1.1 }
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 loizides 1.3 if (idx<fSize)
113 bendavid 1.1 return fArray[idx];
114    
115 loizides 1.2 ArrayElement tmp;
116 loizides 1.4 TObject::Fatal("At","Index too large: (%u < %u violated) for %s containing %s",
117 loizides 1.2 idx, fSize, GetName(), typeid(tmp).name());
118     return 0;
119 bendavid 1.1 }
120    
121     //-------------------------------------------------------------------------------------------------
122     template<class ArrayElement, UInt_t N>
123 loizides 1.8 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 bendavid 1.1 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 loizides 1.2 inline ArrayElement mithep::StackArrayBasic<ArrayElement, N>::UncheckedAt(UInt_t idx)
153 bendavid 1.1 {
154     // Return entry at given index.
155    
156     return fArray[idx];
157     }
158    
159     //--------------------------------------------------------------------------------------------------
160     template<class ArrayElement, UInt_t N>
161 loizides 1.2 inline const ArrayElement mithep::StackArrayBasic<ArrayElement, N>::UncheckedAt(UInt_t idx) const
162 bendavid 1.1 {
163     // Return entry at given index.
164    
165     return fArray[idx];
166     }
167 loizides 1.2
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 bendavid 1.1 #endif