ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TResponseTable.cxx
Go to the documentation of this file.
1 // @(#)root/table:$Id$
2 // Author: Valery Fine(fine@bnl.gov) 03/04/2002
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 
13 #include "TResponseTable.h"
14 
15 //______________________________________________________________________________
16 //
17 // TResponseTable is an example of the custom version of the TGenericTable class
18 //______________________________________________________________________________
19 
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 ///to be documented
25 
26 TResponseTable::TResponseTable():TGenericTable(), fResponseLocation(-1)
27 {
28 }
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// Set an empty descriptor
32 
33 TResponseTable::TResponseTable(const char *name,const char *volumePath, const char *responseDefinition, Int_t /*allocSize*/)
34  : TGenericTable(), fResponseLocation(-1)
35 {
37 
38  // The first element is always "int TRACK;"
39  AddElement("TRACK",kInt);
40  AddVolumePath(volumePath);
41  AddResponse(responseDefinition);
44  SetType("DetectorResponse");
45 }
46 ////////////////////////////////////////////////////////////////////////////////
47 ///to be documented
48 
49 void TResponseTable::AddVolumePath(const char *path)
50 {
51  Int_t counter = 0;
52  const Int_t maxResponseCounter = 15;
53  const char *next = &path[0];
54  while( ( *next && *next != ' ') && counter < maxResponseCounter ) {
55  TString elName;
56  for (int j=0; j<4 && (next[j] != ' ');j++) elName += next[j];
57  AddElement(elName,kInt);
58  next += 4;
59  counter++;
60  }
61 }
62 ////////////////////////////////////////////////////////////////////////////////
63 ///to be documented
64 
65 void TResponseTable::AddResponse(const char *chit)
66 {
67  Int_t counter = 0;
68  const Int_t maxResponseCounter = 15;
69  const char *next = &chit[0];
70  while( ( *next != ' ' ) && counter < maxResponseCounter ) {
71  TString elName;
72  for (int j=0; j<4 && (next[j] != ' ');j++) elName += next[j];
73  AddElement(elName,kFloat);
74  next += 4;
75  counter++;
76  }
77 }
78 ////////////////////////////////////////////////////////////////////////////////
79 ///to be documented
80 
82 {
83  assert( (type == kInt || type == kFloat ) );
84 
86  Int_t nRow = dsc.GetNRows();
88 
89  memset(&row,0,sizeof(row));
90  strlcpy(row.fColumnName,path,sizeof(row.fColumnName));
91  if (nRow) row.fOffset = dsc[nRow-1].fOffset + dsc[nRow-1].fSize;
92 
93  row.fType = type;
94  if (type == kInt)
95  row.fTypeSize = sizeof(Int_t);
96  else
97  row.fTypeSize = sizeof(Float_t);
98 
99  row.fSize = row.fTypeSize;
100  dsc.AddAt(&row);
101 }
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Add one extra his/digit to the table
105 /// Reallocate the table if needed
106 
107 void TResponseTable::SetResponse(int track, int *nvl, float *response)
108 {
109  char *charBuffer = new char[GetRowSize()];
110  Int_t *nvlBuffer = (Int_t *)charBuffer;
111  Float_t *responseBuffer = (Float_t *)charBuffer;
112  Int_t jResponse = 0;
113  Int_t jNvl = 0;
114 
115  // Loop for the response information
117  Int_t nRow = dsc.GetNRows();
119  nvlBuffer[0] = track; row++;
120  for (int i=1;i<nRow;i++,row++) {
121  if (row->fType == kFloat) {
122  responseBuffer[i] = response[jResponse++];
123  } else {
124  nvlBuffer[i] = nvl[jNvl++];
125  }
126  }
127  AddAt(charBuffer);
128  delete [] charBuffer;
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Look up the table descriptor to find the
133 /// first respnse value location
134 /// TResponsetable layout:
135 /// offset
136 /// +0 int TRACK
137 /// +1
138 /// ... int <volume path description>
139 /// +nVl.
140 /// +nVl+1 <---- fResponseLocation
141 /// ... response values
142 /// RowSize
143 
145 {
146  // responseLocation is an offset of the first float data-member
147  Int_t responseLocation = -1;
148  Int_t nRow = dsc.GetNRows();
150  for (int i=0;i<nRow;i++,row++) {
151  if (row->fType == kFloat) {
152  // found
153  responseLocation = i;
154  break;
155  }
156  }
157  return responseLocation;
158 }
void SetResponse(int track, int *nvl, float *response)
Add one extra his/digit to the table Reallocate the table if needed.
tuple row
Definition: mrt.py:26
void AddResponse(const char *chit)
to be documented
#define TableClassStreamerImp(className)
Definition: Ttypes.h:42
Long_t fSize
Definition: TTable.h:56
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
float Float_t
Definition: RtypesCore.h:53
tableDescriptor_st * GetTable(Int_t i=0) const
void AddElement(const char *path, EColumnType type)
to be documented
virtual void SetDescriptorPointer(TTableDescriptor *list)
to be documented
Definition: TGenericTable.h:22
#define assert(cond)
Definition: unittest.h:542
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1399
unsigned int fOffset
virtual TTableDescriptor * GetDescriptorPointer() const
to be documented
Definition: TGenericTable.h:21
ClassImp(TResponseTable) TableClassStreamerImp(TResponseTable) TResponseTable
to be documented
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
ClassImp(TTable) TTableDescriptor *TTable return new TTableDescriptor(this)
protected: create a new TTableDescriptor descriptor for this table
Int_t Sizeof() const
to be documented
EColumnType
Definition: TTable.h:86
void AddVolumePath(const char *path)
to be documented
virtual Int_t AddAt(const void *c)
Append one row pointed by "c" to the descriptor.
static Int_t FindResponseLocation(TTableDescriptor &dsc)
Look up the table descriptor to find the first respnse value location TResponsetable layout: offset +...
virtual void SetType(const char *const type)
to be documented
Definition: TTable.cxx:1983
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1392
unsigned int fSize
virtual Int_t AddAt(const void *c)
Add the "row" at the GetNRows() position, and reallocate the table if neccesary, and return the row i...
Definition: TTable.cxx:1126
Int_t fResponseLocation
int type
Definition: TGX11.cxx:120
unsigned int fTypeSize
#define name(a, b)
Definition: linkTestLib0.cpp:5
TTableDescriptor * GetTableDescriptors() const
Definition: TGenericTable.h:63