Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TTreeResult.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 TTreeResult
13\ingroup tree
14
15Class defining interface to a TTree query result with the same
16interface as for SQL databases. A TTreeResult is returned by
17TTree::Query() (actually TTreePlayer::Query()).
18
19Related classes are TTreeRow.
20*/
21
22#include "TTreeResult.h"
23#include "TTreeRow.h"
24#include "TString.h"
25#include "TObjArray.h"
26
28
29////////////////////////////////////////////////////////////////////////////////
30/// Create a query result object.
31
33{
34 fColumnCount = 0;
35 fRowCount = 0;
36 fFields = 0;
37 fResult = 0;
38 fNextRow = 0;
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Create a query result object.
43
45{
46 fColumnCount = nfields;
47 fRowCount = 0;
48 fFields = new TString [nfields];
49 fResult = new TObjArray;
50 fNextRow = 0;
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Cleanup result object.
55
57{
58 if (fResult)
59 Close();
60
61 delete [] fFields;
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Close query result.
66
68{
69 if (!fResult)
70 return;
71
72 fResult->Delete();
73 delete fResult;
74 fResult = 0;
75 fRowCount = 0;
76}
77
78////////////////////////////////////////////////////////////////////////////////
79/// Check if result set is open and field index within range.
80
82{
83 if (!fResult) {
84 Error("IsValid", "result set closed");
85 return kFALSE;
86 }
87 if (field < 0 || field >= GetFieldCount()) {
88 Error("IsValid", "field index out of bounds");
89 return kFALSE;
90 }
91 return kTRUE;
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Get number of fields in result.
96
98{
99 if (!fResult) {
100 Error("GetFieldCount", "result set closed");
101 return 0;
102 }
103 return fColumnCount;
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Get name of specified field.
108
110{
111 if (!IsValid(field))
112 return 0;
113
114 return fFields[field].Data();
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// Get next query result row. The returned object must be
119/// deleted by the user and becomes invalid when the result set is
120/// closed or deleted.
121
123{
124 if (!fResult) {
125 Error("Next", "result set closed");
126 return 0;
127 }
128
129 if (fNextRow >= fRowCount)
130 return 0;
131 else {
133 fNextRow++;
134 return row;
135 }
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Add field name to result set. This is an internal method that is not
140/// exported via the abstract interface and that should not be user called.
141
142void TTreeResult::AddField(Int_t field, const char *fieldname)
143{
144 if (!IsValid(field))
145 return;
146
147 fFields[field] = fieldname;
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Adopt a row to result set. This is an internal method that is not
152/// exported via the abstract interface and that should not be user called.
153
155{
156 if (!fResult) {
157 Error("AddRow", "result set closed");
158 return;
159 }
160
161 fResult->Add(row);
162 fRowCount++;
163}
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
An array of TObjects.
Definition TObjArray.h:37
void Add(TObject *obj)
Definition TObjArray.h:74
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
TObject * At(Int_t idx) const
Definition TObjArray.h:166
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:893
Int_t fRowCount
Definition TSQLResult.h:35
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
Class defining interface to a TTree query result with the same interface as for SQL databases.
Definition TTreeResult.h:34
const char * GetFieldName(Int_t field)
Get name of specified field.
Int_t fColumnCount
number of columns in result
Definition TTreeResult.h:39
void Close(Option_t *option="")
Close query result.
TTreeResult()
Create a query result object.
Int_t fNextRow
row iterator
Definition TTreeResult.h:42
TSQLRow * Next()
Get next query result row.
TString * fFields
[fColumnCount] array containing field strings
Definition TTreeResult.h:40
virtual ~TTreeResult()
Cleanup result object.
Int_t GetFieldCount()
Get number of fields in result.
Bool_t IsValid(Int_t field)
Check if result set is open and field index within range.
void AddRow(TSQLRow *row)
Adopt a row to result set.
TObjArray * fResult
query result (TTreeRow objects)
Definition TTreeResult.h:41
void AddField(Int_t field, const char *fieldname)
Add field name to result set.
Class defining interface to a row of a TTree query result.
Definition TTreeRow.h:29