Getting error like 'generate the dictionary for this collection (map<string,bool>)'

Hi,

I am getting the following errors while accessing the dictionary branch using c++ syntax.
Error in TChain::SetBranchAddress: The class requested (map<string,bool>) for the branch “HLT_BPH_isFired” is an instance of an stl collection and does not have a compiled CollectionProxy. Please generate the dictionary for this collection (map<string, bool>) to avoid writing corrupted data.

*** Break *** segmentation violation

Please help me accessing the branch. I have attached the root file for ref. The branch name is “HLT_BPH_isFired”
flatntuple_MC_.root (382.4 KB)
.

Thanks
Priyanka


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi @psadangi ,
as per the error message, you are missing dictionaries for map<string, bool> (which tell ROOT how to do I/O of that type).

You can find some information about dictionary generation here:

Cheers,
Enrico

Hi @eguiraud

Thanks for your reply. Actually i am not generating any dictionary. It is already present in my root file, I am trying to access it. I can’t plot or print any other variables too until the BranchStatus of the “HLT_BPH_isFired” (dictionary) is turned off.

Please suggest what need to be done here.

Thanks
Priyanka

ROOT does not know how to do I/O of map<string, bool> without dictionaries. They should come with the data. If not, you can produce them. Otherwise, you can probably still read the individual elements of the map but you might have problems reading the full map<string, bool> object.

Cheers,
Enrico

P.S.
@pcanal feel free to correct me if I’m wrong

Actually i am not generating any dictionary. It is already present in my root file,

The “dictionaries” are piece of C++ code that make the connection between C++ object (map<string, bool> in your case) and the data on file, as such they are not (and can not be) “in” the file. What is present in the file is only a data and a description of the data (i.e. that it is a map<string, bool>).

To connect the data to a C++ object (i.e. what you attempt with SetBranchAddress) you must have a dictionary for the class/type of that object.

However, as Enrico, mentions there is also way to access the data without relying on the C++ objects. For example you can read you data without a dictionary with TTree::Draw or RDataFrame.

Thanks,

Following the interactive way (ACLiC), the dictionary I have created. But I am unable to print them with normal cpp syntax. When I tried to make cout statement (Screenshot is attached) unusual sign appeared. Sorry but Is it not possible to print in the terminal with cpp syntax ?

Thanks
Priyanka

What exact code did you try?

Hi @pcanal and @eguiraud

Sorry for late reply. Here is the code.
Can you please give a look and suggest me.

Thanks
Priyanka
plotsAll.cpp (3.5 KB)

Hi @pcanal @eguiraud

Is it not possible to access ? I have already tried the interactive way. Can you please suggest me here ?

Thanks
Priyanka

Hi,
as we mentioned you need to create dictionaries for the std::map<string,bool> to be able to read it.

See the documentation here: ROOT macros and shared libraries - ROOT and some practical examples here: GitHub - eguiraud/root_dictionaries_tutorial: A tutorial on creating ROOT dictionaries to perform I/O of custom C++ classes .

Cheers,
Enrico

Hi @eguiraud

As I have told i have already tried via ACLiC, plotsAll_cpp.d, plotsAll_cpp.so files are already generated. I am unable access now also after following your example.

Thanks
Priyanka

Hi @psadangi ,
I’ll take a look this afternoon.

Cheers,
Enrico

Alright this is the shortest demonstrator I could put together:

#include <TFile.h>
#include <TTree.h>
#include <map>
#include <string>
#include <iostream>

#pragma link C++ class std::map<std::string, bool>+;

int read_map_branch() {
  TFile f("flatntuple_MC_.root");
  f.ls();
  f.cd("ntuplizer");
  f.ls();
  auto t = f.Get<TTree>("ntuplizer/tree");

  std::map<std::string, bool> *m = nullptr;
  t->SetBranchAddress("HLT_BPH_isFired", &m);
  for (Long64_t i = 0ll; i < t->GetEntries(); ++i) {
   t->GetEntry(i);
   for (auto p : *m)
      std::cout << p.first << ": " << p.second << '\n';
  }

  return 0;
}

that you can execute with root read_map_branch.C+.

ACLiC will produce the dictionaries as per the #pragma link ..., and then use them to read the std::map<std::string, bool>.
Variations on that theme will also work: you can produce the dictionaries first and then load them before opening the file, you can produce the dictionaries with the rootcling command line and then compile them together with your source, etc., as per GitHub - eguiraud/root_dictionaries_tutorial: A tutorial on creating ROOT dictionaries to perform I/O of custom C++ classes .

I hope this helps!
Enrico

1 Like

Hi @eguiraud

Thank you very much, now I can access them. I understand why I was unable to access.

Thanks
Priyanka

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.