Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
FixedArrayVar.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 15/2/2016
2
4//
5// FixedArrayVar
6//
7// A "global variable" referencing a fixed size array of basic data.
8//
10
11#include "FixedArrayVar.h"
12#include "THaVar.h"
13#include "TError.h"
14#include <iostream>
15#include <cstring>
16#include <typeinfo> // for typeid
17
18using namespace std;
19
20namespace Podd {
21
22//_____________________________________________________________________________
23FixedArrayVar::FixedArrayVar( THaVar* pvar, const void* addr, VarType type )
24 : Variable(pvar,addr,type), fParsedName(GetName())
25{
26 // Constructor
27
29 fValueP = nullptr;
30 return;
31 }
32
33 fSelf->TNamed::SetName( fParsedName.GetName() );
34}
35
36//_____________________________________________________________________________
38{
39 // Return true if the variable string has valid array syntax
40
41 const char* const here = "FixedArrayVar::VerifyArrayName";
42
43 if( parsed_name.IsError() ) {
44 fSelf->Error( here, "Malformed array specification for variable %s",
45 GetName() );
46 return false;
47 } else if( !parsed_name.IsArray() ) {
48 fSelf->Error( here, "Specification \"%s\" for variable %s is not a "
49 "fixed array", parsed_name.GetName(), GetName() );
50 return false;
51 }
52
53 return true;
54}
55
56//_____________________________________________________________________________
58{
59 // Get number of elements of the variable
60
61 return fParsedName.GetLen();
62}
63
64//_____________________________________________________________________________
66{
67 // Get number of elements of the variable
68
69 return fParsedName.GetNdim();
70}
71
72//_____________________________________________________________________________
74{
75 // Return array of dimensions of the array. Scalars always return a
76 // pointer to 1 (as with array definition [1]).
77
78 return fParsedName.GetDim();
79}
80
81//_____________________________________________________________________________
83{
84 // Compare the size (=number of elements) of this variable to that of 'rhs'.
85
86 if( typeid(*this) != typeid(rhs) )
87 return false;
88
89 const auto* const other = dynamic_cast<const FixedArrayVar*>(&rhs);
90 assert( other );
91 if( !other )
92 return false;
93
94 return ( fParsedName.GetNdim() == other->fParsedName.GetNdim() &&
95 fParsedName.GetLen() == other->fParsedName.GetLen() );
96}
97
98//_____________________________________________________________________________
100{
101 // Data are contiguous in memory
102
103 return !IsPointerArray();
104}
105
106//_____________________________________________________________________________
108{
109 // Data are an array of pointers to data
110
111 return fType>=kDouble2P && fType <= kObject2P;
112}
113
114//_____________________________________________________________________________
116{
117 // Variable is a variable-sized array
118
119 return false;
120}
121
122//_____________________________________________________________________________
124{
125 // Print a description of this variable. If option=="FULL" (default), also
126 // print current data
127
128 fSelf->TNamed::Print(option);
129
130 if( strcmp(option, "FULL") != 0 ) return;
131
132 cout << "(" << GetTypeName() << ")=[";
133 fParsedName.Print("dimonly");
134 cout << "]";
135 for( int i=0; i<GetLen(); i++ ) {
136 cout << " ";
137 if( IsFloat() )
138 cout << GetValue(i);
139 else
140 cout << GetValueInt(i);
141 }
142 cout << endl;
143}
144
145//_____________________________________________________________________________
146void FixedArrayVar::SetName( const char* name )
147{
148 // Set the name of the variable
149
150 THaArrayString new_name = name;
151 if( !VerifyArrayName(new_name) )
152 return;
153
154 fSelf->TNamed::SetName( new_name );
155 fParsedName = new_name;
156}
157
158//_____________________________________________________________________________
159void FixedArrayVar::SetNameTitle( const char* name, const char* descript )
160{
161 // Set name and description of the variable
162
163 THaArrayString new_name = name;
164 if( !VerifyArrayName(new_name) )
165 return;
166
167 fSelf->TNamed::SetNameTitle( new_name, descript );
168 fParsedName = new_name;
169}
170
171//_____________________________________________________________________________
172
173} //namespace Podd
int Int_t
bool Bool_t
const char Option_t
Option_t Option_t option
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
char name[80]
static const char *const here
Definition THaVar.cxx:64
virtual void SetNameTitle(const char *name, const char *desc)
virtual Bool_t HasSameSize(const Variable &rhs) const
virtual void SetName(const char *)
virtual Int_t GetLen() const
virtual Bool_t IsContiguous() const
virtual void Print(Option_t *opt="FULL") const
virtual Bool_t IsPointerArray() const
virtual const Int_t * GetDim() const
THaArrayString fParsedName
virtual Int_t GetNdim() const
virtual Bool_t IsVarArray() const
Bool_t VerifyArrayName(const THaArrayString &astr) const
FixedArrayVar(THaVar *pvar, const void *addr, VarType type)
virtual Bool_t IsFloat() const
Definition Variable.cxx:441
const void * fValueP
Definition Variable.h:60
virtual Double_t GetValue(Int_t i=0) const
Definition Variable.cxx:109
const char * GetName() const
Definition Variable.cxx:56
THaVar * fSelf
Definition Variable.h:59
VarType fType
Definition Variable.h:61
virtual Long64_t GetValueInt(Int_t i=0) const
Definition Variable.cxx:188
const char * GetTypeName() const
Definition Variable.cxx:68
virtual void Print(Option_t *opt="") const
Bool_t IsArray() const
const Int_t * GetDim() const
Bool_t IsError() const
Int_t GetNdim() const
const char * GetName() const
Int_t GetLen() const
virtual void Error(const char *method, const char *msgfmt,...) const
STL namespace.