Outputting list of branch names to sorted TList

Greetings all,

I am looking for a method to output the branch names from a TTree into a sorted TList. My various attempts to get a list produce either a list to screen using

or a pointer to a TObjectArray using.

The reason that I am trying to do this is that I have received a set of files in a non-ROOT format for which the numbers and types of devices varies unpredictably from file to file (so far between 195 and 230 different devices of up to 10 different types) and for which the experiment definition file represents approximate guidance only.

I have transferred the data into ROOT successfully. Each ROOT tree has one branch per device. I am trying to develop code to sort and group the devices. For that purpose I need a listing.

Any guidance you can give on how to produce the TList or any suggestions as to a better way of handling this issue would be greatly appreciated.

Regards

Hi,

The easiest is probably to use a copy of the TObjArray rather than a TList:TObjArray *mycopy = tree->GetListOfBranches()->Clone(); mycopy->SetOwner(kFALSE); mycopy->Sort();

Cheers,
Philippe.

Dear Philippe,

Thank you for your rapid response.

My follow-up question is, how can I use the sorted TObjectArray as a list of labels. The only bit I need from the TObjectArray is the name of each branch, but everything I try gives me a lot of detailed info about each branch.

What command can I use to extract just the name of each branch from the TObjectArray?

There may be an extremely obvious anwser in the documentation, but for some reason I am not succeeding in finding/recognising the next step.

Regards

[quote]What command can I use to extract just the name of each branch from the TObjectArray? [/quote]Most likely the same way as you would for the TList :slight_smile:

In which context (for what purpose, for what api) do you need the list of labels?

You can print the name of each branches simply by doing:for(int i = 0; i < array->GetEntries(); ++i) { cout << array->At(i)->GetName() << '\n'; }

Cheers,
Philippe.

Dear Philippe,

I have a series of particle detectors, a series of gamma detectors, a series of timing devices and some devices that relate to gating and timing.

I need to relate events in each of the particle detectors to each of the gamma detectors in ways that relate to their physical locations in the experimental setup and to the concurrent output from the gating and timing devices. In some cases the identifying details, physical locations and detector types changed between experimental runs.

In order to manipulate the data in any branch the script needs to either know each branch’s name or have some form of functional pointer based on the type of information in each branch. Because of changes in setup that were made during the collection of the data I do not have the information necessary to define these relationships a priori.

Without a listing of branches I can’t tell how many branches of each device type I have and I can’t relate branches of different type together.

So in answer to your question, there is ++no++ specific api I need to call - I simply need the information. [edit because I left the word “no” out of the sentence]

If I could succeed in making the TList it would simply contain the list of names I am trying to get access to. Accessing names in a TList is not something I have had problems with in the past.

Regards

[quote]If I could succeed in making the TList it would simply contain the list of names I am trying to get access to. Accessing names in a TList is not something I have had problems with in the past.
[/quote]From the code snippet I provided you should be able to either use the name directly from the TObjArray of TBranch objects or make you TList of TObjString …

Cheers,
Philippe.

Dear Philippe,

Unfortunately I am currently using a system that does not have ROOT installed, I will be able to try your code snippet later today.

I will post either my thanks or a further question when I get to the next step.

Regards

Dear Philippe,

OK I define my TObjectArray and sort it and then execute the command

the output I get is

If I understand this correctly it is giving me both the value of the pointer to the branch name and the branch name. The string “CSS_Ge01_101” is the correct name for the first branch in tree.

If there anyway just to get the branch name?

Thank you for your help

Regards

Dear Philippe,

It works perfectly now - I must have made a typo in my first attempt.

The output is exactly what I need to go forward.

Thank you for your help.