14 #include "TTableDescriptor.h"
17 #include "TDataMember.h"
18 #include "TDataType.h"
20 #include "TInterpreter.h"
31 TString TTableDescriptor::fgCommentsName =
".comments";
39 return fgColDescriptors;
47 fgColDescriptors = list;
55 fgCommentsName = name;
62 void TTableDescriptor::Streamer(TBuffer &R__b)
64 fSecondDescriptor = 0;
65 TTable::Streamer(R__b);
99 Char_t *name = (Char_t *)ColumnName(i);
100 if (name)
delete [] name;
101 UInt_t *indxArray = (UInt_t *)IndexArray(i);
102 if (indxArray)
delete [] indxArray;
106 if (fSecondDescriptor !=
this) {
107 delete fSecondDescriptor;
108 fSecondDescriptor = 0;
130 #ifdef NORESTRICTIONS
131 const char *comment = element->fColumnName && element->fColumnName[0] ? element->fColumnName :
"N/A";
133 const char *comment = element->fColumnName[0] ? element->fColumnName :
"N/A";
159 comment->SetTitle(commentText);
168 const Char_t typeMapTBranch[]=
"\0FIISDiisbBC";
169 Int_t maxRows = NumberOfColumns();
171 for (Int_t i=0;i<maxRows;i++){
172 if (i)
string +=
":";
173 UInt_t nDim = Dimensions(i);
175 UInt_t totalSize = 1;
179 const UInt_t *indx = IndexArray(i);
182 Error(
"CreateLeafList()",
"Can not create leaflist for arrays");
185 for (k=0;k< nDim; k++) totalSize *= indx[k];
187 const Char_t *colName = ColumnName(i);
189 for ( k = 0; k < totalSize; k++) {
191 snprintf(buf,10,
"_%d",k);
196 string += typeMapTBranch[ColumnType(i)];
198 if (k != totalSize -1)
string +=
":";
201 string += ColumnName(i);
203 string += typeMapTBranch[ColumnType(i)];
216 fSecondDescriptor = 0;
219 fRowClass = classPtr;
220 SetName(classPtr->GetName());
257 if (!classPtr)
return;
259 if (!(classPtr->GetNdata()))
return;
265 ReAllocate(classPtr->GetListOfDataMembers()->GetSize());
266 Int_t columnIndex = 0;
267 TIter next(classPtr->GetListOfDataMembers());
268 TDataMember *member = 0;
269 while ( (member = (TDataMember *) next()) ) {
271 varname = (Char_t *) member->GetName();
272 #ifdef NORESTRICTIONS
274 elementDescriptor.fColumnName = StrDup(varname);
276 elementDescriptor.fColumnName[0] =
'\0';
277 strncat(elementDescriptor.fColumnName,varname,
sizeof(elementDescriptor.fColumnName)-1);
280 if (member->IsaPointer() ) {
281 elementDescriptor.fTypeSize =
sizeof(
void *);
282 const char *typeName = member->GetTypeName();
285 TDataType *memberType = member->GetDataType();
286 R__ASSERT(memberType!=0);
287 elementDescriptor.fTypeSize = memberType->Size();
290 Int_t globalIndex = 1;
291 if (elementDescriptor.fType != kNAN) {
293 if ( (dim = member->GetArrayDim()) ) {
294 elementDescriptor.fDimensions = dim;
295 #ifdef NORESTRICTIONS
296 elementDescriptor.fIndexArray =
new UInt_t(dim);
298 UInt_t maxDim =
sizeof(elementDescriptor.fIndexArray)/
sizeof(UInt_t);
299 if (UInt_t(dim) > maxDim) {
300 Error(
"LearnTable",
"Too many dimenstions - %d", dim);
304 for( Int_t indx=0; indx < dim; indx++ ){
305 elementDescriptor.fIndexArray[indx] = member->GetMaxIndex(indx);
306 globalIndex *= elementDescriptor.fIndexArray[indx];
310 else Error(
"LearnTable",
"Wrong data type for <%s> structure",classPtr->GetName());
311 elementDescriptor.fSize = globalIndex * (elementDescriptor.fTypeSize);
312 elementDescriptor.fOffset = member->GetOffset();
313 AddAt(elementDescriptor,member->GetTitle(),columnIndex); columnIndex++;
331 TClass *cl = TClass::GetClass(structName, kTRUE);
342 if (!comments && createFlag)
343 comments =
new TDataSet(fgCommentsName.Data(),
this,kTRUE);
353 Int_t maxColumns = NumberOfColumns();
356 if ( (UInt_t(maxColumns) == newDescriptor->NumberOfColumns())
361 for (Int_t colCounter=0; colCounter < maxColumns; colCounter++) {
362 Int_t colNewIndx = newDescriptor->
ColumnByName(ColumnName(colCounter));
364 EColumnType newType = colNewIndx >=0 ? newDescriptor->ColumnType(colNewIndx): kNAN;
366 if (newType == kInt) newType = kLong;
367 else if (newType == kUInt) newType = kULong;
370 && Dimensions(colCounter) == newDescriptor->Dimensions(colNewIndx)
371 && ColumnType(colCounter) == newType) {
372 Bool_t same = kFALSE;
373 if ( Dimensions(colCounter)) {
374 for (UInt_t d = 0; d < Dimensions(colCounter); d++) {
375 if (IndexArray(colCounter)[d] != newDescriptor->IndexArray(colNewIndx)[d]){ same = kTRUE;
break; }
378 SetOffset(newDescriptor->Offset(colNewIndx),colCounter);
379 if (colNewIndx != colCounter) {
380 Printf(
"Schema evolution: \t%d column of the \"%s\" table has been moved to %d-th column\n",
381 colCounter,ColumnName(colCounter),colNewIndx);
384 Printf(
"Schema evolution: \t%d column \"%s\" size has been changed\n",
385 colNewIndx, ColumnName(colCounter));
389 Printf(
"Schema evolution: \t%d column \"%s\" of %d type has been lost\n",
390 colCounter,ColumnName(colCounter),ColumnType(colCounter));
391 Printf(
" Indx = %d, name = %s \n", colNewIndx, ColumnName(colCounter));
392 SetOffset(UInt_t(-1),colCounter);
396 if (!mismathes && UInt_t(maxColumns) != newDescriptor->NumberOfColumns()) {
398 Printf(
"Warning: One extra column has been introduced\n");
410 if (!elementDescriptor)
return i;
414 char *name = StrDup(columnName);
415 if ((bracket = strchr(name,
'[')) ) *bracket = 0;
416 for (i=0; i < nRows; i++,elementDescriptor++)
417 if (strcmp(name,elementDescriptor->fColumnName) == 0)
break;
420 if (i==nRows) i = -1;
422 if (bracket && !Dimensions(i)) {
424 Warning(
"ColumnByName",
"%s column contains a scalar value",columnName);
434 Int_t TTableDescriptor::Offset(
const Char_t *columnName)
const
440 offset = Offset(indx);
441 const char *openBracket = 0;
442 if ( (openBracket = strchr(columnName,
'[')) )
443 offset += atoi(openBracket+1)*TypeSize(indx);
452 Int_t TTableDescriptor::ColumnSize(
const Char_t *columnName)
const
455 if (indx >= 0 ) indx = ColumnSize(indx);
462 Int_t TTableDescriptor::TypeSize(
const Char_t *columnName)
const
465 if (indx >= 0 ) indx = TypeSize(indx);
472 Int_t TTableDescriptor::Dimensions(
const Char_t *columnName)
const
475 if (indx >= 0 ) indx = Dimensions(indx);
482 TTable::EColumnType TTableDescriptor::ColumnType(
const Char_t *columnName)
const
485 if (indx >= 0 ) indx = ColumnType(indx);
486 return EColumnType(indx);
493 Int_t fullRowSize = 0;
494 if (RowClass() ) fullRowSize = RowClass()->Size();
498 if (iLastRows >=0) fullRowSize = Offset(iLastRows) + ColumnSize(iLastRows);
void LearnTable(const TTable *parentTable)
to be documented
virtual TClass * GetRowClass() const
to be documented
virtual void SetDescriptorPointer(TTableDescriptor *list)
set table descriptor
virtual void AddAtAndExpand(TDataSet *dataset, Int_t idx=0)
virtual TTableDescriptor * GetDescriptorPointer() const
return column descriptor
virtual Int_t UpdateOffsets(const TTableDescriptor *newDesciptor)
Int_t Sizeof() const
to be documented
Int_t ColumnByName(const Char_t *columnName=0) const
Find the column index but the column name.
virtual void Init(TClass *classPtr)
virtual Int_t AddAt(const void *c)
Append one row pointed by "c" to the descriptor.
virtual void SetType(const char *const type)
to be documented
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
virtual Int_t AddAt(const void *c)
static EColumnType GetTypeId(const char *typeName)
static void SetCommentsSetName(const char *name=".comments")
set comments name
static TTableDescriptor * MakeDescriptor(const char *structName)
virtual TDataSet * FindByName(const char *name, const char *path="", Option_t *opt="") const
TString CreateLeafList() const
Create a list of leaf to be useful for TBranch::TBranch ctor.
virtual ~TTableDescriptor()
class destructor
TDataSet * MakeCommentField(Bool_t createFlag=kTRUE)
Instantiate a comment dataset if any.
TTableDescriptor(const TTable *parentTable)
to be documented