]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Added optimised color lookup function/cache; do not alow threshold to overrun maxval...
authormtadel <mtadel@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 14 Jun 2006 20:28:04 +0000 (20:28 +0000)
committermtadel <mtadel@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 14 Jun 2006 20:28:04 +0000 (20:28 +0000)
EVE/Alieve/TPCSectorViz.cxx
EVE/Alieve/TPCSectorViz.h

index 2f0d631f8fb5a842db3094af382ee02a47aed93f..6d03c7b0342e48097b70b9a14a34c0437bcf7d68 100644 (file)
@@ -41,12 +41,15 @@ TPCSectorViz::TPCSectorViz(const Text_t* n, const Text_t* t) :
   fFrameColor ((Color_t) 4),
   fRnrFrame (kTRUE),
   fTrans    (kFALSE),
-  fRTS      (1)
+  fRTS      (1),
+
+  fColorArray (0)
 {}
 
 TPCSectorViz::~TPCSectorViz()
 {
   if(fTPCData) fTPCData->DecRefCount();
+  delete [] fColorArray;
 }
 
 void TPCSectorViz::CopyVizParams(const TPCSectorViz& v)
@@ -89,6 +92,22 @@ TPCSectorData* TPCSectorViz::GetSectorData() const
 
 /**************************************************************************/
 
+void TPCSectorViz::SetThreshold(Short_t t)
+{
+  fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
+  ClearColorArray();
+  IncRTS();
+}
+
+void TPCSectorViz::SetMaxVal(Int_t mv)
+{
+  fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
+  ClearColorArray();
+  IncRTS();
+}
+
+/**************************************************************************/
+
 void TPCSectorViz::SetTrans(Bool_t trans) 
 {
   fTrans = trans;
@@ -124,3 +143,22 @@ void TPCSectorViz::SetupColor(Int_t val, UChar_t* pixel) const
 
   ColorFromIdx(gStyle->GetColorPalette(Min(nCol - 1, cBin)), pixel);
 }
+
+void TPCSectorViz::ClearColorArray()
+{
+  if(fColorArray) {
+    delete [] fColorArray;
+    fColorArray = 0;
+  }
+}
+
+void TPCSectorViz::SetupColorArray() const
+{
+  if(fColorArray)
+    return;
+
+  fColorArray = new UChar_t [4 * (fMaxVal - fThreshold + 1)];
+  UChar_t* p = fColorArray;
+  for(Int_t v=fThreshold; v<=fMaxVal; ++v, p+=4)
+    SetupColor(v, p);
+}
index 9fc1b7403d3f4ac70624d5d9f3631f182ae0b81d..a2e75e2bf6a0dec56c7ccec00de117481113eace 100644 (file)
@@ -50,6 +50,12 @@ protected:
 
   void SetupColor(Int_t val, UChar_t* pix) const;
 
+  mutable UChar_t* fColorArray;
+  void ClearColorArray();
+  void SetupColorArray() const;
+  UChar_t* ColorFromArray(Int_t val) const;
+  void     ColorFromArray(Int_t val, UChar_t* pix) const;
+
 public:
   TPCSectorViz(const Text_t* n="TPCSectorViz", const Text_t* t=0);
   virtual ~TPCSectorViz();
@@ -68,8 +74,8 @@ public:
 
   void SetMinTime(Int_t mt)    { fMinTime   = mt; IncRTS(); }
   void SetMaxTime(Int_t mt)    { fMaxTime   = mt; IncRTS(); }
-  void SetThreshold(Short_t t) { fThreshold =  t; IncRTS(); }
-  void SetMaxVal(Int_t mv)     { fMaxVal    = mv; IncRTS(); }
+  void SetThreshold(Short_t t);
+  void SetMaxVal(Int_t mv);
 
   void SetRnrInn(Bool_t r)     { fRnrInn  = r; IncRTS(); }
   void SetRnrOut1(Bool_t r)    { fRnrOut1 = r; IncRTS(); }
@@ -82,6 +88,20 @@ public:
   ClassDef(TPCSectorViz, 1); // Base-class for TPC raw-data visualization
 }; // endclass TPCSectorViz
 
+
+inline UChar_t* TPCSectorViz::ColorFromArray(Int_t val) const
+{
+  if(val < fThreshold) val = fThreshold;
+  if(val > fMaxVal)    val = fMaxVal;
+  return fColorArray + 4 * (val - fThreshold);
+}
+
+inline void TPCSectorViz::ColorFromArray(Int_t val, UChar_t* pix) const
+{
+  UChar_t* c = ColorFromArray(val);
+  pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2]; pix[3] = c[3];
+}
+
 }
 
 #endif