00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "TResponseTable.h"
00014
00015
00016
00017
00018
00019
00020 ClassImp(TResponseTable)
00021 TableClassStreamerImp(TResponseTable)
00022
00023
00024 TResponseTable::TResponseTable():TGenericTable(), fResponseLocation(-1)
00025 {
00026
00027 }
00028
00029
00030 TResponseTable::TResponseTable(const char *name,const char *volumePath, const char *responseDefinition, Int_t )
00031 : TGenericTable(), fResponseLocation(-1)
00032 {
00033
00034 SetDescriptorPointer(new TTableDescriptor(name));
00035
00036
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
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
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
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
00102
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
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
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
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
00147 responseLocation = i;
00148 break;
00149 }
00150 }
00151 return responseLocation;
00152 }