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
24
25////////////////////////////////////////////////////////////////////////////////
26/// Single row of a query result.
27
29{
30 fColumnCount = 0;
31 fFields = nullptr;
32 fOriginal = nullptr;
33 fRow = nullptr;
34
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Single row of a query result.
39
41{
43 fFields = nullptr;
44 fOriginal = nullptr;
45 fRow = nullptr;
46
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// Single row of a query result.
51
52TTreeRow::TTreeRow(Int_t nfields, const Int_t *fields, const char *row)
53{
55 fFields = nullptr;
56 fOriginal = nullptr;
57 fRow = nullptr;
58 SetRow(fields,row);
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// This is a shallow copy of a real row, i.e. it only contains
63/// a pointer to the original.
64
66{
67 fFields = nullptr;
68 fOriginal = nullptr;
69 fColumnCount = 0;
70 fRow = nullptr;
71
72 if (!original) {
73 Error("TTreeRow", "original may not be 0");
74 return;
75 }
76 if (original->IsA() != TTreeRow::Class()) {
77 Error("TTreeRow", "original must be a TTreeRow");
78 return;
79 }
80
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Destroy row object.
87
89{
90 if (fFields)
91 Close();
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Close row.
96
98{
99 if (fRow) delete [] fRow;
100 if (fFields) delete [] fFields;
101 fColumnCount = 0;
102 fOriginal = nullptr;
103 fRow = nullptr;
104 fFields = nullptr;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Check if row is open and field index within range.
109
111{
112 if (!fFields && !fOriginal) {
113 Error("IsValid", "row closed");
114 return false;
115 }
117 Error("IsValid", "field index out of bounds");
118 return false;
119 }
120 return true;
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Get length in bytes of specified field.
125
127{
128 if (!IsValid(field))
129 return 0;
130
131 if (fOriginal)
133
134 if (field > 0) return fFields[field] - fFields[field-1] -1;
135 else return fFields[0] -1;
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Get specified field from row (0 <= field < GetFieldCount()).
140
142{
143 if (!IsValid(field))
144 return nullptr;
145
146 if (fOriginal)
147 return fOriginal->GetField(field);
148
149 if (field > 0) return fRow +fFields[field-1];
150 else return fRow;
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// The field and row information.
155
156void TTreeRow::SetRow(const Int_t *fields, const char *row)
157{
158 if (!fColumnCount) return;
159 if (fFields) delete [] fFields;
162 fOriginal = nullptr;
163 if (fRow) delete [] fRow;
164 fRow = new char[nch];
165 for (Int_t i=0;i<fColumnCount;i++) fFields[i] = fields[i];
166 memcpy(fRow,row,nch);
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Stream an object of class TTreeRow.
171
173{
175 if (R__b.IsReading()) {
176 R__b.ReadVersion(&R__s, &R__c);
180 R__b.ReadFastArray(fFields,fColumnCount);
181 Int_t nch;
182 R__b >> nch;
183 fRow = new char[nch];
184 R__b.ReadFastArray(fRow,nch);
185 R__b.CheckByteCount(R__s, R__c, TTreeRow::IsA());
186 } else {
187 R__c = R__b.WriteVersion(TTreeRow::Class(),true);
190 R__b.WriteFastArray(fFields,fColumnCount);
192 R__b << nch;
193 R__b.WriteFastArray(fRow,nch);
194 R__b.SetByteCount(R__c,true);
195 }
196}
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:972
static TClass * Class()
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual TClass * IsA() const
Definition TObject.h:246
void Streamer(TBuffer &) override
Stream an object of class TObject.
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:88
ULong_t GetFieldLength(Int_t field) override
Get length in bytes of specified field.
Definition TTreeRow.cxx:126
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:141
void SetRow(const Int_t *fields, const char *row)
The field and row information.
Definition TTreeRow.cxx:156
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:110
char * fRow
string with all the fColumnCount fields
Definition TTreeRow.h:37
TTreeRow()
Single row of a query result.
Definition TTreeRow.cxx:28
void Close(Option_t *option="") override
Close row.
Definition TTreeRow.cxx:97