#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "TList.h"
#include "TString.h"

#include <vector>
#include <map>
#include <string>

namespace evwgh {
    struct MCEventWeight
    {
        std::map<std::string, std::vector<double> > fWeight;
    };
}

void test_save_obj(
        const char* output = "save_obj.root"
        ) {

    auto *tf_out = TFile::Open(output, "recreate");

    auto *tree = new TTree("save_obj","save_obj");

    //evwgh::MCEventWeight EventWeightMar18;
    //tree->Branch("EventWeightMar18", &EventWeightMar18);

    std::map<std::string, std::vector<double>> fWeight;
    tree->Branch("fWeight", "std::map<std::string, std::vector<double>>",&fWeight);

    for(Long64_t ientry=0; ientry<2; ++ientry) {

        //EventWeightMar18.fWeight["knob0"] = {0.1, 0.2};
        //EventWeightMar18.fWeight["knob1"] = {1.1, 1.2};

        fWeight["knob0"] = {0.1, 0.2};
        fWeight["knob1"] = {1.1, 1.2};

        tree->Fill();
    }

    tree->Write();
    tf_out->Close();
}
