ROOT logo
// @(#)root/tree:$Id: TTreeRow.cxx 31603 2009-12-07 18:59:15Z pcanal $
// Author: Fons Rademakers   30/11/99

/*************************************************************************
 * 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.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TTreeRow                                                             //
//                                                                      //
// Class defining interface to a row of a TTree query result.           //
// Objects of this class are created by TTreeResult methods.            //
//                                                                      //
// Related classes are TTreeResult.                                     //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TTreeRow.h"
#include "TObjArray.h"

ClassImp(TTreeRow)

//______________________________________________________________________________
TTreeRow::TTreeRow()
{
   // Single row of a query result.

   fColumnCount = 0;
   fFields      = 0;
   fOriginal    = 0;
   fRow         = 0;
   
}

//______________________________________________________________________________
TTreeRow::TTreeRow(Int_t nfields)
{
   // Single row of a query result.

   fColumnCount = nfields;
   fFields      = 0;
   fOriginal    = 0;
   fRow         = 0;
   
}

//______________________________________________________________________________
TTreeRow::TTreeRow(Int_t nfields, const Int_t *fields, const char *row)
{
   // Single row of a query result.

   fColumnCount = nfields;
   fFields      = 0;
   fOriginal    = 0;
   fRow         = 0;
   SetRow(fields,row);
}

//______________________________________________________________________________
TTreeRow::TTreeRow(TSQLRow *original)
{
   // This is a shallow copy of a real row, i.e. it only contains
   // a pointer to the original.

   fFields      = 0;
   fOriginal    = 0;
   fColumnCount = 0;
   fRow         = 0;
   
   if (!original) {
      Error("TTreeRow", "original may not be 0");
      return;
   }
   if (original->IsA() != TTreeRow::Class()) {
      Error("TTreeRow", "original must be a TTreeRow");
      return;
   }

   fOriginal = (TTreeRow*) original;
   fColumnCount = fOriginal->fColumnCount;
}

//______________________________________________________________________________
TTreeRow::~TTreeRow()
{
   // Destroy row object.

   if (fFields)
      Close();
}

//______________________________________________________________________________
void TTreeRow::Close(Option_t *)
{
   // Close row.

   if (fRow)    delete [] fRow;
   if (fFields) delete [] fFields;
   fColumnCount = 0;
   fOriginal = 0;
}

//______________________________________________________________________________
Bool_t TTreeRow::IsValid(Int_t field)
{
   // Check if row is open and field index within range.

   if (!fFields && !fOriginal) {
      Error("IsValid", "row closed");
      return kFALSE;
   }
   if (field < 0 || field >= fColumnCount) {
      Error("IsValid", "field index out of bounds");
      return kFALSE;
   }
   return kTRUE;
}

//______________________________________________________________________________
ULong_t TTreeRow::GetFieldLength(Int_t field)
{
   // Get length in bytes of specified field.

   if (!IsValid(field))
      return 0;

   if (fOriginal)
      return fOriginal->GetFieldLength(field);

   if (field > 0) return fFields[field] - fFields[field-1] -1;
   else           return fFields[0] -1;
}

//______________________________________________________________________________
const char *TTreeRow::GetField(Int_t field) 
{
   // Get specified field from row (0 <= field < GetFieldCount()).

   if (!IsValid(field))
      return 0;

   if (fOriginal)
      return fOriginal->GetField(field);

   if (field > 0) return fRow +fFields[field-1];
   else           return fRow;
}

//______________________________________________________________________________
void TTreeRow::SetRow(const Int_t *fields, const char *row)
{
   // The field and row information.

   if (!fColumnCount) return;
   if (fFields) delete [] fFields;
   Int_t nch    = fields[fColumnCount-1];
   fFields      = new Int_t[fColumnCount];
   fOriginal    = 0;
   fRow         = new char[nch];
   for (Int_t i=0;i<fColumnCount;i++) fFields[i] = fields[i];
   memcpy(fRow,row,nch);
}

//______________________________________________________________________________
void TTreeRow::Streamer(TBuffer &R__b)
{
   // Stream an object of class TTreeRow.
   UInt_t R__s, R__c;
   if (R__b.IsReading()) {
      R__b.ReadVersion(&R__s, &R__c);
      TSQLRow::Streamer(R__b);
      R__b >> fColumnCount;
      fFields = new Int_t[fColumnCount];
      R__b.ReadFastArray(fFields,fColumnCount);
      Int_t nch;
      R__b >> nch;
      fRow = new char[nch];
      R__b.ReadFastArray(fRow,nch);
      R__b.CheckByteCount(R__s, R__c, TTreeRow::IsA());
   } else {
      R__c = R__b.WriteVersion(TTreeRow::Class(),kTRUE);
      TSQLRow::Streamer(R__b);
      R__b << fColumnCount;
      R__b.WriteFastArray(fFields,fColumnCount);
      Int_t nch = fFields[fColumnCount-1];
      R__b << nch;
      R__b.WriteFastArray(fRow,nch);
      R__b.SetByteCount(R__c,kTRUE);
   }
}
 TTreeRow.cxx:1
 TTreeRow.cxx:2
 TTreeRow.cxx:3
 TTreeRow.cxx:4
 TTreeRow.cxx:5
 TTreeRow.cxx:6
 TTreeRow.cxx:7
 TTreeRow.cxx:8
 TTreeRow.cxx:9
 TTreeRow.cxx:10
 TTreeRow.cxx:11
 TTreeRow.cxx:12
 TTreeRow.cxx:13
 TTreeRow.cxx:14
 TTreeRow.cxx:15
 TTreeRow.cxx:16
 TTreeRow.cxx:17
 TTreeRow.cxx:18
 TTreeRow.cxx:19
 TTreeRow.cxx:20
 TTreeRow.cxx:21
 TTreeRow.cxx:22
 TTreeRow.cxx:23
 TTreeRow.cxx:24
 TTreeRow.cxx:25
 TTreeRow.cxx:26
 TTreeRow.cxx:27
 TTreeRow.cxx:28
 TTreeRow.cxx:29
 TTreeRow.cxx:30
 TTreeRow.cxx:31
 TTreeRow.cxx:32
 TTreeRow.cxx:33
 TTreeRow.cxx:34
 TTreeRow.cxx:35
 TTreeRow.cxx:36
 TTreeRow.cxx:37
 TTreeRow.cxx:38
 TTreeRow.cxx:39
 TTreeRow.cxx:40
 TTreeRow.cxx:41
 TTreeRow.cxx:42
 TTreeRow.cxx:43
 TTreeRow.cxx:44
 TTreeRow.cxx:45
 TTreeRow.cxx:46
 TTreeRow.cxx:47
 TTreeRow.cxx:48
 TTreeRow.cxx:49
 TTreeRow.cxx:50
 TTreeRow.cxx:51
 TTreeRow.cxx:52
 TTreeRow.cxx:53
 TTreeRow.cxx:54
 TTreeRow.cxx:55
 TTreeRow.cxx:56
 TTreeRow.cxx:57
 TTreeRow.cxx:58
 TTreeRow.cxx:59
 TTreeRow.cxx:60
 TTreeRow.cxx:61
 TTreeRow.cxx:62
 TTreeRow.cxx:63
 TTreeRow.cxx:64
 TTreeRow.cxx:65
 TTreeRow.cxx:66
 TTreeRow.cxx:67
 TTreeRow.cxx:68
 TTreeRow.cxx:69
 TTreeRow.cxx:70
 TTreeRow.cxx:71
 TTreeRow.cxx:72
 TTreeRow.cxx:73
 TTreeRow.cxx:74
 TTreeRow.cxx:75
 TTreeRow.cxx:76
 TTreeRow.cxx:77
 TTreeRow.cxx:78
 TTreeRow.cxx:79
 TTreeRow.cxx:80
 TTreeRow.cxx:81
 TTreeRow.cxx:82
 TTreeRow.cxx:83
 TTreeRow.cxx:84
 TTreeRow.cxx:85
 TTreeRow.cxx:86
 TTreeRow.cxx:87
 TTreeRow.cxx:88
 TTreeRow.cxx:89
 TTreeRow.cxx:90
 TTreeRow.cxx:91
 TTreeRow.cxx:92
 TTreeRow.cxx:93
 TTreeRow.cxx:94
 TTreeRow.cxx:95
 TTreeRow.cxx:96
 TTreeRow.cxx:97
 TTreeRow.cxx:98
 TTreeRow.cxx:99
 TTreeRow.cxx:100
 TTreeRow.cxx:101
 TTreeRow.cxx:102
 TTreeRow.cxx:103
 TTreeRow.cxx:104
 TTreeRow.cxx:105
 TTreeRow.cxx:106
 TTreeRow.cxx:107
 TTreeRow.cxx:108
 TTreeRow.cxx:109
 TTreeRow.cxx:110
 TTreeRow.cxx:111
 TTreeRow.cxx:112
 TTreeRow.cxx:113
 TTreeRow.cxx:114
 TTreeRow.cxx:115
 TTreeRow.cxx:116
 TTreeRow.cxx:117
 TTreeRow.cxx:118
 TTreeRow.cxx:119
 TTreeRow.cxx:120
 TTreeRow.cxx:121
 TTreeRow.cxx:122
 TTreeRow.cxx:123
 TTreeRow.cxx:124
 TTreeRow.cxx:125
 TTreeRow.cxx:126
 TTreeRow.cxx:127
 TTreeRow.cxx:128
 TTreeRow.cxx:129
 TTreeRow.cxx:130
 TTreeRow.cxx:131
 TTreeRow.cxx:132
 TTreeRow.cxx:133
 TTreeRow.cxx:134
 TTreeRow.cxx:135
 TTreeRow.cxx:136
 TTreeRow.cxx:137
 TTreeRow.cxx:138
 TTreeRow.cxx:139
 TTreeRow.cxx:140
 TTreeRow.cxx:141
 TTreeRow.cxx:142
 TTreeRow.cxx:143
 TTreeRow.cxx:144
 TTreeRow.cxx:145
 TTreeRow.cxx:146
 TTreeRow.cxx:147
 TTreeRow.cxx:148
 TTreeRow.cxx:149
 TTreeRow.cxx:150
 TTreeRow.cxx:151
 TTreeRow.cxx:152
 TTreeRow.cxx:153
 TTreeRow.cxx:154
 TTreeRow.cxx:155
 TTreeRow.cxx:156
 TTreeRow.cxx:157
 TTreeRow.cxx:158
 TTreeRow.cxx:159
 TTreeRow.cxx:160
 TTreeRow.cxx:161
 TTreeRow.cxx:162
 TTreeRow.cxx:163
 TTreeRow.cxx:164
 TTreeRow.cxx:165
 TTreeRow.cxx:166
 TTreeRow.cxx:167
 TTreeRow.cxx:168
 TTreeRow.cxx:169
 TTreeRow.cxx:170
 TTreeRow.cxx:171
 TTreeRow.cxx:172
 TTreeRow.cxx:173
 TTreeRow.cxx:174
 TTreeRow.cxx:175
 TTreeRow.cxx:176
 TTreeRow.cxx:177
 TTreeRow.cxx:178
 TTreeRow.cxx:179
 TTreeRow.cxx:180
 TTreeRow.cxx:181
 TTreeRow.cxx:182
 TTreeRow.cxx:183
 TTreeRow.cxx:184
 TTreeRow.cxx:185
 TTreeRow.cxx:186
 TTreeRow.cxx:187
 TTreeRow.cxx:188
 TTreeRow.cxx:189
 TTreeRow.cxx:190
 TTreeRow.cxx:191
 TTreeRow.cxx:192
 TTreeRow.cxx:193
 TTreeRow.cxx:194
 TTreeRow.cxx:195