Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
VectorVar.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 15/2/2016
2
4//
5// VectorVar
6//
7// A "global variable" referencing a std::vector of basic data
8//
10
11#include "VectorVar.h"
12#include "THaVar.h"
13#include "TError.h"
14#include <vector>
15#include <cassert>
16#include <stdexcept>
17
18#define kInvalid THaVar::kInvalid
19#define kInvalidInt THaVar::kInvalidInt
20
21using namespace std;
22
23namespace Podd {
24
25//_____________________________________________________________________________
26VectorVar::VectorVar( THaVar* pvar, const void* addr, VarType type )
27 : Variable(pvar,addr,type), fDim(0)
28{
29 // Constructor
30
31 if( !VerifyNonArrayName(GetName()) ) {
32 fValueP = nullptr;
33 return;
34 }
35}
36
37//_____________________________________________________________________________
39{
40 // Get number of elements of the variable
41
42 assert( fValueP && IsVector() );
43
44 // To be safe, cast the pointer to the exact type of vector
45 vector<int>::size_type siz = kInvalidInt;
46 switch( fType ) {
47 case kIntV: {
48 const vector<int>& vec = *static_cast< const vector<int>* >(fValueP);
49 siz = vec.size();
50 break;
51 }
52 case kUIntV: {
53 const vector<unsigned int>& vec = *static_cast< const vector<unsigned int>* >(fValueP);
54 siz = vec.size();
55 break;
56 }
57 case kFloatV: {
58 const vector<float>& vec = *static_cast< const vector<float>* >(fValueP);
59 siz = vec.size();
60 break;
61 }
62 case kDoubleV: {
63 const vector<double>& vec = *static_cast< const vector<double>* >(fValueP);
64 siz = vec.size();
65 break;
66 }
67 //TODO: support matrix types
68 default:
69 assert(false); // should never happen, object ill-constructed
70 break;
71 }
72 if( siz > kMaxInt )
73 throw overflow_error("Podd::VectorVar array size overflow");
74 return static_cast<Int_t>(siz);
75}
76
77//_____________________________________________________________________________
79{
80 // Number of dimensions
81
82 return 1;
83}
84
85//_____________________________________________________________________________
87{
88 // Return array of dimensions of the array
89
90 fDim = GetLen();
91 return &fDim;
92}
93
94//_____________________________________________________________________________
95const void* VectorVar::GetDataPointer( Int_t i ) const
96{
97 // Get pointer to data in memory, including to data in a non-contiguous
98 // pointer array and data in objects stored in a TSeqCollection (TClonesArray)
99
100 const char* const here = "GetDataPointer()";
101
102 assert( fValueP && IsVector() );
103
104 if( GetLen() == 0 )
105 return nullptr;
106
107 if( i<0 || i>=GetLen() ) {
108 fSelf->Error(here, "Index out of range, variable %s, index %d", GetName(), i );
109 return nullptr;
110 }
111
112 switch( fType ) {
113 case kIntV: {
114 const vector<int>& vec = *static_cast<const vector<int>* >(fValueP);
115 return &vec[i];
116 }
117 case kUIntV: {
118 const vector<unsigned int>& vec = *static_cast<const vector<unsigned int>* >(fValueP);
119 return &vec[i];
120 }
121 case kFloatV: {
122 const vector<float>& vec = *static_cast<const vector<float>* >(fValueP);
123 return &vec[i];
124 }
125 case kDoubleV: {
126 const vector<double>& vec = *static_cast<const vector<double>* >(fValueP);
127 return &vec[i];
128 }
129 //TODO: support matrix types?
130 default:
131 break;
132 }
133
134 return nullptr;
135}
136
137//_____________________________________________________________________________
139{
140 // Compare the size counter of this variable to that of 'rhs'.
141 // As currently implemented, std::vector variables are always different
142 // since their sizes are in principle independent
143
144 return false;
145}
146
147//_____________________________________________________________________________
149{
150 // Data are basic (POD variable or array)
151
152 return false;
153}
154
155//_____________________________________________________________________________
157{
158 // Data are contiguous in memory
159
160 return true;
161}
162
163//_____________________________________________________________________________
165{
166 // Data are an array of pointers to data
167
168 //TODO: support matrix types
169 return false;
170}
171
172//_____________________________________________________________________________
174{
175 // Variable refers to an object that can be streamed via ROOT I/O
176
177 return true;
178}
179
180//_____________________________________________________________________________
182{
183 // Variable is a variable-size array
184
185 return true;
186}
187
188//_____________________________________________________________________________
189
190}// namespace Podd
int Int_t
bool Bool_t
const Int_t kMaxInt
#define kInvalidInt
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
static const char *const here
Definition THaVar.cxx:64
const void * fValueP
Definition Variable.h:60
Bool_t VerifyNonArrayName(const char *name) const
Definition Variable.cxx:38
const char * GetName() const
Definition Variable.cxx:56
virtual Bool_t IsVector() const
Definition Variable.cxx:485
THaVar * fSelf
Definition Variable.h:59
VarType fType
Definition Variable.h:61
virtual const void * GetDataPointer(Int_t i=0) const
Definition VectorVar.cxx:95
virtual Bool_t HasSameSize(const Variable &rhs) const
VectorVar(THaVar *pvar, const void *addr, VarType type)
Definition VectorVar.cxx:26
virtual Int_t GetNdim() const
Definition VectorVar.cxx:78
virtual Bool_t IsVarArray() const
virtual Bool_t IsStreamable() const
virtual const Int_t * GetDim() const
Definition VectorVar.cxx:86
virtual Bool_t IsPointerArray() const
virtual Int_t GetLen() const
Definition VectorVar.cxx:38
virtual Bool_t IsContiguous() const
virtual Bool_t IsBasic() const
virtual void Error(const char *method, const char *msgfmt,...) const
STL namespace.