Home | News | Documentation | Download

Problem using a string from a tree

Dear All,

I’m trying to read a string from a tree so that eventually I can cut it into pieces, because it is a date and time. For some reason, I don’t manage to even print the string on the screen, I can’t figure out how to properly read it from the tree. Here is my code:

#include <iostream>

#include "TList.h"
#include "TTree.h"

const int nFiles = 18;

const char* fileName (int day = 17) 
  const char* fileList[nFiles] = {"LT-IVs_testBeam__2019-11-28_17-21.csv",

  return fileList[day];
}//end const char* fileName

TTree* mergeFiles (int day = 17) 
  TList* myList = new TList();
  for (int i=0; i<nFiles; i++)
    TTree* tempTree = new TTree();
    tempTree->ReadFile(Form("/eos/cms/store/group/dpg_tracker_upgrade/BeamTestTelescope/2019-DESY-BT-OT-2S-4MODS/HvMonitoring/%s", fileName(i)));
    std::cout << "File " << i << " apended to the list, with " << tempTree->GetEntries() << " entries." << std::endl;
  TTree* myTree = TTree::MergeTrees(myList);

  Int_t Index = 0, Year = 0, Month = 0, Day = 0, Hour = 0, Minute = 0, Second = 0;
  char Date;
  Double_t KitV;

  TBranch *bIndex = myTree->Branch("Index",&Index,"Index/I");
  TBranch *bYear = myTree->Branch("Year",&Year,"Year/I");
  TBranch *bMonth = myTree->Branch("Month",&Month,"Month/I");
  TBranch *bDay = myTree->Branch("Day",&Day,"Day/I");
  TBranch *bHour = myTree->Branch("Hour",&Hour,"Hour/I");
  TBranch *bMinute = myTree->Branch("Minute",&Minute,"Minute/I");
  TBranch *bSecond = myTree->Branch("Second",&Second,"Second/I");


  for (Long64_t i=0; i<myTree->GetEntries(); i++) 
    std::cout << Date << " With U " << KitV << std::endl;
    //if (Date.SubString("2019", 0)!=NULL) std::cout << "I found the year" << std::endl;
    Index = i;

  return myTree;

void hvPlots() {

  TTree* myTree = mergeFiles();


An example of what the files looks like is this:


Can somebody help me with how to get the string back in some variable so that I can chop it into the year, month and so on?


ROOT Version: Not Provided
Platform: Not Provided

try these changes:

char Date[40];
1 Like
  myTree->ResetBranchAddresses(); // disconnect from local variables
  return myTree;
1 Like

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