I have packed arrays of UShort_t in a TTree and I wish to unpack them into TVectorD for my analysis.
I have code that works, but it just has a loop and copies the elements one-by-one:
TVectorD get_trace(UShort_t * digiWF)
{ Int_t recL = 1024;
Int_t chan_offset = -1;
// some code here determines a proper chan_offset value
TVectorD tv(recL);
for(Int_t i=0;i<recL;i++) {
tv[i] = digiWF[i+chan_offset*recL];
}
return tv;
}
I tried optimizing a bit by using std::copy instead of an explicit loop:
TVectorD tv(recL);
std::copy(digiWF+chan_offset*recL,
digiWF+chan_offset*(recL+1),
tv.GetMatrixArray());
return tv;
but it looks like it doesn’t work, probably because the type-conversion is not done properly. I also tried just using a TVectorD constructor:
But here I get a compiler error about the types (recall digiWF is a UShort_t * not a Double_t *).
My profiling tells me that this function represents a good chunk of my runtime, so I’d like to get it as tight as possible. Can anyone advise on efficiently copying some UShort_t array into a TVectorD?
Thanks,
Jean-François