Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <vector>
  5.  
  6. #include "TFile.h"
  7. #include "TTree.h"
  8.  
  9. #ifdef __MAKECINT__
  10. #pragma link C++ class std::map < std::string, bool> + ;
  11. #endif
  12.  
  13. void Print(char const *file) {
  14.  
  15.   TFile *f = TFile::Open(file, "READ");
  16.   if (!f || !f->IsOpen()) {
  17.     std::cout << "[ERROR]: Failed to open " << file << " for reading."
  18.               << std::endl;
  19.     return;
  20.   }
  21.  
  22.   TTree *t = (TTree *)f->Get("cc1piselec/outtree");
  23.   if (!t) {
  24.     std::cout << "[ERROR]: Failed to get TTree, \"cc1piselec/outtree\"."
  25.               << std::endl;
  26.     return;
  27.   }
  28.  
  29.   t->SetBranchStatus("*", 0);
  30.   t->SetBranchStatus("TPCObj_PFP_n2LLH_fwd_mu", 1);
  31.   t->SetBranchStatus("CC1picutflow", 1);
  32.  
  33.   std::vector<double> *v = nullptr;
  34.   TBranch *bvpx = nullptr;
  35.  
  36.   std::map<std::string, bool> *m = nullptr;
  37.   TBranch *bmpx = nullptr;
  38.  
  39.   // t->SetBranchAddress("TPCObj_PFP_n2LLH_fwd_mu", &v, &bvpx);
  40.   t->SetBranchAddress("TPCObj_PFP_n2LLH_fwd_mu", &v);
  41.   t->SetBranchAddress("CC1picutflow", &m);
  42.  
  43.   // Long64_t NEntries = bvpx->GetEntries();
  44.   Long64_t NEntries = t->GetEntries();
  45.  
  46.   for (Long64_t ent_it = 0; ent_it < NEntries; ++ent_it) {
  47.     // bvpx->GetEntry(ent_it);
  48.     t->GetEntry(ent_it);
  49.     std::cout << "Entry " << ent_it << "\n\tHas vector (" << v->size() << ") {"
  50.               << std::endl;
  51.     for (double &v_ent : (*v)) {
  52.       std::cout << v_ent << std::endl;
  53.     }
  54.     std::cout << "}." << std::endl;
  55.     std::cout << "\tHas map (" << m->size() << ") {" << std::endl;
  56.     for (auto &m_ent : (*m)) {
  57.       std::cout << "\"" << m_ent.first << "\":" << m_ent.second << " "
  58.                 << std::endl;
  59.     }
  60.     std::cout << "}." << std::endl;
  61.   }
  62. }
  63.  
  64. int main(int argc, char const *argv[]) { Print(argv[1]); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement