StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TTable3Points.cxx
1 // @(#)root/table:$Id$
2 // Author: Valery Fine 10/05/99 (E-mail: fine@bnl.gov)
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TTable3Points.h"
13 
15 //
16 // TTable3Points class is to create 3D view of any 3 columns of the TTable objects
17 // with one and the same "key column value".
18 //
19 // 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
20 // from the rows with one and same "track_id" column value will be regarded
21 // as an image of one and the same "track".
22 // The last means all those points will be painted with one and the same 3D
23 // attributes like "color", "size", "style", "light","markers", "connections" etc.
24 //
25 // The original TTable object must be pre-sorted by "key column" via TTableSorter
26 // class
27 //
28 // void CreatePoints(Tg2t_tpc_hit *points)
29 // {
30 // g2t_tpc_hit_st *p = points->GetTable();
31 //
32 // TTable3Points *track = 0;
33 // TString tr;
34 // tr = "track_p";
35 // TTable &ttt = *((TTable *)points);
36 // // Track2Line MUST be on heap otherwise 3D view will crash just code leaves this
37 // // subroutine
38 // We will assemble all points by its "track_p" field.
39 //
40 // TTableSorter *Track2Line = new TTableSorter (ttt,"track_p");
41 //
42 // Int_t i = 0;
43 // Char_t buffer[10];
44 // Int_t ntracks = 0;
45 // const Int_t maxtracks = 5;
46 // //---------------------------- Fill tracks -------------------
47 // long currentId = -1;
48 // long newId = 0;
49 // g2t_tpc_hit_st *hitPoint = 0;
50 // TVolume *thisTrack[7] = {0,0,0,0,0,0,0}; // seven volumes for 7 different colors
51 // Int_t MaxRowtoCount = 5000; // 5000;
52 // Int_t MaxTracks = Track2Line->CountKeys();
53 // MaxTracks = 100;
54 // for (i=0;i<Track2Line->GetNRows() && ntracks < MaxTracks ;i++)
55 // {
56 // hitPoint = p + Track2Line->GetIndex(i);
57 // newId = hitPoint->track_p;
58 // if (newId != currentId) { // The hit for the new track has been found
59 //
60 // const Char_t *xName = "x[0]";
61 // const Char_t *yName = "x[1]";
62 // const Char_t *zName = "x[2]";
63 //
64 // track = new TTable3Points(Track2Line,(const void *)&newId,xName,yName,zName);
65 //
66 // // Create a shape for this node
67 // TPolyLineShape *trackShape = new TPolyLineShape(track);
68 // trackShape->SetVisibility(1);
69 // Int_t colorIndx = ntracks%7;
70 // trackShape->SetColorAttribute(colorIndx+kGreen);
71 // trackShape->SetLineStyle(1);
72 // trackShape->SetSizeAttribute(2);
73 // // Create a node to hold it
74 // if (!thisTrack[colorIndx]) {
75 // thisTrack[colorIndx] = new TVolume("hits","hits",trackShape);
76 // thisTrack[colorIndx]->Mark();
77 // thisTrack[colorIndx]->SetVisibility();
78 // TVolumePosition *pp = hall->Add(thisTrack[colorIndx]);
79 // if (!pp) printf(" no position %d\n",ntrack);
80 // }
81 // else
82 // thisTrack[colorIndx]->Add(trackShape);
83 // currentId = newId;
84 // ntracks++;
85 // }
86 // }
87 //
89 
90 ClassImp(TTable3Points);
91 
94 
95 TTable3Points::TTable3Points():fColumnOffset(0)
96 {
97 }
98 
100 
101 TTable3Points::TTable3Points(TTableSorter *sorter,const void *key,
102  const Char_t *xName, const Char_t *yName, const Char_t *zName
103  ,Option_t *opt)
104  : TTablePoints(sorter,key,opt)
105 
106 {
107  //to be documented
108  fColumnOffset = new ULong_t [kTotalSize];
109  SetXColumn(xName); SetYColumn(yName); SetZColumn(zName);
110 }
111 
113 
114 TTable3Points::TTable3Points(TTableSorter *sorter,Int_t keyIndex,
115  const Char_t *xName, const Char_t *yName, const Char_t *zName
116  ,Option_t *opt)
117  : TTablePoints(sorter,keyIndex,opt)
118 
119 {
120  //to be documented
121  fColumnOffset = new ULong_t [kTotalSize];
122  SetXColumn(xName); SetYColumn(yName); SetZColumn(zName);
123 }
124 
127 
129 {
130  SafeDelete(fColumnOffset);
131 }
132 
135 
136 Float_t TTable3Points::GetAnyPoint(Int_t idx, EPointDirection xAxis) const
137 {
138  Float_t point = 0;
139  TTable *table = 0;
140  if (fTableSorter) table = fTableSorter->GetTable();
141  if (table) {
142  const Char_t *tablePtr = ((Char_t *)table->At(Indx(idx))) + fColumnOffset[xAxis] ;
143  point = *((Float_t *)tablePtr);
144  }
145  return point;
146 }
147 
150 
151 void TTable3Points::SetAnyColumn(const Char_t *anyName, EPointDirection indx)
152 {
153  fColumnOffset[indx] = fTableSorter->GetTable()->GetOffset(anyName);
154  if (fColumnOffset[indx] == ULong_t(-1)) MakeZombie();
155 }
156 
159 
160 Float_t *TTable3Points::GetXYZ(Float_t *xyz,Int_t idx, Int_t num) const
161 {
162  if (xyz) {
163  Int_t size = TMath::Min(idx+num,Size());
164  Int_t j=0;
165  for (Int_t i=idx;i<size;i++) {
166  xyz[j++] = GetX(i);
167  xyz[j++] = GetY(i);
168  xyz[j++] = GetZ(i);
169  }
170  }
171  return xyz;
172 }
virtual TTable * GetTable() const
to be documented
~TTable3Points()
to be documented
virtual Float_t GetAnyPoint(Int_t idx, EPointDirection xAxis) const
to be documented
virtual void SetAnyColumn(const Char_t *anyName, EPointDirection indx)
to be documented
TTable3Points()
to be documented
Definition: TTable.h:48
const void * At(Int_t i) const
Returns a pointer to the i-th row of the table.
Definition: TTable.cxx:303