Logo ROOT   6.08/07
Reference Guide
TArrayF.h
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Rene Brun 06/03/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TArrayF
13 #define ROOT_TArrayF
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TArrayF //
19 // //
20 // Array of floats (32 bits per element). //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #ifndef ROOT_TArray
25 #include "TArray.h"
26 #endif
27 
28 
29 class TArrayF : public TArray {
30 
31 public:
32  Float_t *fArray; //[fN] Array of fN floats
33 
34  TArrayF();
35  TArrayF(Int_t n);
36  TArrayF(Int_t n, const Float_t *array);
37  TArrayF(const TArrayF &array);
38  TArrayF &operator=(const TArrayF &rhs);
39  virtual ~TArrayF();
40 
41  void Adopt(Int_t n, Float_t *array);
42  void AddAt(Float_t c, Int_t i);
43  Float_t At(Int_t i) const ;
44  void Copy(TArrayF &array) const {array.Set(fN,fArray);}
45  const Float_t *GetArray() const { return fArray; }
46  Float_t *GetArray() { return fArray; }
47  Double_t GetAt(Int_t i) const { return At(i); }
48  Stat_t GetSum() const {Stat_t sum=0; for (Int_t i=0;i<fN;i++) sum+=fArray[i]; return sum;}
49  void Reset() {memset(fArray, 0, fN*sizeof(Float_t));}
50  void Reset(Float_t val) {for (Int_t i=0;i<fN;i++) fArray[i] = val;}
51  void Set(Int_t n);
52  void Set(Int_t n, const Float_t *array);
53  void SetAt(Double_t v, Int_t i) { AddAt((Float_t)v, i); }
55  Float_t operator[](Int_t i) const;
56 
57  ClassDef(TArrayF,1) //Array of floats
58 };
59 
60 #if defined R__TEMPLATE_OVERLOAD_BUG
61 template <>
62 #endif
63 inline TBuffer &operator>>(TBuffer &buf, TArrayF *&obj)
64 {
65  // Read TArrayF object from buffer.
66 
67  obj = (TArrayF *) TArray::ReadArray(buf, TArrayF::Class());
68  return buf;
69 }
70 
71 #if defined R__TEMPLATE_OVERLOAD_BUG
72 template <>
73 #endif
74 inline TBuffer &operator<<(TBuffer &buf, const TArrayF *obj)
75 {
76  // Write a TArrayF object into buffer
77  return buf << (const TArray*)obj;
78 }
79 
80 inline Float_t TArrayF::At(Int_t i) const
81 {
82  if (!BoundsOk("TArrayF::At", i)) return 0;
83  return fArray[i];
84 }
85 
87 {
88  if (!BoundsOk("TArrayF::operator[]", i))
89  i = 0;
90  return fArray[i];
91 }
92 
94 {
95  if (!BoundsOk("TArrayF::operator[]", i)) return 0;
96  return fArray[i];
97 }
98 
99 #endif
Abstract array base class.
Definition: TArray.h:33
Float_t * GetArray()
Definition: TArrayF.h:46
Float_t * fArray
Definition: TArrayF.h:32
static long int sum(long int i)
Definition: Factory.cxx:1786
Float_t At(Int_t i) const
Definition: TArrayF.h:80
void AddAt(Float_t c, Int_t i)
Add float c at position i. Check for out of bounds.
Definition: TArrayF.cxx:93
Stat_t GetSum() const
Definition: TArrayF.h:48
const Float_t * GetArray() const
Definition: TArrayF.h:45
float Float_t
Definition: RtypesCore.h:53
return c
void Adopt(Int_t n, Float_t *array)
Adopt array arr into TArrayF, i.e.
Definition: TArrayF.cxx:81
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
Array of floats (32 bits per element).
Definition: TArrayF.h:29
int Int_t
Definition: RtypesCore.h:41
void Reset()
Definition: TArrayF.h:49
const char * Class
Definition: TXMLSetup.cxx:64
virtual ~TArrayF()
Delete TArrayF object.
Definition: TArrayF.cxx:71
#define ClassDef(name, id)
Definition: Rtypes.h:254
Bool_t BoundsOk(const char *where, Int_t at) const
Definition: TArray.h:79
Float_t & operator[](Int_t i)
Definition: TArrayF.h:86
TArrayF & operator=(const TArrayF &rhs)
TArrayF assignment operator.
Definition: TArrayF.cxx:61
Int_t fN
Definition: TArray.h:40
void Copy(TArrayF &array) const
Definition: TArrayF.h:44
SVector< double, 2 > v
Definition: Dict.h:5
static TArray * ReadArray(TBuffer &b, const TClass *clReq)
Read TArray object from buffer.
Definition: TArray.cxx:41
TBuffer & operator>>(TBuffer &buf, TArrayF *&obj)
Definition: TArrayF.h:63
void Reset(Float_t val)
Definition: TArrayF.h:50
friend TBuffer & operator<<(TBuffer &b, const TArray *obj)
Write TArray or derived object to buffer.
Definition: TArray.cxx:112
double Double_t
Definition: RtypesCore.h:55
void SetAt(Double_t v, Int_t i)
Definition: TArrayF.h:53
double Stat_t
Definition: RtypesCore.h:73
TArrayF()
Default TArrayF ctor.
Definition: TArrayF.cxx:26
void Set(Int_t n)
Set size of this array to n floats.
Definition: TArrayF.cxx:105
Double_t GetAt(Int_t i) const
Definition: TArrayF.h:47
const Int_t n
Definition: legend1.C:16