Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TTreeRow.cxx
Go to the documentation of this file.
1// @(#)root/tree:$Id$
2// Author: Fons Rademakers 30/11/99
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TTreeRow
13\ingroup tree
14
15Class defining interface to a row of a TTree query result.
16Objects of this class are created by TTreeResult methods.
17
18Related classes are TTreeResult.
19*/
20
21#include "TTreeRow.h"
22#include "TBuffer.h"
23
25
26////////////////////////////////////////////////////////////////////////////////
27/// Single row of a query result.
28
30{
31 fColumnCount = 0;
32 fFields = nullptr;
33 fOriginal = nullptr;
34 fRow = nullptr;
35
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// Single row of a query result.
40
42{
43 fColumnCount = nfields;
44 fFields = nullptr;
45 fOriginal = nullptr;
46 fRow = nullptr;
47
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Single row of a query result.
52
53TTreeRow::TTreeRow(Int_t nfields, const Int_t *fields, const char *row)
54{
55 fColumnCount = nfields;
56 fFields = nullptr;
57 fOriginal = nullptr;
58 fRow = nullptr;
59 SetRow(fields,row);
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// This is a shallow copy of a real row, i.e. it only contains
64/// a pointer to the original.
65
67{
68 fFields = nullptr;
69 fOriginal = nullptr;
70 fColumnCount = 0;
71 fRow = nullptr;
72
73 if (!original) {
74 Error("TTreeRow", "original may not be 0");
75 return;
76 }
77 if (original->IsA() != TTreeRow::Class()) {
78 Error("TTreeRow", "original must be a TTreeRow");
79 return;
80 }
81
82 fOriginal = (TTreeRow*) original;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Destroy row object.
88
90{
91 if (fFields)
92 Close();
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Close row.
97
99{
100 if (fRow) delete [] fRow;
101 if (fFields) delete [] fFields;
102 fColumnCount = 0;
103 fOriginal = nullptr;
104 fRow = nullptr;
105 fFields = nullptr;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Check if row is open and field index within range.
110
112{
113 if (!fFields && !fOriginal) {
114 Error("IsValid", "row closed");
115 return false;
116 }
117 if (field < 0 || field >= fColumnCount) {
118 Error("IsValid", "field index out of bounds");
119 return false;
120 }
121 return true;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Get length in bytes of specified field.
126
128{
129 if (!IsValid(field))
130 return 0;
131
132 if (fOriginal)
133 return fOriginal->GetFieldLength(field);
134
135 if (field > 0) return fFields[field] - fFields[field-1] -1;
136 else return fFields[0] -1;
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Get specified field from row (0 <= field < GetFieldCount()).
141
142const char *TTreeRow::GetField(Int_t field)
143{
144 if (!IsValid(field))
145 return nullptr;
146
147 if (fOriginal)
148 return fOriginal->GetField(field);
149
150 if (field > 0) return fRow +fFields[field-1];
151 else return fRow;
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// The field and row information.
156
157void TTreeRow::SetRow(const Int_t *fields, const char *row)
158{
159 if (!fColumnCount) return;
160 if (fFields) delete [] fFields;
161 Int_t nch = fields[fColumnCount-1];
163 fOriginal = nullptr;
164 if (fRow) delete [] fRow;
165 fRow = new char[nch];
166 for (Int_t i=0;i<fColumnCount;i++) fFields[i] = fields[i];
167 memcpy(fRow,row,nch);
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Stream an object of class TTreeRow.
172
173void TTreeRow::Streamer(TBuffer &R__b)
174{
175 UInt_t R__s, R__c;
176 if (R__b.IsReading()) {
177 R__b.ReadVersion(&R__s, &R__c);
178 TSQLRow::Streamer(R__b);
179 R__b >> fColumnCount;
182 Int_t nch;
183 R__b >> nch;
184 fRow = new char[nch];
185 R__b.ReadFastArray(fRow,nch);
186 R__b.CheckByteCount(R__s, R__c, TTreeRow::IsA());
187 } else {
188 R__c = R__b.WriteVersion(TTreeRow::Class(),true);
189 TSQLRow::Streamer(R__b);
190 R__b << fColumnCount;
192 Int_t nch = fFields ? fFields[fColumnCount-1] : 0;
193 R__b << nch;
194 R__b.WriteFastArray(fRow,nch);
195 R__b.SetByteCount(R__c,true);
196 }
197}
int Int_t
Definition RtypesCore.h:45
unsigned long ULong_t
Definition RtypesCore.h:55
unsigned int UInt_t
Definition RtypesCore.h:46
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual void WriteFastArray(const Bool_t *b, Long64_t n)=0
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:894
static TClass * Class()
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:993
virtual TClass * IsA() const
Definition TObject.h:243
void Streamer(TBuffer &) override
Stream an object of class TObject.
TClass * IsA() const override
Definition TSQLRow.h:43
Class defining interface to a row of a TTree query result.
Definition TTreeRow.h:29
Int_t fColumnCount
number of columns in row
Definition TTreeRow.h:35
~TTreeRow() override
Destroy row object.
Definition TTreeRow.cxx:89
ULong_t GetFieldLength(Int_t field) override
Get length in bytes of specified field.
Definition TTreeRow.cxx:127
Int_t * fFields
[fColumnCount] index in fRow of the end of each field
Definition TTreeRow.h:36
const char * GetField(Int_t field) override
Get specified field from row (0 <= field < GetFieldCount()).
Definition TTreeRow.cxx:142
void SetRow(const Int_t *fields, const char *row)
The field and row information.
Definition TTreeRow.cxx:157
TTreeRow * fOriginal
! pointer to original row
Definition TTreeRow.h:38
bool IsValid(Int_t field)
Check if row is open and field index within range.
Definition TTreeRow.cxx:111
char * fRow
string with all the fColumnCount fields
Definition TTreeRow.h:37
TTreeRow()
Single row of a query result.
Definition TTreeRow.cxx:29
void Close(Option_t *option="") override
Close row.
Definition TTreeRow.cxx:98