ROOT logo
// @(#)root/table:$Id: TTable3Points.cxx 20882 2007-11-19 11:31:26Z rdm $
// Author: Valery Fine   10/05/99  (E-mail: fine@bnl.gov)

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TTable3Points.h"

///////////////////////////////////////////////////////////////////////////////////
//
//   TTable3Points class is to create 3D view of any 3 columns of the TTable objects
//   with one and the same "key column value".
//
//   For example all values of the column "x[0]" "x[1]" "x[2]" of the begin_html <a href="http://www.rhic.bnl.gov/STAR/html/comp_l/root/html/g2t_tpc_hit_st.html"> g2t_tpc_hit </a> end_html table
//   from the rows with one and same "track_id" column value will be regarded
//   as an image of one and the same "track".
//   The last means all those points will be painted with one and the same 3D
//   attributes like "color", "size", "style", "light","markers", "connections"  etc.
//
//   The original TTable object must be pre-sorted by "key column" via TTableSorter
//   class
//
// void   CreatePoints(Tg2t_tpc_hit *points)
// {
//   g2t_tpc_hit_st *p = points->GetTable();
//
//  TTable3Points *track = 0;
//  TString tr;
//  tr = "track_p";
//  TTable &ttt = *((TTable *)points);
//  // Track2Line MUST be on heap otherwise 3D view will crash just code leaves this
//  // subroutine
//  We will assemble all points by its "track_p" field.
//
//  TTableSorter *Track2Line = new TTableSorter (ttt,"track_p");
//
//  Int_t i = 0;
//  Char_t buffer[10];
//  Int_t ntracks = 0;
//  const Int_t maxtracks = 5;
////---------------------------- Fill tracks -------------------
//  long currentId = -1;
//  long newId =  0;
//  g2t_tpc_hit_st *hitPoint = 0;
//  TVolume *thisTrack[7] = {0,0,0,0,0,0,0}; // seven volumes for 7 different colors
//  Int_t  MaxRowtoCount = 5000; // 5000;
//  Int_t  MaxTracks = Track2Line->CountKeys();
//  MaxTracks = 100;
//  for (i=0;i<Track2Line->GetNRows() && ntracks <  MaxTracks ;i++)
//  {
//   hitPoint = p + Track2Line->GetIndex(i);
//   newId =  hitPoint->track_p;
//   if (newId != currentId)  { // The hit for the new track has been found
//
//     const Char_t *xName = "x[0]";
//     const Char_t *yName = "x[1]";
//     const Char_t *zName = "x[2]";
//
//     track =  new TTable3Points(Track2Line,(const void *)&newId,xName,yName,zName);
//
//     // Create a shape for this node
//     TPolyLineShape *trackShape  =  new TPolyLineShape(track);
//     trackShape->SetVisibility(1);
//     Int_t colorIndx = ntracks%7;
//     trackShape->SetColorAttribute(colorIndx+kGreen);
//     trackShape->SetLineStyle(1);
//     trackShape->SetSizeAttribute(2);
//     // Create a node to hold it
//     if (!thisTrack[colorIndx])  {
//         thisTrack[colorIndx] = new TVolume("hits","hits",trackShape);
//         thisTrack[colorIndx]->Mark();
//         thisTrack[colorIndx]->SetVisibility();
//         TVolumePosition *pp = hall->Add(thisTrack[colorIndx]);
//         if (!pp) printf(" no position %d\n",ntrack);
//     }
//     else
//       thisTrack[colorIndx]->Add(trackShape);
//     currentId = newId;
//     ntracks++;
//   }
// }
//
///////////////////////////////////////////////////////////////////////////////////

ClassImp(TTable3Points)

//________________________________________________________________________________
TTable3Points::TTable3Points():fColumnOffset(0)
{
   //to be documented
}

//________________________________________________________________________________
TTable3Points::TTable3Points(TTableSorter *sorter,const void *key,
                       const Char_t *xName, const Char_t *yName, const Char_t *zName
                      ,Option_t *opt)
                : TTablePoints(sorter,key,opt)

