]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDtrapAlu.cxx
Removing warnings on gcc 4.3
[u/mrichter/AliRoot.git] / TRD / AliTRDtrapAlu.cxx
index b10d0abb74461a945c97915300a20af401f424ca..005cdca549c0283a40233d086eb56435f62a3616 100644 (file)
@@ -1,19 +1,46 @@
+/**************************************************************************\r
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
+*                                                                        *\r
+* Author: The ALICE Off-line Project.                                    *\r
+* Contributors are mentioned in the code where appropriate.              *\r
+*                                                                        *\r
+* Permission to use, copy, modify and distribute this software and its   *\r
+* documentation strictly for non-commercial purposes is hereby granted   *\r
+* without fee, provided that the above copyright notice appears in all   *\r
+* copies and that both the copyright notice and this permission notice   *\r
+* appear in the supporting documentation. The authors make no claims     *\r
+* about the suitability of this software for any purpose. It is          *\r
+* provided "as is" without express or implied warranty.                  *\r
+**************************************************************************/\r
+\r
+/* $Id: AliTRDtrapAlu.cxx 25891 2008-05-19 14:58:18Z fca $ */\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+//                                                                           //\r
+//  TRAP-ALU implementation                                                  //\r
+//                                                                           //\r
+//  Author:                                                                  //\r
+//    Clemens Haltebourg <halteb@physi.uni-heidelberg.de>                    //\r
+//                                                                           //\r
+//  Usage of the class:                                                      //\r
+//    Declaration of class instances: AliTRDtrapAlu a,b,c;                   //\r
+//    Initialization:                 a.Init(2,11); b.Init(4,4); c.Init(5,4);//\r
+//    Assigning values:               a.AssignDouble(5.7); b.AssignInt(3);   //\r
+//    (you can also do b.AssignDouble(3) with same effect);                  //\r
+//    Calculation:                     c = a*b;                              //\r
+//    Test if c has right value:       c.WriteWord();                        //\r
+//    Don't declare pointers; operators not overridden for pointer types;    //\r
+//    You have to dereference yourself;                                      //\r
+//    Use operators +,-,*,/ only with instances of the class; don't do       //\r
+//    things like c=a*2 but rather b.AssignInt(2); c=a*b;                    //\r
+//                                                                           //\r
+///////////////////////////////////////////////////////////////////////////////\r
+\r
 #include "AliTRDtrapAlu.h"\r
 \r
 ClassImp(AliTRDtrapAlu)\r
 \r
-//usage of the class: \r
-//declaration of class instances:   AliTRDtrapAlu a,b,c;\r
-//initialization:                  a.Init(2,11); b.Init(4,4); c.Init(5,4);\r
-//assigning values:                a.AssignDouble(5.7); b.AssignInt(3);(you can also do b.AssignDouble(3) with same effect);\r
-//calculation:                     c = a*b;  \r
-//test if c has right value:       c.WriteWord();\r
-//don't declare pointers; operators not overridden for pointer types; you have to dereference yourself;\r
-//use operators +,-,*,/ only with instances of the class; don't do things like c=a*2 but rather b.AssignInt(2); c=a*b;\r
-\r
-\r
-\r
-  \r
+//_____________________________________________________________________________  \r
 AliTRDtrapAlu::AliTRDtrapAlu():TObject()\r
 \r
   ,fValue(0)\r
@@ -25,18 +52,16 @@ AliTRDtrapAlu::AliTRDtrapAlu():TObject()
 \r
 {\r
   \r
- // default constructor\r
\r
\r
+  // default constructor\r
+  \r
 }\r
 \r
-\r
+//_____________________________________________________________________________  \r
 AliTRDtrapAlu::~AliTRDtrapAlu(){\r
   //destructor\r
 }\r
 \r
