GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Spin.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #ifndef GW_SPIN_H
24 #define GW_Spin
25 #define GW_SPIN_H Gw_Spin
26 
27 // GW includes
28 #ifndef GW_QNUMBER_H
29 #include "QNumber.h"
30 #endif
31 
32 #ifndef GW_INFODATA_H
33 #include "InfoData.h"
34 #endif
35 
36 // std includes
37 #include <iostream>
38 
39 namespace Gw {
40 
46 class Spin : public QNumber, public InfoData
47 {
48 public:
49  //friend bool operator> (Spin &S1, Spin &S2);
50  //friend bool operator<= (Spin &S1, Spin &S2);
51 
52  //friend bool operator< (Spin &S1, Spin &S2);
53  //friend bool operator>= (Spin &S1, Spin &S2);
54 
55 protected:
56  Int_t fN; // numerator
57  Int_t fD; // denominator - should be 1 or 2 for a spin
58 
59 public:
60  Spin();
61  Spin(Int_t, Int_t);
62  Spin(const Spin &spin): QNumber(spin), InfoData(spin) { fN = spin.fN; fD = spin.fD; }
63  virtual ~Spin();
64 
66  void Set(Int_t n, Int_t d = 1);
68  Float_t Get() const;
70  const Char_t* GetString() const;
72  Bool_t IsHalfInt() const { return fD == 2; }
73 
75  Int_t GetN() const { return fN; }
77  Int_t GetD() const { return fD; }
78 
80  Int_t GetInTwoHalfUnit() const
81  {
82  if ( fD == 1 )
83  return 2*fN;
84  return fN;
85  }
86 
88  virtual void Set(const char *s) ;
89 
91  virtual Bool_t IsQNumber(QNumber::EQtype) const;
92 
93 // some operators
95  Spin& operator+=(Int_t value);
97  {
98  fN += fD;
99  return *this;
100  }
102  {
103  Spin result(*this);
104  operator++();
105  return result;
106  }
108  {
109  fN -= fD;
110  return *this;
111  }
113  {
114  Spin result(*this);
115  operator--();
116  return result;
117  }
118 
120  {
121  Spin result(*this);
122  result.Set(-fN,fD);
123 
124  return result;
125  }
126 
128  Spin& operator+=(Spin sp);
129 
131  bool operator == (const Spin &s) const
132  {
133  if ( fN == s.fN && fD == s.fD )
134  return true;
135 
136  return false;
137  }
138  bool operator<= (const Spin &s) const
139  {
140  if ( fN == s.fN && fD == s.fD )
141  return true;
142 
143  return Get() <= s.Get();
144  }
145  bool operator< (const Spin &s) const
146  {
147  return Get() < s.Get();
148  }
149  bool operator>= (const Spin &s) const
150  {
151  if ( fN == s.fN && fD == s.fD )
152  return true;
153 
154  return Get() >= s.Get();
155  }
156  bool operator> (const Spin &s) const
157  {
158  return Get() > s.Get();
159  }
160 
162  ClassDef(Spin,1); // a Spin
163 };
164 // inline members
165 inline Bool_t Spin::IsQNumber(QNumber::EQtype t) const { return kSpin == t; }
166 inline Float_t Spin::Get() const { return Float_t(fN) / fD; }
167 
168 // friend bool operator> (Spin &S1, Spin &S2);
169 //inline bool operator<= (Spin &S1, Spin &S2){}
170 
171 // friend bool operator< (Spin &S1, Spin &S2);
172 // friend bool operator>= (Spin &S1, Spin &S2);
173 }
174 
176 std::ostream & operator << (std::ostream &, const Gw::Spin &);
177 
178 #endif
Spin operator++(int)
Definition: Spin.h:101
void Set(Int_t n, Int_t d=1)
To set the spin.
Definition: Spin.cpp:124
header file for InfoData
ClassDef(Spin, 1)
rootcint dictionary
bool operator<=(const Spin &s) const
Definition: Spin.h:138
Spin & operator++()
Definition: Spin.h:96
Int_t GetD() const
To get the spin (denominator)
Definition: Spin.h:77
bool operator>(const Spin &s) const
Definition: Spin.h:156
std::ostream & operator<<(std::ostream &, const Gw::Spin &)
to write a Spin in a stream
Definition: Spin.cpp:151
Base class for a quantum number.
Definition: QNumber.h:43
EQtype
label type for any possible quantum number
Definition: QNumber.h:47
Spin & operator--()
Definition: Spin.h:107
Float_t Get() const
To get the spin as a float.
Definition: Spin.h:166
virtual ~Spin()
Definition: Spin.cpp:51
bool operator>=(const Spin &s) const
Definition: Spin.h:149
UInt_t value[MaxValue]
Definition: ReadDaqAlone.C:29
A spin is defined by two integers: a numerator and a denominator.
Definition: Spin.h:46
Int_t fD
Definition: Spin.h:57
Int_t GetInTwoHalfUnit() const
to get the spin in two half unit
Definition: Spin.h:80
bool operator==(const Spin &s) const
comparison
Definition: Spin.h:131
Int_t fN
Definition: Spin.h:56
Spin & operator+=(Int_t value)
operator +=
Definition: Spin.cpp:134
const Char_t * GetString() const
To get the spin as a string.
Definition: Spin.cpp:55
Bool_t IsHalfInt() const
To get the spin as a float.
Definition: Spin.h:72
Spin()
Definition: Spin.cpp:39
Base class to get/set some flag informations concerning any data.
Definition: InfoData.h:46
header file for a general quantum number (QNumber)
virtual Bool_t IsQNumber(QNumber::EQtype) const
QNumber members.
Definition: Spin.h:165
Int_t GetN() const
To get the spin (numerator)
Definition: Spin.h:75
bool operator<(const Spin &s) const
Definition: Spin.h:145
Spin(const Spin &spin)
Definition: Spin.h:62
Spin operator-() const
Definition: Spin.h:119
Spin operator--(int)
Definition: Spin.h:112