Is there a way to store an array of words of bits in a TTree, and access it with RDataFrame?
If I try (root -b -q hello_word.C+
)
#include <TChain.h>
#include "ROOT/RDataFrame.hxx"
#include "ROOT/RVec.hxx"
#include <array>
#include <bitset>
#include <iostream>
#include <TInterpreter.h>
const int N_BITS = 128;
const int N_WORDS = 20;
void hello_word(void) {
gInterpreter->GenerateDictionary("bitset<128>;array<bitset<128>, 20>", "array;vector;ROOT/RVec.hxx");
std::bitset<N_BITS> word;
std::bitset<N_BITS> words[N_WORDS];
std::array<std::bitset<N_BITS>, N_WORDS> words2;
std::cout << "Defining the tree" << std::endl;
auto f = new TFile("test.root", "RECREATE");
auto t = new TTree("t", "a test tree");
t->Branch("word", &word);
t->Branch("words", &words, "words[20]");
t->Branch("words2", &words2, "words2[20]");
for (Int_t i = 0; i < N_WORDS; i++) {
word.flip();
words[i].set();
words2[i].set();
t->Fill();
}
f->Write();
f->Close();
SafeDelete(f);
std::cout << std::endl << "Reading it back" << std::endl;
auto chain = TChain("t");
chain.Add("test.root");
ROOT::RDataFrame dset(chain);
for (auto var: dset.GetColumnNames()) {
std::cout << var << " is " << dset.GetColumnType(var) <<std::endl;
}
}
returns
Defining the tree
Error in <TTree::Branch>: The class requested (bitset<128>) for the branch "word" is an instance of an stl collection and does not have a compiled CollectionProxy. Please generate the dictionary for this collection (bitset<128>) to avoid to write corrupted data.
Reading it back
words is ROOT::VecOps::RVec<Float_t>
words2 is ROOT::VecOps::RVec<Float_t>
The actual use case has a new column which contains a struct with a few arrays of bitsets (one per sub-detector) - the motivation for using bitset is probably obvious, while that of using arrays instead of vectors is performance-related (the number of sub-detectors is of course fixed).
Please read tips for efficient and successful posting and posting code
Please fill also the fields below. Note that root -b -q
will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug
from the ROOT prompt to pre-populate a topic.
ROOT Version: 6.28/10
Platform: linuxx8664gcc
Compiler: g++ (GCC) 13.1.0