StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MIntArray.cc
1 // $Id: MIntArray.cc,v 1.5 2003/09/16 15:27:01 jcs Exp $
2 // $Log: MIntArray.cc,v $
3 // Revision 1.5 2003/09/16 15:27:01 jcs
4 // removed inline as it would leave a few undefined reference
5 //
6 // Revision 1.4 2001/07/12 08:24:11 oldi
7 // New function CountAppearance() introduced.
8 //
9 // Revision 1.3 2000/11/10 18:32:36 oldi
10 // Introduced new function ShiftByOneAndAddAtFirst(Int_t value).
11 // Cleanup.
12 //
13 // Revision 1.2 2000/07/18 21:22:14 oldi
14 // Changes due to be able to find laser tracks.
15 // Cleanup: - new functions in StFtpcConfMapper, StFtpcTrack, and StFtpcPoint
16 // to bundle often called functions
17 // - short functions inlined
18 // - formulas of StFormulary made static
19 // - avoid streaming of objects of unknown size
20 // (removes the bunch of CINT warnings during compile time)
21 // - two or three minor bugs cured
22 //
23 // Revision 1.1 2000/05/10 13:39:00 oldi
24 // Initial version of StFtpcTrackMaker
25 //
26 
27 //----------Author: Markus D. Oldenburg
28 //----------Last Modified: 18.10.2000
29 //----------Copyright: &copy MDO Production 2000
30 
31 #include "MIntArray.h"
32 
34 // //
35 // MIntArray class - this class extends the possibilities of the usual TArrayI //
36 // //
38 
39 ClassImp(MIntArray)
40 
42 {
43  // Constructer.
44  // Has nothing to do.
45 
46  fN = 0;
47  Set(0);
48 }
49 
50 
51 MIntArray::~MIntArray()
52 {
53  // Destructor.
54  // Has nothing to do.
55 }
56 
57 
58 void MIntArray::ShiftByOneAndAddAtFirst(Int_t value)
59 {
60  // Shifts every array element in the next slot and adds the value in the first slot.
61 
62  Set(GetSize() + 1);
63 
64  {for (Int_t i = GetSize() - 2; i >= 0; i--) {
65  AddAt(At(i), i+1);
66  }}
67 
68  AddAt(value, 0);
69 
70  return;
71 }
72 
73 
74 Int_t MIntArray::CountAppearance(Int_t value)
75 {
76  // Loops over array and counts appearances of 'value'.
77 
78  Int_t result = 0;
79 
80  {for (Int_t i = 0; i < GetSize(); i++) {
81 
82  if (At(i) == value) {
83  result++;
84  }
85  }}
86 
87  return result;
88 }
89 
90 void MIntArray::AddLast(Int_t value)
91 {
92  // Adds the value after the last entry of the array.
93  // Therefore the array size has to be increased by one.
94 
95  Set(GetSize() + 1);
96  AddAt(value, GetSize() - 1);
97 }
98 
99 
100 Int_t MIntArray::AtLast()
101 {
102  // Returns the value of the last array element.
103 
104  return At(GetSize()-1);
105 }
106 
107 
108 Int_t MIntArray::AtFirst()
109 {
110  // Returns the value of the last array element.
111 
112  return At(0);
113 }
114 
115 
116 void MIntArray::Fill(Int_t value)
117 {
118  // Fills the whole array with the value 'value'.
119 
120  for (Int_t i = 0; i < GetSize(); AddAt(value, i), i++);
121 
122  return;
123 }
124 
125 
126 void MIntArray::SetFill(Int_t size, Int_t value)
127 {
128  // Set the array size to 'size' and fill the whole array with 'value'.
129 
130  if (GetSize() > 0) {
131  Set(0);
132  }
133 
134  for (Int_t i = 0; i < size; AddLast(value), i++);
135 
136  return;
137 }
138