TResponseTable.cxx

Go to the documentation of this file.
00001 // @(#)root/table:$Id: TResponseTable.cxx 35505 2010-09-21 08:18:20Z brun $
00002 // Author: Valery Fine(fine@bnl.gov)   03/04/2002
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 
00013 #include "TResponseTable.h"
00014 
00015 //______________________________________________________________________________
00016 //
00017 // TResponseTable is an example of the custom version of the TGenericTable class
00018 //______________________________________________________________________________
00019 
00020 ClassImp(TResponseTable)
00021 TableClassStreamerImp(TResponseTable)
00022 
00023 //______________________________________________________________________________
00024 TResponseTable::TResponseTable():TGenericTable(), fResponseLocation(-1)
00025 {
00026    //to be documented
00027 }
00028 
00029 //______________________________________________________________________________
00030 TResponseTable::TResponseTable(const char *name,const char *volumePath, const char *responseDefinition, Int_t /*allocSize*/)
00031  :  TGenericTable(), fResponseLocation(-1)
00032 {
00033    // Set an empty descriptor
00034    SetDescriptorPointer(new TTableDescriptor(name));
00035 
00036    // The first element is always "int TRACK;"
00037    AddElement("TRACK",kInt);
00038    AddVolumePath(volumePath);
00039    AddResponse(responseDefinition);
00040    fSize = GetDescriptorPointer()->Sizeof();
00041    fResponseLocation = FindResponseLocation(*GetDescriptorPointer());
00042    SetType("DetectorResponse");
00043 }
00044 //______________________________________________________________________________
00045 void TResponseTable::AddVolumePath(const char *path)
00046 {
00047    //to be documented
00048    Int_t counter = 0;
00049    const Int_t maxResponseCounter = 15;
00050    const char *next = &path[0];
00051    while( ( *next && *next != ' ') &&  counter < maxResponseCounter ) {
00052       TString elName;
00053       for (int j=0; j<4 && (next[j] != ' ');j++)  elName += next[j];
00054       AddElement(elName,kInt);
00055       next += 4;
00056       counter++;
00057    }
00058 }
00059 //______________________________________________________________________________
00060 void TResponseTable::AddResponse(const char *chit)
00061 {
00062    //to be documented
00063    Int_t counter = 0;
00064    const Int_t maxResponseCounter = 15;
00065    const char *next = &chit[0];
00066    while( ( *next != ' ' ) &&  counter < maxResponseCounter )  {
00067       TString elName;
00068       for (int j=0; j<4 && (next[j] != ' ');j++)  elName += next[j];
00069       AddElement(elName,kFloat);
00070       next += 4;
00071       counter++;
00072    }
00073 }
00074 //______________________________________________________________________________
00075 void TResponseTable::AddElement(const char *path,EColumnType type)
00076 {
00077    //to be documented
00078    assert( (type == kInt || type == kFloat ) );
00079 
00080    TTableDescriptor  &dsc = *GetTableDescriptors();
00081    Int_t nRow = dsc.GetNRows();
00082    tableDescriptor_st row;
00083 
00084    memset(&row,0,sizeof(row));
00085    strlcpy(row.fColumnName,path,sizeof(row.fColumnName));
00086    if (nRow) row.fOffset = dsc[nRow-1].fOffset + dsc[nRow-1].fSize;
00087 
00088    row.fType = type;
00089    if (type == kInt)
00090       row.fTypeSize = sizeof(Int_t);
00091    else
00092       row.fTypeSize = sizeof(Float_t);
00093 
00094    row.fSize = row.fTypeSize;
00095    dsc.AddAt(&row);
00096 }
00097 
00098 //______________________________________________________________________________
00099 void TResponseTable::SetResponse(int track, int *nvl, float *response)
00100 {
00101    // Add one extra his/digit to the table
00102    // Reallocate the table if needed
00103    char    *charBuffer     = new char[GetRowSize()];
00104    Int_t   *nvlBuffer      = (Int_t *)charBuffer;
00105    Float_t *responseBuffer = (Float_t *)charBuffer;
00106    Int_t jResponse  = 0;
00107    Int_t jNvl       = 0;
00108 
00109    // Loop for the response information
00110    TTableDescriptor  &dsc = *GetTableDescriptors();
00111    Int_t nRow = dsc.GetNRows();
00112    tableDescriptor_st *row = dsc.GetTable();
00113    nvlBuffer[0] =  track; row++;
00114    for (int i=1;i<nRow;i++,row++) {
00115       if (row->fType == kFloat) {
00116          responseBuffer[i] = response[jResponse++];
00117       } else {
00118          nvlBuffer[i] = nvl[jNvl++];
00119       }
00120    }
00121    AddAt(charBuffer);
00122    delete [] charBuffer;
00123 }
00124 
00125 //______________________________________________________________________________
00126 Int_t TResponseTable::FindResponseLocation(TTableDescriptor  &dsc)
00127 {
00128  // Look up the table descriptor to find the
00129  // first respnse value location
00130  // TResponsetable layout:
00131  //  offset
00132  //   +0    int TRACK
00133  //   +1
00134  //   ...   int <volume path description>
00135  //  +nVl.
00136  //  +nVl+1  <----  fResponseLocation
00137  //   ...   response values
00138  //  RowSize
00139 
00140    // responseLocation is an offset of the first float data-member
00141    Int_t responseLocation = -1;
00142    Int_t nRow = dsc.GetNRows();
00143    tableDescriptor_st *row = dsc.GetTable();
00144    for (int i=0;i<nRow;i++,row++) {
00145       if (row->fType == kFloat) {
00146          // found
00147          responseLocation = i;
00148          break;
00149       }
00150    }
00151    return responseLocation;
00152 }

Generated on Tue Jul 5 14:45:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1