ROOT logo
// @(#)root/table:$Id: TResponseTable.cxx 21414 2007-12-17 14:15:59Z brun $
// Author: Valery Fine(fine@bnl.gov)   03/04/2002

/*************************************************************************
 * 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 "TResponseTable.h"

//______________________________________________________________________________
//
// TResponseTable is an example of the custom version of the TGenericTable class
//______________________________________________________________________________

ClassImp(TResponseTable)
TableClassStreamerImp(TResponseTable)

//______________________________________________________________________________
TResponseTable::TResponseTable():TGenericTable(), fResponseLocation(-1)
{
   //to be documented
}

//______________________________________________________________________________
TResponseTable::TResponseTable(const char *name,const char *volumePath, const char *responseDefinition, Int_t /*allocSize*/)
 :  TGenericTable(), fResponseLocation(-1)
{
   // Set an empty descriptor
   SetDescriptorPointer(new TTableDescriptor(name));

   // The first element is always "int TRACK;"
   AddElement("TRACK",kInt);
   AddVolumePath(volumePath);
   AddResponse(responseDefinition);
   fSize = GetDescriptorPointer()->Sizeof();
   fResponseLocation = FindResponseLocation(*GetDescriptorPointer());
   SetType("DetectorResponse");
}
//______________________________________________________________________________
void TResponseTable::AddVolumePath(const char *path)
{
   //to be documented
   Int_t counter = 0;
   const Int_t maxResponseCounter = 15;
   const char *next = &path[0];
   while( ( *next && *next != ' ') &&  counter < maxResponseCounter ) {
      TString elName;
      for (int j=0; j<4 && (next[j] != ' ');j++)  elName += next[j];
      AddElement(elName,kInt);
      next += 4;
      counter++;
   }
}
//______________________________________________________________________________
void TResponseTable::AddResponse(const char *chit)
{
   //to be documented
   Int_t counter = 0;
   const Int_t maxResponseCounter = 15;
   const char *next = &chit[0];
   while( ( *next != ' ' ) &&  counter < maxResponseCounter )  {
      TString elName;
      for (int j=0; j<4 && (next[j] != ' ');j++)  elName += next[j];
      AddElement(elName,kFloat);
      next += 4;
      counter++;
   }
}
//______________________________________________________________________________
void TResponseTable::AddElement(const char *path,EColumnType type)
{
   //to be documented
   assert( (type == kInt || type == kFloat ) );

   TTableDescriptor  &dsc = *GetTableDescriptors();
   Int_t nRow = dsc.GetNRows();
   tableDescriptor_st row;

   memset(&row,0,sizeof(row));
   strncpy(row.fColumnName,path,sizeof(row.fColumnName));
   if (nRow) row.fOffset = dsc[nRow-1].fOffset + dsc[nRow-1].fSize;

   row.fType = type;
   if (type == kInt)
      row.fTypeSize = sizeof(Int_t);
   else
      row.fTypeSize = sizeof(Float_t);

   row.fSize = row.fTypeSize;
   dsc.AddAt(&row);
}

//______________________________________________________________________________
void TResponseTable::SetResponse(int track, int *nvl, float *response)
{
   // Add one extra his/digit to the table
   // Reallocate the table if needed
   char    *charBuffer     = new char[GetRowSize()];
   Int_t   *nvlBuffer      = (Int_t *)charBuffer;
   Float_t *responseBuffer = (Float_t *)charBuffer;
   Int_t jResponse  = 0;
   Int_t jNvl       = 0;

   // Loop for the response information
   TTableDescriptor  &dsc = *GetTableDescriptors();
   Int_t nRow = dsc.GetNRows();
   tableDescriptor_st *row = dsc.GetTable();
   nvlBuffer[0] =  track; row++;
   for (int i=1;i<nRow;i++,row++) {
      if (row->fType == kFloat) {
         responseBuffer[i] = response[jResponse++];
      } else {
         nvlBuffer[i] = nvl[jNvl++];
      }
   }
   AddAt(charBuffer);
   delete [] charBuffer;
}

