Logo ROOT  
Reference Guide
TArrayS.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_TArrayS
13 #define ROOT_TArrayS
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TArrayS //
19 // //
20 // Array of shorts (16 bits per element). //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TArray.h"
25 
26 
27 class TArrayS : public TArray {
28 
29 public:
30  Short_t *fArray; //[fN] Array of fN shorts
31 
32  TArrayS();
33  TArrayS(Int_t n);
34  TArrayS(Int_t n, const Short_t *array);
35  TArrayS(const TArrayS &array);
36  TArrayS &operator=(const TArrayS &rhs);
37  virtual ~TArrayS();
38 
39  void Adopt(Int_t n, Short_t *array);
40  void AddAt(Short_t c, Int_t i);
41  Short_t At(Int_t i) const ;
42  void Copy(TArrayS &array) const {array.Set(fN,fArray);}
43  const Short_t *GetArray() const { return fArray; }
44  Short_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(Short_t));}
48  void Reset(Short_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 Short_t *array);
51  void SetAt(Double_t v, Int_t i) { AddAt((Short_t)v, i); }
53  Short_t operator[](Int_t i) const;
54 
55  ClassDef(TArrayS,1) //Array of shorts
56 };
57 
58 #if defined R__TEMPLATE_OVERLOAD_BUG
59 template <>
60 #endif
61 inline TBuffer &operator>>(TBuffer &buf, TArrayS *&obj)
62 {
63  // Read TArrayS object from buffer.
64 
65  obj = (TArrayS *) TArray::ReadArray(buf, TArrayS::Class());
66  return buf;
67 }
68 
69 #if defined R__TEMPLATE_OVERLOAD_BUG
70 template <>
71 #endif
72 inline TBuffer &operator<<(TBuffer &buf, const TArrayS *obj)
73 {
74  // Write a TArrayS object into buffer
75  return buf << (const TArray*)obj;
76 }
77 
78 inline Short_t TArrayS::At(Int_t i) const
79 {
80  if (!BoundsOk("TArrayS::At", i)) return 0;
81  return fArray[i];
82 }
83 
85 {
86  if (!BoundsOk("TArrayS::operator[]", i))
87  i = 0;
88  return fArray[i];
89 }
90 
92 {
93  if (!BoundsOk("TArrayS::operator[]", i)) return 0;
94  return fArray[i];
95 }
96 
97 #endif
c
#define c(i)
Definition: RSha256.hxx:101
TArrayS::GetArray
const Short_t * GetArray() const
Definition: TArrayS.h:43
TArrayS::Reset
void Reset(Short_t val)
Definition: TArrayS.h:48
n
const Int_t n
Definition: legend1.C:16
TArrayS
Array of shorts (16 bits per element).
Definition: TArrayS.h:27
TArrayS::At
Short_t At(Int_t i) const
Definition: TArrayS.h:78
Int_t
int Int_t
Definition: RtypesCore.h:45
TArrayS::GetArray
Short_t * GetArray()
Definition: TArrayS.h:44
TArrayS::fArray
Short_t * fArray
Definition: TArrayS.h:30
TBuffer
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
TArray::fN
Int_t fN
Definition: TArray.h:38
v
@ v
Definition: rootcling_impl.cxx:3635
TArrayS::GetSum
Stat_t GetSum() const
Definition: TArrayS.h:46
TArrayS::GetAt
Double_t GetAt(Int_t i) const
Definition: TArrayS.h:45
TArrayS::operator=
TArrayS & operator=(const TArrayS &rhs)
TArrayS assignment operator.
Definition: TArrayS.cxx:61
TArrayS::~TArrayS
virtual ~TArrayS()
Delete TArrayS object.
Definition: TArrayS.cxx:71
TArrayS::Copy
void Copy(TArrayS &array) const
Definition: TArrayS.h:42
operator<<
TBuffer & operator<<(TBuffer &buf, const TArrayS *obj)
Definition: TArrayS.h:72
Short_t
short Short_t
Definition: RtypesCore.h:39
TArrayS::TArrayS
TArrayS()
Default TArrayS ctor.
Definition: TArrayS.cxx:26
TArrayS::AddAt
void AddAt(Short_t c, Int_t i)
Add short c at position i. Check for out of bounds.
Definition: TArrayS.cxx:93
TArray::ReadArray
static TArray * ReadArray(TBuffer &b, const TClass *clReq)
Read TArray object from buffer.
Definition: TArray.cxx:41
sum
static long int sum(long int i)
Definition: Factory.cxx:2272
Double_t
double Double_t
Definition: RtypesCore.h:59
TArrayS::SetAt
void SetAt(Double_t v, Int_t i)
Definition: TArrayS.h:51
TArray
Abstract array base class.
Definition: TArray.h:31
TArray::BoundsOk
Bool_t BoundsOk(const char *where, Int_t at) const
Definition: TArray.h:77
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TArrayS::operator[]
Short_t & operator[](Int_t i)
Definition: TArrayS.h:84
TArrayS::Set
void Set(Int_t n)
Set size of this array to n shorts.
Definition: TArrayS.cxx:105
TArray.h
TArrayS::Reset
void Reset()
Definition: TArrayS.h:47
Stat_t
double Stat_t
Definition: RtypesCore.h:77
Class
void Class()
Definition: Class.C:29
operator>>
TBuffer & operator>>(TBuffer &buf, TArrayS *&obj)
Definition: TArrayS.h:61
TArrayS::Adopt
void Adopt(Int_t n, Short_t *array)
Adopt array arr into TArrayS, i.e.
Definition: TArrayS.cxx:81
int