{
   //to be documented
   fColumnOffset =  new ULong_t [kTotalSize];
   SetXColumn(xName);  SetYColumn(yName);  SetZColumn(zName);
}

//________________________________________________________________________________
TTable3Points::TTable3Points(TTableSorter *sorter,Int_t keyIndex,
                       const Char_t *xName, const Char_t *yName, const Char_t *zName
                      ,Option_t *opt)
                : TTablePoints(sorter,keyIndex,opt)

{
   //to be documented
   fColumnOffset =  new ULong_t [kTotalSize];
   SetXColumn(xName);  SetYColumn(yName);  SetZColumn(zName);
}

//________________________________________________________________________________
TTable3Points::~TTable3Points()
{
   //to be documented
   SafeDelete(fColumnOffset);
}

//________________________________________________________________________________
Float_t TTable3Points::GetAnyPoint(Int_t idx, EPointDirection xAxis) const
{
   //to be documented
   Float_t point  = 0;
   TTable  *table = 0;
   if (fTableSorter) table = fTableSorter->GetTable();
   if (table) {
      const Char_t *tablePtr = ((Char_t *)table->At(Indx(idx))) + fColumnOffset[xAxis] ;
      point = *((Float_t *)tablePtr);
   }
   return point;
}

//____________________________________________________________________________
void TTable3Points::SetAnyColumn(const Char_t *anyName, EPointDirection indx)
{
   //to be documented
   fColumnOffset[indx] = fTableSorter->GetTable()->GetOffset(anyName);
   if (fColumnOffset[indx] == ULong_t(-1))  MakeZombie();
}

