Logo ROOT   6.12/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 #include "TArray.h"
25 
26 
27 class TArrayF : public TArray {
28 
29 public:
30  Float_t *fArray; //[fN] Array of fN floats
31 
32  TArrayF();
33  TArrayF(Int_t n);
34  TArrayF(Int_t n, const Float_t *array);
35  TArrayF(const TArrayF &array);
36  TArrayF &operator=(const TArrayF &rhs);
37  virtual ~TArrayF();
38 
39  void Adopt(Int_t n, Float_t *array);
40  void AddAt(Float_t c, Int_t i);
41  Float_t At(Int_t i) const ;
42  void Copy(TArrayF &array) const {array.Set(fN,fArray);}
43  const Float_t *GetArray() const { return fArray; }
44  Float_t *GetArray() { return fArray; }
45  Double_t GetAt(Int_t i) const { return At(i); }
46  Stat_t GetSum() const {Stat_t sum=0; for (Int_t i=0;i<fN;i++) sum+=fArray[i]; return sum;}
47  void Reset() {memset(fArray, 0, fN*sizeof(Float_t));}
48  void Reset(Float_t val) {for (Int_t i=0;i<fN;i++) fArray[i] = val;}
49  void Set(Int_t n);
50  void Set(Int_t n, const Float_t *array);
51  void SetAt(Double_t v, Int_t i) { AddAt((Float_t)v, i); }
53  Float_t operator[](Int_t i) const;
54 
55  ClassDef(TArrayF,1) //Array of floats
56 };
57 
58 #if defined R__TEMPLATE_OVERLOAD_BUG
59 template <>
60 #endif
61 inline TBuffer &operator>>(TBuffer &buf, TArrayF *&obj)
62 {
63  // Read TArrayF object from buffer.
64 
65  obj = (TArrayF *) TArray::ReadArray(buf, TArrayF::Class());
66  return buf;
67 }
68 
69 #if defined R__TEMPLATE_OVERLOAD_BUG
70 template <>
71 #endif
72 inline TBuffer &operator<<(TBuffer &buf, const TArrayF *obj)
73 {
74  // Write a TArrayF object into buffer
75  return buf << (const TArray*)obj;
76 }
77 
78 inline Float_t TArrayF::At(Int_t i) const
79 {
80  if (!BoundsOk("TArrayF::At", i)) return 0;
81  return fArray[i];
82 }
83 
85 {
86  if (!BoundsOk("TArrayF::operator[]", i))
87  i = 0;
88  return fArray[i];
89 }
90 
92 {
93  if (!BoundsOk("TArrayF::operator[]", i)) return 0;
94  return fArray[i];
95 }
96 
97 #endif
Abstract array base class.
Definition: TArray.h:31
Float_t * GetArray()
Definition: TArrayF.h:44
Float_t * fArray
Definition: TArrayF.h:30
static long int sum(long int i)
Definition: Factory.cxx:2173
Float_t At(Int_t i) const
Definition: TArrayF.h:78
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:46
const Float_t * GetArray() const
Definition: TArrayF.h:43
float Float_t
Definition: RtypesCore.h:53
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:40
Array of floats (32 bits per element).
Definition: TArrayF.h:27
int Int_t
Definition: RtypesCore.h:41
void Reset()
Definition: TArrayF.h:47
virtual ~TArrayF()
Delete TArrayF object.
Definition: TArrayF.cxx:71
#define ClassDef(name, id)
Definition: Rtypes.h:320
void Class()
Definition: Class.C:29
Bool_t BoundsOk(const char *where, Int_t at) const
Definition: TArray.h:77
Float_t & operator[](Int_t i)
Definition: TArrayF.h:84
TArrayF & operator=(const TArrayF &rhs)
TArrayF assignment operator.
Definition: TArrayF.cxx:61
Int_t fN
Definition: TArray.h:38
void Copy(TArrayF &array) const
Definition: TArrayF.h:42
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:61
void Reset(Float_t val)
Definition: TArrayF.h:48
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:51
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:45
const Int_t n
Definition: legend1.C:16