One of my branches in my TTree has the following format fDate/C and I’m using TTreeReaderArray<char> fDt(fReader,"fDate"); (i.e I have access to its elements through fDt[n]) I wonder if there is a way to get this char array as a TString without using a loop, as the name suggest it is a date and I need to convert this to a TDatime object but first I have to append “00:00:00” as the info about the hour is not relevant.
Aside question: Is there a way to store a TString/TDatime object in a TTree Branch?
Hi, fDt.GetAddress() and fDt.GetSize() should give you all the information needed to construct a string from the TTreeReaderArray<char> (namely, char * to the beginning of the string and size of the string).
A TString can be constructed with precisely those arguments if I’m not mistaken.
Let me know if you try it out and something breaks.
Cheers,
Enrico
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/TString.h:257:4: note: candidate constructor not viable: cannot convert argument of incomplete type 'void *' to 'const char *' for 1st argument
TString(const char *s, Ssiz_t n); // Copy past any embedded nulls
^
/TString.h:260:4: note: candidate constructor not viable: cannot convert argument of incomplete type 'void *' to 'char' for 1st argument
TString(char c, Ssiz_t s);
^
From the error message GetAddress returns a void* that you need to convert to char*: fDate = TString(static_cast<char*>(fDt.GetAddress()), fDt.GetSize());
My guess is this is a bug in TTreeReaderArray<char>::GetSize (it stops counting when it sees a 0 character).
I’ll try to reproduce it and confirm it and let you know soon. Pinging @Axel in case he knows right away.
I don’t know what this is. That said, I bet it’s not the 0, but the size gets determined incorrectly. An example file / reproducer would indeed be most helpful.