TClonesArray for types

Dear Rooters,
I have question concerning passing objects policy in ROOT.
Lets say that I have class Array that looks like this:

class Array : public TObject{
Int_t fSize;
Int_t fActiveSize;
Int_t *fArray; //fSize
...
}

To speed up my code I would like to use two variables to describe my class - fSize (that is real size of array) and fActiveSize. In such case I dont’ have to reallocate memory to shrink my array - I just reduce ActiveSize. But I would like to be sure that during writing (doesn’t matter how) only “ActiveSize” will be written into tree.
So basically I would like to have “TClonesArray with types”. Is it possible to achieve this in ROOT? If yes then how?

Then you need to use

class Array : public TObject {
   Array() : fSize(0), fActiveSize(0), fArray(nullptr) {}

   Int_t fSize;  //<! Allocated size, transient.
   Int_t fActiveSize; 
   Int_t *fArray; //[fActiveSize]
   ...
};

You can also use the I/O rule:

#pragma read sourceClass="Array" targetClass="Array" version="[1-]" source="Int_t fActiveSize" target="fSize" code="{ fSize = fActiveSize; }"

or

#pragma read sourceClass="Array" targetClass="Array" version="[1-]" source="" target="fSize" code="{ fSize = 0; }"

Cheers,
Philippe.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.