Array of Object Vectors

I am trying to save cluster information in an array of “n” vectors containing objects of class “User” in a root format.

std::vector Nclust[n];

If someone could guide how to generate the dictionary as I am getting this error

“Please generate the dictionary for this collection (vector) to avoid to write corrupted data.”

Also if someone can provide the link of an example to write and read objects of a class in root file.


Hi @qmalik,
and sorry for the late reply!

There are several ways to generate dictionaries in ROOT, the simplest is probably to create a LinkDef.h file like explained here, e.g.:

// MyClass.h
#include <string>
#include <vector>

struct User {
   int n;
   std::string foo;

class MyClass {
   std::vector<User> Nclust[10];
// LinkDef.h
#ifdef __CLING__
#pragma link C++ class MyClass+;

and then from the commandline rootcling myclass_dict.cxx myclass.h LinkDef.h and then when compiling you should link myclass_dict.cxx to the library/executable that needs to read/write MyClass.

@pcanal might add more information on the topic.