00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "TTreeRow.h"
00024 #include "TObjArray.h"
00025
00026 ClassImp(TTreeRow)
00027
00028
00029 TTreeRow::TTreeRow()
00030 {
00031
00032
00033 fColumnCount = 0;
00034 fFields = 0;
00035 fOriginal = 0;
00036 fRow = 0;
00037
00038 }
00039
00040
00041 TTreeRow::TTreeRow(Int_t nfields)
00042 {
00043
00044
00045 fColumnCount = nfields;
00046 fFields = 0;
00047 fOriginal = 0;
00048 fRow = 0;
00049
00050 }
00051
00052
00053 TTreeRow::TTreeRow(Int_t nfields, const Int_t *fields, const char *row)
00054 {
00055
00056
00057 fColumnCount = nfields;
00058 fFields = 0;
00059 fOriginal = 0;
00060 fRow = 0;
00061 SetRow(fields,row);
00062 }
00063
00064
00065 TTreeRow::TTreeRow(TSQLRow *original)
00066 {
00067
00068
00069
00070 fFields = 0;
00071 fOriginal = 0;
00072 fColumnCount = 0;
00073 fRow = 0;
00074
00075 if (!original) {
00076 Error("TTreeRow", "original may not be 0");
00077 return;
00078 }
00079 if (original->IsA() != TTreeRow::Class()) {
00080 Error("TTreeRow", "original must be a TTreeRow");
00081 return;
00082 }
00083
00084 fOriginal = (TTreeRow*) original;
00085 fColumnCount = fOriginal->fColumnCount;
00086 }
00087
00088
00089 TTreeRow::~TTreeRow()
00090 {
00091
00092
00093 if (fFields)
00094 Close();
00095 }
00096
00097
00098 void TTreeRow::Close(Option_t *)
00099 {
00100
00101
00102 if (fRow) delete [] fRow;
00103 if (fFields) delete [] fFields;
00104 fColumnCount = 0;
00105 fOriginal = 0;
00106 }
00107
00108
00109 Bool_t TTreeRow::IsValid(Int_t field)
00110 {
00111
00112
00113 if (!fFields && !fOriginal) {
00114 Error("IsValid", "row closed");
00115 return kFALSE;
00116 }
00117 if (field < 0 || field >= fColumnCount) {
00118 Error("IsValid", "field index out of bounds");
00119 return kFALSE;
00120 }
00121 return kTRUE;
00122 }
00123
00124
00125 ULong_t TTreeRow::GetFieldLength(Int_t field)
00126 {
00127
00128
00129 if (!IsValid(field))
00130 return 0;
00131
00132 if (fOriginal)
00133 return fOriginal->GetFieldLength(field);
00134
00135 if (field > 0) return fFields[field] - fFields[field-1] -1;
00136 else return fFields[0] -1;
00137 }
00138
00139
00140 const char *TTreeRow::GetField(Int_t field)
00141 {
00142
00143
00144 if (!IsValid(field))
00145 return 0;
00146
00147 if (fOriginal)
00148 return fOriginal->GetField(field);
00149
00150 if (field > 0) return fRow +fFields[field-1];
00151 else return fRow;
00152 }
00153
00154
00155 void TTreeRow::SetRow(const Int_t *fields, const char *row)
00156 {
00157
00158
00159 if (!fColumnCount) return;
00160 if (fFields) delete [] fFields;
00161 Int_t nch = fields[fColumnCount-1];
00162 fFields = new Int_t[fColumnCount];
00163 fOriginal = 0;
00164 fRow = new char[nch];
00165 for (Int_t i=0;i<fColumnCount;i++) fFields[i] = fields[i];
00166 memcpy(fRow,row,nch);
00167 }
00168
00169
00170 void TTreeRow::Streamer(TBuffer &R__b)
00171 {
00172
00173 UInt_t R__s, R__c;
00174 if (R__b.IsReading()) {
00175 R__b.ReadVersion(&R__s, &R__c);
00176 TSQLRow::Streamer(R__b);
00177 R__b >> fColumnCount;
00178 fFields = new Int_t[fColumnCount];
00179 R__b.ReadFastArray(fFields,fColumnCount);
00180 Int_t nch;
00181 R__b >> nch;
00182 fRow = new char[nch];
00183 R__b.ReadFastArray(fRow,nch);
00184 R__b.CheckByteCount(R__s, R__c, TTreeRow::IsA());
00185 } else {
00186 R__c = R__b.WriteVersion(TTreeRow::Class(),kTRUE);
00187 TSQLRow::Streamer(R__b);
00188 R__b << fColumnCount;
00189 R__b.WriteFastArray(fFields,fColumnCount);
00190 Int_t nch = fFields[fColumnCount-1];
00191 R__b << nch;
00192 R__b.WriteFastArray(fRow,nch);
00193 R__b.SetByteCount(R__c,kTRUE);
00194 }
00195 }