Std::map or TTree::GetV1()

Dear All,

I am looking a way to store my data.
I have the following quantities "run:spill:var1:var2:var3"
My plan is to loop over run and spill and process var1:var2:var3 independantly.

  • I was wondering if it is better to have a map<TString, map<TString, TTree>> where I could get my var1:var2:var3 like this : map[run][spill][subtree]
  • On the other hand, I looked at some thread here, and I saw that it is possible to use TTree::Draw() and then use TTree::GetV1() , TTree:GetV2(), etc…

So someone could help me to better see the advantages/disadvantages of both methods, and what do you think ? Thank you

Hi,

I would abandon the idea of adopting a map of maps containing trees.
You have five variables: why not using a simple TNtuple (root.cern.ch/doc/master/classTNtuple.html) ?

Cheers,
Danilo

I use basically TNtuple actually. But I said TTree because it’s heritating…

Anyway, I would not overloop over elements in my TNtuple, since I know already the number of run or spill that I am studying. Do you see ?

I am filtering my TNtuple everytime I think it will be more time consuming.
If I could directly access like tree[run][spill] it would be more efficient. Am I wrong ?

Hi,

I am not sure how big the penalty would be of skipping rows in your ntuple: do you have a performance figure for that?
Simpler than the map, you can write a separate TNtuple for run-spill pair , e.g. values__.

D

I see indeed, this is quite simillar to a map ! I will try to implement this idea.

What do you mean by performance figure a plot where I compare methods ? If yes, no I don’t have.
I will use this script in the context of PROOF environment. Basically everything will be parallelized.

Maybe I can share an example. (I took it from a previous thread and I modified it.)

Actually to be more precise, I will know the number of spill/run after reading the tree once.
Then I thing there are multiple methods to access it. I just wanted to know if someone has an idea of how to access it and if my method is not too bad…

In all case, thank you for your answers!
I’m looking forward to hearing from you :slight_smile:

[code]void testv1() {

    int n = 3;
    Int_t run, spill, N, timeinspill;

    TTree *tree = new TTree("tree", "Just a tree");
    tree->Branch("run", &run, "run/i");
    tree->Branch("spill", &spill, "spill/i");
    tree->Branch("timeinspill", &timeinspill, "timeinspill/i");

    cout << "prepare" << endl;
    for (run = 0 ; run < n ; run++) for(spill = 1; spill < 201; spill++) {

            if(spill%10 == 1) timeinspill = 1;
            else if(spill%10 == 2) timeinspill = 2;
            else if(spill%10 == 3) timeinspill = 3;
            else timeinspill = 4;

            cout << timeinspill << endl;
            tree->Fill();
    }

cout << "draw" << endl;
    tree->SetEstimate(tree->GetEntries());
    tree->Draw("run:spill", "", "goff");
    Double_t *runlist = tree->GetV1();
    Double_t *slist = tree->GetV2();

    for(i = 0, N = tree->GetSelectedRows(); i < N; i++) {

            TString selection = "run==" + TString::Itoa(runlist[i],10) + " && spill==" + TString::Itoa(slist[i],10);
            cout << selection << endl;
            tree->Draw("timeinspill", selection.Data(), "goff");

            Double_t *timelist = tree->GetV1();
            cout << TMath::MinElement(N,timelist) << " " << TMath::MaxElement(N,timelist) << endl;
    }

}[/code]

Hi,

great that the solution works for you.
In this case (several named TNtuples), you’ll know the runs/spills after looping over the keys in the file (GetListOfKeys()).
Let us know if you encounter problems.

Danilo