What is the fastest way to write a complex variable to a branch in ROOT? I have real and complex variables, and custom structs containing arrays of real and complex variables, as follows (simplified version):
template<typename T, std::size_t N>
MyVector<double, 3> vec;
MyVector<std::complex<double>, 3> cvec;
vec is apparently straightforward:
tree->Branch("real_var", &var, "D");
tree->Branch("real_vec", &vec, "element/D");
But how can I efficiently save a branch containing elements of the type
MyVector<std::complex<double>, 3>? Speed of writing the file is important (reading speed matters too, but much less) so I don’t want to split the structs into TLeaves for each component.
Apologies for the very elementary question, but any help would be greatly appreciated.
ROOT Version: 6.22
Hi @ed20 ,
sorry for the high latency, @pcanal or @Axel might be able to indicate the most performant way to write
std::complex<double> to a TTree.
ROOT contains a dictionary for
std::complex<double> so you can directly do:
For a collection of
std::complex<double> (for example
std::vector<std::complex<double>> or your
MyVector<double, 3>) you will need to generate a dictionary for that class/container; for example:
#pragma link C++ class std::vector<std::complex<double>>+;
#pragma link C++ class MyVector<double, 3>+;
PS. In all those case, you can play with the split level to determine if the default is the fastest (default split level is 9, you would compare it to 0). Note that another factor that you may care about is the final file size (the split case is likely to compress better than the non-split case).
If write speed is important, the choice of compression algorithm might also be important (at the expense of file size, for example ‘no compression’ will, of course, be the fastest.
Next, depending of how costly it is to acquire the data and whether you need compression of not, having multiple prepare portion of the output on their own (i.e. run in parallel the processing, serialization and compression steps) and merge the output into the final file, might be of interest to you.