//____________________________________________________________________________
Float_t *TTable3Points::GetXYZ(Float_t *xyz,Int_t idx, Int_t num) const
{
   //to be documented
   if (xyz) {
      Int_t size = TMath::Min(idx+num,Size());
      Int_t j=0;
      for (Int_t i=idx;i<size;i++) {
         xyz[j++] = GetX(i);
         xyz[j++] = GetY(i);
         xyz[j++] = GetZ(i);
      }
   }
   return xyz;
}
 TTable3Points.cxx:1
 TTable3Points.cxx:2
 TTable3Points.cxx:3
 TTable3Points.cxx:4
 TTable3Points.cxx:5
 TTable3Points.cxx:6
 TTable3Points.cxx:7
 TTable3Points.cxx:8
 TTable3Points.cxx:9
 TTable3Points.cxx:10
 TTable3Points.cxx:11
 TTable3Points.cxx:12
 TTable3Points.cxx:13
 TTable3Points.cxx:14
 TTable3Points.cxx:15
 TTable3Points.cxx:16
 TTable3Points.cxx:17
 TTable3Points.cxx:18
 TTable3Points.cxx:19
 TTable3Points.cxx:20
 TTable3Points.cxx:21
 TTable3Points.cxx:22
 TTable3Points.cxx:23
 TTable3Points.cxx:24
 TTable3Points.cxx:25
 TTable3Points.cxx:26
 TTable3Points.cxx:27
 TTable3Points.cxx:28
 TTable3Points.cxx:29
 TTable3Points.cxx:30
 TTable3Points.cxx:31
 TTable3Points.cxx:32
 TTable3Points.cxx:33
 TTable3Points.cxx:34
 TTable3Points.cxx:35
 TTable3Points.cxx:36
 TTable3Points.cxx:37
 TTable3Points.cxx:38
 TTable3Points.cxx:39
 TTable3Points.cxx:40
 TTable3Points.cxx:41
 TTable3Points.cxx:42
 TTable3Points.cxx:43
 TTable3Points.cxx:44
 TTable3Points.cxx:45
 TTable3Points.cxx:46
 TTable3Points.cxx:47
 TTable3Points.cxx:48
 TTable3Points.cxx:49
 TTable3Points.cxx:50
 TTable3Points.cxx:51
 TTable3Points.cxx:52
 TTable3Points.cxx:53
 TTable3Points.cxx:54
 TTable3Points.cxx:55
 TTable3Points.cxx:56
 TTable3Points.cxx:57
 TTable3Points.cxx:58
 TTable3Points.cxx:59
 TTable3Points.cxx:60
 TTable3Points.cxx:61
 TTable3Points.cxx:62
 TTable3Points.cxx:63
 TTable3Points.cxx:64
 TTable3Points.cxx:65
 TTable3Points.cxx:66
 TTable3Points.cxx:67
 TTable3Points.cxx:68
 TTable3Points.cxx:69
 TTable3Points.cxx:70
 TTable3Points.cxx:71
 TTable3Points.cxx:72
 TTable3Points.cxx:73
 TTable3Points.cxx:74
 TTable3Points.cxx:75
 TTable3Points.cxx:76
 TTable3Points.cxx:77
 TTable3Points.cxx:78
 TTable3Points.cxx:79
 TTable3Points.cxx:80
 TTable3Points.cxx:81
 TTable3Points.cxx:82
 TTable3Points.cxx:83
 TTable3Points.cxx:84
 TTable3Points.cxx:85
 TTable3Points.cxx:86
 TTable3Points.cxx:87
 TTable3Points.cxx:88
 TTable3Points.cxx:89
 TTable3Points.cxx:90
 TTable3Points.cxx:91
 TTable3Points.cxx:92
 TTable3Points.cxx:93
 TTable3Points.cxx:94
 TTable3Points.cxx:95
 TTable3Points.cxx:96
 TTable3Points.cxx:97
 TTable3Points.cxx:98
 TTable3Points.cxx:99
 TTable3Points.cxx:100
 TTable3Points.cxx:101
 TTable3Points.cxx:102
 TTable3Points.cxx:103
 TTable3Points.cxx:104
 TTable3Points.cxx:105
 TTable3Points.cxx:106
 TTable3Points.cxx:107
 TTable3Points.cxx:108
 TTable3Points.cxx:109
 TTable3Points.cxx:110
 TTable3Points.cxx:111
 TTable3Points.cxx:112
 TTable3Points.cxx:113
 TTable3Points.cxx:114
 TTable3Points.cxx:115
 TTable3Points.cxx:116
 TTable3Points.cxx:117
 TTable3Points.cxx:118
 TTable3Points.cxx:119
 TTable3Points.cxx:120
 TTable3Points.cxx:121
 TTable3Points.cxx:122
 TTable3Points.cxx:123
 TTable3Points.cxx:124
 TTable3Points.cxx:125
 TTable3Points.cxx:126
 TTable3Points.cxx:127
 TTable3Points.cxx:128
 TTable3Points.cxx:129
 TTable3Points.cxx:130
 TTable3Points.cxx:131
 TTable3Points.cxx:132
 TTable3Points.cxx:133
 TTable3Points.cxx:134
 TTable3Points.cxx:135
 TTable3Points.cxx:136
 TTable3Points.cxx:137
 TTable3Points.cxx:138
 TTable3Points.cxx:139
 TTable3Points.cxx:140
 TTable3Points.cxx:141
 TTable3Points.cxx:142
 TTable3Points.cxx:143
 TTable3Points.cxx:144
 TTable3Points.cxx:145
 TTable3Points.cxx:146
 TTable3Points.cxx:147
 TTable3Points.cxx:148
 TTable3Points.cxx:149
 TTable3Points.cxx:150
 TTable3Points.cxx:151
 TTable3Points.cxx:152
 TTable3Points.cxx:153
 TTable3Points.cxx:154
 TTable3Points.cxx:155
 TTable3Points.cxx:156
 TTable3Points.cxx:157
 TTable3Points.cxx:158
 TTable3Points.cxx:159
 TTable3Points.cxx:160
 TTable3Points.cxx:161
 TTable3Points.cxx:162
 TTable3Points.cxx:163
 TTable3Points.cxx:164
 TTable3Points.cxx:165