I am looking for a nice way to get all different values from branches which contain either ints or strings.
Other branches in the tree contain a continuous range of values, but some contain very few different values which I would like to retrieve to enable a selection by those values.
The closest analogy that comes to my mind is a “select distinct” in an oracle query.
Any suggestions apart from manually looping over all entries of the tree?
if your Tree has been created from an object, you can get some inspiration from the example below where Event.root is the file generated by running
Event 100 1 99 1
in $ROOTSYS/test (run make in this dir)
[code]void selectb() {
//open a tree and print the leaf names with integers or strings
TFile f(“Event.root”);
TTree T = (TTree)f.Get(“T”);
TIter next(T->GetListOfLeaves());
TLeafElement leaf;
while ((leaf = (TLeafElement)next())) {
TString typeName = leaf->GetTypeName();
printf(“leaf = %s, typeName = %s\n”,leaf->GetName(),typeName.Data());
if (typeName == “Int_t”) {
printf(" found leaf: %s with integer type\n",leaf->GetName());
} else if (typeName == “Char_t”) {
printf(" found leaf: %s with string type\n",leaf->GetName());
}
}
}
[/code]
The tree is the output from a different script and prior to doing any full analysis on it, I would like to get the range of values from some of the branches.
The code example should illustrate the data structure, namely that I have a very limited number of different values in branches i and j which I would like to retrieve.
If I then want to exclude or include certain values of either variable, the code changes you provided do what I want, but I would like to get the different values beforehand if possible.
Maybe there is no truly simple method and I can just disable all other branches prior to looping over the tree, to minimize the amount of data to be read.