//______________________________________________________________________________
Int_t TResponseTable::FindResponseLocation(TTableDescriptor  &dsc)
{
 // Look up the table descriptor to find the
 // first respnse value location
 // TResponsetable layout:
 //  offset
 //   +0    int TRACK
 //   +1
 //   ...   int <volume path description>
 //  +nVl.
 //  +nVl+1  <----  fResponseLocation
 //   ...   response values
 //  RowSize

   // responseLocation is an offset of the first float data-member
   Int_t responseLocation = -1;
   Int_t nRow = dsc.GetNRows();
   tableDescriptor_st *row = dsc.GetTable();
   for (int i=0;i<nRow;i++,row++) {
      if (row->fType == kFloat) {
         // found
         responseLocation = i;
         break;
      }
   }
   return responseLocation;
}
 TResponseTable.cxx:1
 TResponseTable.cxx:2
 TResponseTable.cxx:3
 TResponseTable.cxx:4
 TResponseTable.cxx:5
 TResponseTable.cxx:6
 TResponseTable.cxx:7
 TResponseTable.cxx:8
 TResponseTable.cxx:9
 TResponseTable.cxx:10
 TResponseTable.cxx:11
 TResponseTable.cxx:12
 TResponseTable.cxx:13
 TResponseTable.cxx:14
 TResponseTable.cxx:15
 TResponseTable.cxx:16
 TResponseTable.cxx:17
 TResponseTable.cxx:18
 TResponseTable.cxx:19
 TResponseTable.cxx:20
 TResponseTable.cxx:21
 TResponseTable.cxx:22
 TResponseTable.cxx:23
 TResponseTable.cxx:24
 TResponseTable.cxx:25
 TResponseTable.cxx:26
 TResponseTable.cxx:27
 TResponseTable.cxx:28
 TResponseTable.cxx:29
 TResponseTable.cxx:30
 TResponseTable.cxx:31
 TResponseTable.cxx:32
 TResponseTable.cxx:33
 TResponseTable.cxx:34
 TResponseTable.cxx:35
 TResponseTable.cxx:36
 TResponseTable.cxx:37
 TResponseTable.cxx:38
 TResponseTable.cxx:39
 TResponseTable.cxx:40
 TResponseTable.cxx:41
 TResponseTable.cxx:42
 TResponseTable.cxx:43
 TResponseTable.cxx:44
 TResponseTable.cxx:45
 TResponseTable.cxx:46
 TResponseTable.cxx:47
 TResponseTable.cxx:48
 TResponseTable.cxx:49
 TResponseTable.cxx:50
 TResponseTable.cxx:51
 TResponseTable.cxx:52
 TResponseTable.cxx:53
 TResponseTable.cxx:54
 TResponseTable.cxx:55
 TResponseTable.cxx:56
 TResponseTable.cxx:57
 TResponseTable.cxx:58
 TResponseTable.cxx:59
 TResponseTable.cxx:60
 TResponseTable.cxx:61
 TResponseTable.cxx:62
 TResponseTable.cxx:63
 TResponseTable.cxx:64
 TResponseTable.cxx:65
 TResponseTable.cxx:66
 TResponseTable.cxx:67
 TResponseTable.cxx:68
 TResponseTable.cxx:69
 TResponseTable.cxx:70
 TResponseTable.cxx:71
 TResponseTable.cxx:72
 TResponseTable.cxx:73
 TResponseTable.cxx:74
 TResponseTable.cxx:75
 TResponseTable.cxx:76
 TResponseTable.cxx:77
 TResponseTable.cxx:78
 TResponseTable.cxx:79
 TResponseTable.cxx:80
 TResponseTable.cxx:81
 TResponseTable.cxx:82
 TResponseTable.cxx:83
 TResponseTable.cxx:84
 TResponseTable.cxx:85
 TResponseTable.cxx:86
 TResponseTable.cxx:87
 TResponseTable.cxx:88
 TResponseTable.cxx:89
 TResponseTable.cxx:90
 TResponseTable.cxx:91
 TResponseTable.cxx:92
 TResponseTable.cxx:93
 TResponseTable.cxx:94
 TResponseTable.cxx:95
 TResponseTable.cxx:96
 TResponseTable.cxx:97
 TResponseTable.cxx:98
 TResponseTable.cxx:99
 TResponseTable.cxx:100
 TResponseTable.cxx:101
 TResponseTable.cxx:102
 TResponseTable.cxx:103
 TResponseTable.cxx:104
 TResponseTable.cxx:105
 TResponseTable.cxx:106
 TResponseTable.cxx:107
 TResponseTable.cxx:108
 TResponseTable.cxx:109
 TResponseTable.cxx:110
 TResponseTable.cxx:111
 TResponseTable.cxx:112
 TResponseTable.cxx:113
 TResponseTable.cxx:114
 TResponseTable.cxx:115
 TResponseTable.cxx:116
 TResponseTable.cxx:117
 TResponseTable.cxx:118
 TResponseTable.cxx:119
 TResponseTable.cxx:120
 TResponseTable.cxx:121
 TResponseTable.cxx:122
 TResponseTable.cxx:123
 TResponseTable.cxx:124
 TResponseTable.cxx:125
 TResponseTable.cxx:126
 TResponseTable.cxx:127
 TResponseTable.cxx:128
 TResponseTable.cxx:129
 TResponseTable.cxx:130
 TResponseTable.cxx:131
 TResponseTable.cxx:132
 TResponseTable.cxx:133
 TResponseTable.cxx:134
 TResponseTable.cxx:135
 TResponseTable.cxx:136
 TResponseTable.cxx:137
 TResponseTable.cxx:138
 TResponseTable.cxx:139
 TResponseTable.cxx:140
 TResponseTable.cxx:141
 TResponseTable.cxx:142
 TResponseTable.cxx:143
 TResponseTable.cxx:144
 TResponseTable.cxx:145
 TResponseTable.cxx:146
 TResponseTable.cxx:147
 TResponseTable.cxx:148
 TResponseTable.cxx:149
 TResponseTable.cxx:150
 TResponseTable.cxx:151
 TResponseTable.cxx:152