-\r
-\r
+//_____________________________________________________________________________  \r
 void AliTRDtrapAlu::Init(const Int_t& precom, const Int_t& postcom, const Int_t& lRestriction, const Int_t& uRestriction){\r
    // initialization: characterizes the bit-word (nr of pre- and post-comma bits, boundaries)\r
    fPostCom = postcom;\r
@@ -56,7 +81,7 @@ void AliTRDtrapAlu::Init(const Int_t& precom, const Int_t& postcom, const Int_t&
    // up to now you can only choose a non-negative lower restriction (e.g. if you want your values to be >=0) ; can't deal with asymmetric borders; have to be implemented if needed\r
 }\r
 \r
-\r
+//_____________________________________________________________________________  \r
 Double_t AliTRDtrapAlu::GetValueWhole() const { \r
    // get the actual value (respecting pre- and post-comma parts) in integer-description\r
    Double_t valPre = (Double_t)(fValue>>fPostCom);\r
@@ -70,7 +95,7 @@ Double_t AliTRDtrapAlu::GetValueWhole() const {
    return val;\r
  }\r
 \r
-\r
+//_____________________________________________________________________________  \r
 void AliTRDtrapAlu::WriteWord(){\r
   // for debugging purposes\r
   printf("bit-word: ");\r
@@ -86,10 +111,7 @@ void AliTRDtrapAlu::WriteWord(){
          \r
 }\r
 \r
-\r
-\r
-\r
-\r
+//_____________________________________________________________________________  \r
 AliTRDtrapAlu& AliTRDtrapAlu::AssignInt(const Int_t& first){  \r
   // assign an integer\r
 \r
@@ -108,7 +130,7 @@ AliTRDtrapAlu& AliTRDtrapAlu::AssignInt(const Int_t& first){
     \r
     //setting fValue to maximum; first was to big\r
     fValue  = fuRestriction;\r
-    fValue  = fValue & LUT(exponent)-1;\r
+    fValue  = fValue & (LUT(exponent)-1);\r
     return *this;\r
   }\r
 \r
@@ -116,19 +138,20 @@ AliTRDtrapAlu& AliTRDtrapAlu::AssignInt(const Int_t& first){
     \r
     //setting fValue to minimum; first was to small\r
     fValue  = flRestriction;\r
-    fValue  = fValue & LUT(exponent)-1;\r
+    fValue  = fValue & (LUT(exponent)-1);\r
     return *this;\r
   }\r
 \r
   \r
   fValue  = first;\r
   fValue  = fValue<<fPostCom; \r
-  fValue  = fValue & LUT(exponent)-1;\r
+  fValue  = fValue & (LUT(exponent)-1);\r
  \r
   return *this;\r
     \r
 }\r
 \r
+//_____________________________________________________________________________  \r
 AliTRDtrapAlu& AliTRDtrapAlu::AssignDouble(const  Double_t& first){\r
   // assign a double\r
  \r
@@ -182,7 +205,7 @@ AliTRDtrapAlu& AliTRDtrapAlu::AssignDouble(const  Double_t& first){
   return *this;\r
 }\r
 \r
-\r
+//_____________________________________________________________________________  \r
 AliTRDtrapAlu& AliTRDtrapAlu::operator=(const AliTRDtrapAlu& binary){\r
   // assign an object of type AliTRDtrapAlu\r
 \r
@@ -249,13 +272,13 @@ AliTRDtrapAlu& AliTRDtrapAlu::operator=(const AliTRDtrapAlu& binary){
   return *this;\r
 }\r
 \r
-\r
-\r
-AliTRDtrapAlu& AliTRDtrapAlu::operator+(AliTRDtrapAlu& binary){ \r
+//_____________________________________________________________________________  \r
+AliTRDtrapAlu AliTRDtrapAlu::operator+(const AliTRDtrapAlu& binary){ \r
   // + operator\r
 \r
   //no const parameter because referenced object will be changed\r
      \r
+    AliTRDtrapAlu alu;\r
   \r
   Int_t binPre     = binary.GetPre();\r
   Int_t binPost    = binary.GetPost();\r
@@ -272,7 +295,7 @@ AliTRDtrapAlu& AliTRDtrapAlu::operator+(AliTRDtrapAlu& binary){
   if(fSigned == kTRUE) add2 = -add2;\r
   Int_t add = add1 + add2;\r
   \r
-  \r
+  /*\r
   //because the parameter "binary" could be a reference to the object to which Mem() is a reference, do not change Mem() until you have extracted all information from "binary"; otherwise you change the information you would like to read\r
   Mem().Init(max + 1,min);      //buffer: enough space for pre-comma,post-comma according to accuracy\r
   Mem().AssignFormatted(Max(add,-add));\r
@@ -280,13 +303,22 @@ AliTRDtrapAlu& AliTRDtrapAlu::operator+(AliTRDtrapAlu& binary){
   \r
 \r
   //Mem().FastInit(max+1,min,add);\r
-  return Mem();\r
-}\r
+  return Mem();*/\r
\r
+ alu.Init(max + 1,min);      //buffer: enough space for pre-comma,post-comma according to accuracy\r
+ alu.AssignFormatted(Max(add,-add));\r
+ alu.SetSign(add);\r
\r
+ return alu;\r
 \r
+}\r
 \r
-AliTRDtrapAlu& AliTRDtrapAlu::operator-(AliTRDtrapAlu& binary){\r
+//_____________________________________________________________________________  \r
+AliTRDtrapAlu AliTRDtrapAlu::operator-(const AliTRDtrapAlu& binary){\r
   // - operator    \r
 \r
+    AliTRDtrapAlu alu;\r
+\r
   Int_t binPre    = binary.GetPre();\r
   Int_t binPost   = binary.GetPost();\r
   Int_t binVal    = binary.GetValue();\r
@@ -303,18 +335,26 @@ AliTRDtrapAlu& AliTRDtrapAlu::operator-(AliTRDtrapAlu& binary){
   if(fSigned  == kTRUE) sub2 = -sub2;\r
   Int_t sub = sub2 - sub1;     // order of subtraction is important\r
  \r
-\r
+/*\r
   Mem().Init(max + 1,min);      //buffer: enough space for pre-comma, post-comma according to accuracy\r
   Mem().AssignFormatted(Max(sub,-sub)); \r
   Mem().SetSign(sub);\r
   //Mem().FastInit(max+1,min,sub);\r
-  return Mem();\r
-} \r
+  return Mem();*/\r
+  \r
+  alu.Init(max + 1,min);\r
+  alu.AssignFormatted(Max(sub,-sub)); \r
+  alu.SetSign(sub);\r
+\r
+  return alu;\r
 \r
+} \r
 \r
-AliTRDtrapAlu& AliTRDtrapAlu::operator*(AliTRDtrapAlu& binary){\r
+//_____________________________________________________________________________  \r
+AliTRDtrapAlu AliTRDtrapAlu::operator*(const AliTRDtrapAlu& binary){\r
   // * operator\r
   \r
+    AliTRDtrapAlu alu;\r
 \r
   Int_t binPre   = binary.GetPre();\r
   Int_t binPost  = binary.GetPost();\r
@@ -341,6 +381,8 @@ AliTRDtrapAlu& AliTRDtrapAlu::operator*(AliTRDtrapAlu& binary){
   mult = Max(mult,-mult);\r
   //Int_t shift = fPostCom + binPost - min;\r
   //mult = mult>>(shift);\r
+\r
+/*\r
   Mem().Init(2 * max + 1, min); // +1 to consider the borrow from the past-comma part; accuracy of past-comma part is determined by the minimum; therefore, for the result not more accuracy is guaranteed\r
   // be aware that this only works if 2*max+1+min <= 32!! adjusting the pre-comma place to the value would consume too much time\r
 \r
@@ -348,14 +390,22 @@ AliTRDtrapAlu& AliTRDtrapAlu::operator*(AliTRDtrapAlu& binary){
   Mem().SetSign(sign);\r
   //mult = sign*mult;\r
   //Mem().FastInit(2*max+1,min,mult);\r
-  return Mem();\r
-}\r
+  return Mem();*/\r
   \r
+  alu.Init(2 * max + 1, min); // +1 to consider the borrow from the past-comma part; accuracy of past-comma part is determined by the minimum; therefore, for the result not more accuracy is guaranteed\r
+// be aware that this only works if 2*max+1+min <= 32!! adjusting the pre-comma place to the value would consume too much time\r
 \r
-\r
-AliTRDtrapAlu& AliTRDtrapAlu::operator/(AliTRDtrapAlu& binary){\r
+  alu.AssignFormatted(mult);\r
+  alu.SetSign(sign);\r
+  \r
+  return alu;\r
+}\r
+  \r
+//_____________________________________________________________________________  \r
+AliTRDtrapAlu AliTRDtrapAlu::operator/(const AliTRDtrapAlu& binary){\r
   // / operator\r
  \r
+    AliTRDtrapAlu alu;\r
 \r
   Int_t binPre  = binary.GetPre();\r
   Int_t binPost = binary.GetPost();\r
@@ -377,10 +427,13 @@ AliTRDtrapAlu& AliTRDtrapAlu::operator/(AliTRDtrapAlu& binary){
   \r
 \r
   if (div1 == 0){\r
-    Mem().Init(max + 1,min);\r
+      /*Mem().Init(max + 1,min);\r
     Mem().AssignFormatted(LUT(max+min+1)-1); // division by 0: set to max value\r
     //Mem().FastInit(max+1,min,div1);\r
-    return Mem();\r
+    return Mem();*/\r
+      alu.Init(max + 1,min);\r
+      alu.AssignFormatted(LUT(max+min+1)-1); // division by 0: set to max value\r
+      return alu;\r
   }\r
       \r
   fdiv = (Double_t)numerator/denominator;\r
@@ -409,16 +462,23 @@ AliTRDtrapAlu& AliTRDtrapAlu::operator/(AliTRDtrapAlu& binary){
   div = Max(div,-div);\r
   \r
   // chose min as past-comma part because from a division of integers you can't get only an integer\r
-  Mem().Init(max + 1,min); // max+1+min must <= 32!!\r
+  \r
+  /*Mem().Init(max + 1,min); // max+1+min must <= 32!!\r
   Mem().SetSign(sign);\r
   Mem().AssignFormatted(div);\r
   \r
-  return Mem();\r
-  \r
-}\r
+  return Mem();*/\r
 \r
+  alu.Init(max + 1,min); // max+1+min must <= 32!!\r
+  alu.SetSign(sign);\r
+  alu.AssignFormatted(div);\r
+  \r
+  return alu;\r
 \r
+  \r
+}\r
 \r
+//_____________________________________________________________________________  \r
 Int_t AliTRDtrapAlu::MakePower(const Int_t& base,const  Int_t& exponent)const{\r
 // calculate "base" to the power of "exponent"\r
   Int_t result = 1;\r
@@ -429,12 +489,12 @@ Int_t AliTRDtrapAlu::MakePower(const Int_t& base,const  Int_t& exponent)const{
   return result;\r
 }\r
 \r
-\r
-\r
-\r
+//_____________________________________________________________________________  \r
 Int_t AliTRDtrapAlu::LUT(const Int_t& index){   \r
   // simple look-up table for base=2\r
   \r
+    AliTRDtrapAlu alu;\r
+\r
   static Bool_t fLUT = kFALSE;\r
   static Int_t gLUT[30];\r
   if (fLUT == kFALSE) {\r
@@ -449,6 +509,7 @@ Int_t AliTRDtrapAlu::LUT(const Int_t& index){
   }\r
   else {\r
     \r
-    return Mem().MakePower(2,index);\r
+      //return Mem().MakePower(2,index);\r
+      return alu.MakePower(2,index);\r
   }\r
 }\r