+/**************************************************************************\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
\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
// 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
return val;\r
}\r
\r
-\r
+//_____________________________________________________________________________ \r
void AliTRDtrapAlu::WriteWord(){\r
// for debugging purposes\r
printf("bit-word: ");\r
\r
}\r
\r
-\r
-\r
-\r
-\r
+//_____________________________________________________________________________ \r
AliTRDtrapAlu& AliTRDtrapAlu::AssignInt(const Int_t& first){ \r
// assign an integer\r
\r
\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
\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
return *this;\r
}\r
\r
-\r
+//_____________________________________________________________________________ \r
AliTRDtrapAlu& AliTRDtrapAlu::operator=(const AliTRDtrapAlu& binary){\r
// assign an object of type AliTRDtrapAlu\r
\r
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
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
\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
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
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
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
\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
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
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
}\r
else {\r
\r
- return Mem().MakePower(2,index);\r
+ //return Mem().MakePower(2,index);\r
+ return alu.MakePower(2,index);\r
}\r
}\r