Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
SeqCollectionVar.cxx
Go to the documentation of this file.
1//*-- Author : Ole Hansen 17/2/2016
2
4//
5// SeqCollectionVar
6//
7// A "global variable" referencing data in objects in a TSeqCollection
8//
10
11#include "SeqCollectionVar.h"
12#include "THaVar.h"
13#include "TError.h"
14#include "TClass.h"
15#include "TObjArray.h"
16#include <cassert>
17
18#define kInvalid THaVar::kInvalid
19#define kInvalidInt THaVar::kInvalidInt
20
21using namespace std;
22
23namespace Podd {
24
25//_____________________________________________________________________________
27 VarType type, Int_t offset )
28 : Variable(pvar,addr,type), fOffset(offset), fDim(0)
29{
30 // Constructor
31 assert( offset >= 0 );
32
33 if( !VerifyNonArrayName(GetName()) ) {
34 fValueP = nullptr;
35 return;
36 }
37 // Currently supported data types
38 if( !(fType >= kDouble && fType <= kUChar) &&
39 !(fType >= kDoubleP && fType <= kUCharP) ) {
40 Error( "SeqCollectionVar::SeqCollectionVar", "Variable %s: "
41 "Illegal data type = %s. Only basic types or pointers to basic "
42 "types allowed", pvar->GetName(), Vars::GetTypeName(fType) );
43 fValueP = nullptr; // Make invalid
44 return;
45 }
46}
47
48//_____________________________________________________________________________
50{
51 // Get number of elements of the variable
52
53 assert( fValueP );
54
55 const auto *const obj = static_cast<const TObject*>( fValueP );
56 if( !obj || !obj->IsA()->InheritsFrom( TSeqCollection::Class() ))
57 return kInvalidInt;
58
59 const auto *const c = static_cast<const TSeqCollection*>( obj );
60
61 // Get actual array size
62 if( c->IsA()->InheritsFrom( TObjArray::Class() ))
63 // TObjArray is a special TSeqCollection for which GetSize() reports the
64 // current capacity, not number of elements, so we need to use GetLast():
65 return static_cast<const TObjArray*>(c)->GetLast()+1;
66
67 return c->GetSize();
68}
69
70//_____________________________________________________________________________
72{
73 // Number of dimensions
74
75 return 1;
76}
77
78//_____________________________________________________________________________
80{
81 // Return array of dimensions of the array
82
83 fDim = GetLen();
84 return &fDim;
85}
86
87//_____________________________________________________________________________
89{
90 // Get pointer to data in objects stored in a TSeqCollection (TClonesArray)
91
92 const char* const here = "GetDataPointer()";
93
94 static_assert( sizeof(ULong_t) == sizeof(void*) , "ULong_t must of of pointer size");
95 assert( fValueP );
96
97 Int_t len = GetLen();
98 if( len == 0 || len == kInvalidInt )
99 return nullptr;
100
101 if( i<0 || i>=len ) {
102 fSelf->Error( here, "Index out of range, variable %s, index %d",
103 GetName(), i );
104 return nullptr;
105 }
106
107 void* obj = static_cast<const TSeqCollection*>(fValueP)->At(i);
108 if( !obj ) {
109 fSelf->Error( here, "Variable %s: Collection element %d does not exist. "
110 "Check detector code for bugs.", GetName(), i );
111 return nullptr;
112 }
113
114 // Compute location using the offset.
115 if( fOffset > 0 ) {
116 ULong_t loc = reinterpret_cast<ULong_t>(obj) + fOffset;
117 assert( loc ); // obj != 0 already assured
118 if( fType >= kDoubleP && fType <= kUCharP )
119 obj = *reinterpret_cast<void**>(loc);
120 else
121 obj = reinterpret_cast<void*>(loc);
122 }
123 return obj;
124}
125
126//_____________________________________________________________________________
128{
129 // Compare the size counter of this variable to that of 'rhs'.
130 // Trivially, TSeqCollection variables have the same size if they
131 // belong to the same TSeqCollection
132
133 const auto *const other = dynamic_cast<const SeqCollectionVar*>(&rhs);
134 if( !other )
135 return false;
136
137 return fValueP == other->fValueP;
138}
139
140//_____________________________________________________________________________
142{
143 // Data are basic (POD variable or array)
144
145 return false;
146}
147
148//_____________________________________________________________________________
150{
151 // Data are contiguous in memory
152
153 return false;
154}
155
156//_____________________________________________________________________________
158{
159 // Data are an array of pointers to data
160
161 return false;
162}
163
164//_____________________________________________________________________________
166{
167 // Variable is a variable-size array
168
169 return true;
170}
171
172//_____________________________________________________________________________
173
174}// namespace Podd
int Int_t
unsigned long ULong_t
#define c(i)
bool Bool_t
#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 offset
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 UChar_t len
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
virtual Bool_t HasSameSize(const Variable &rhs) const
SeqCollectionVar(THaVar *pvar, const void *addr, VarType type, Int_t offset)
virtual const void * GetDataPointer(Int_t i=0) const
virtual Bool_t IsContiguous() const
virtual Int_t GetNdim() const
virtual Bool_t IsPointerArray() const
virtual Bool_t IsBasic() const
virtual const Int_t * GetDim() const
virtual Bool_t IsVarArray() const
virtual Int_t GetLen() const
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
THaVar * fSelf
Definition Variable.h:59
VarType fType
Definition Variable.h:61
const char * GetName() const override
static TClass * Class()
virtual void Error(const char *method, const char *msgfmt,...) const
static TClass * Class()
void Error(const char *location, const char *fmt,...)
STL namespace.