StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TResponseTable.cxx
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 
20 ClassImp(TResponseTable);
21 TableClassStreamerImp(TResponseTable)
22 
23 
26 TResponseTable::TResponseTable():TGenericTable(), fResponseLocation(-1)
27 {
28 }
29 
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);
42  fSize = GetDescriptorPointer()->Sizeof();
43  fResponseLocation = FindResponseLocation(*GetDescriptorPointer());
44  SetType("DetectorResponse");
45 }
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 }
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 }
80 
81 void TResponseTable::AddElement(const char *path,EColumnType type)
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 
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();
118  tableDescriptor_st *row = dsc.GetTable();
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 
143 
145 {
146  // responseLocation is an offset of the first float data-member
147  Int_t responseLocation = -1;
148  Int_t nRow = dsc.GetNRows();
149  tableDescriptor_st *row = dsc.GetTable();
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)
void AddResponse(const char *chit)
to be documented
void AddElement(const char *path, EColumnType type)
to be documented
virtual void SetDescriptorPointer(TTableDescriptor *list)
to be documented
Definition: TGenericTable.h:22
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1395
virtual TTableDescriptor * GetDescriptorPointer() const
to be documented
Definition: TGenericTable.h:21
Int_t Sizeof() const
to be documented
void AddVolumePath(const char *path)
to be documented
virtual Int_t AddAt(const void *c)
Append one row pointed by &quot;c&quot; to the descriptor.
static Int_t FindResponseLocation(TTableDescriptor &dsc)
virtual void SetType(const char *const type)
to be documented
Definition: TTable.cxx:1973
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1388
virtual Int_t AddAt(const void *c)
Definition: TTable.cxx:1122
TResponseTable()
to be documented
TTableDescriptor * GetTableDescriptors() const
protected: create a new TTableDescriptor descriptor for this table
Definition: TGenericTable.h:63