I’ve crossed this problem several times. And I am not sure how to deal with it.
Please, find attached an example script to reproduce the problem (execute example_tree_write.C and then example_tree_read.C.
To better describe the problem:
When I create an array of length 100 but save only the first 10 points, it will save the array properly, but anything that comes after it will not be saved (in the example, selection)
I would like to keep the class structure as all my analysis is based on this (in my complete scripts I have several channels and need to work with something very similar to the example).
I cannot invert “selection” with “wvf” as they have different type and the data will not be saved properly.
This solution is (almost) perfect! Thanks.
The only problem is that I still need to define the size of the array during compilation. The best solution I was searching was to define the length inside some function, but I believe that is not possible at all (without using vectors). However, declaring the class with the template is of great help.
template <Int_t npts = 100>
class MY_DATA {
public:
// note: tree branch variables must be sorted in the decreasing order of size
Int_t actualSize = npts;
Int_t selection;
Double_t peak;
Double_t wvf[npts];
std::string tobranch = "actualSize/I:selection/I:peak/D:wvf[actualSize]/D";
MY_DATA();
};
This is a great solution, however I have several channels and I keep the variables declared in the class holding the info for each channel.
So, I prefer to use each class as a branch.
For instance:
The class MY_DATA as ch0 and ch1.
For each waveform I have saved, I have informations like charge, peak, selection, etc.
I hope this makes sense
Yes! This is even better.
I had no idea how to work with class + pointer. This is the solution I wanted from a long time, but I could not figure out in the documentation by lack of knowledge in C++.