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",
"LT-IVs_testBeam__2019-11-28_17-24.csv",
"LT-IVs_testBeam__2019-11-28_17-37.csv",
"LT-IVs_testBeam__2019-11-28_22-27.csv",
"LT-IVs_testBeam__2019-11-28_22-28.csv",
"LT-IVs_testBeam__2019-11-29_10-33.csv",
"LT-IVs_testBeam__2019-11-29_18-49.csv",
"LT-IVs_testBeam__2019-12-01_09-18.csv",
"LT-IVs_testBeam__2019-12-01_18-55.csv",
"LT-IVs_testBeam__2019-12-02_23-03.csv",
"LT-IVs_testBeam__2019-12-03_06-38.csv",
"LT-IVs_testBeam__2019-12-03_17-08.csv",
"LT-IVs_testBeam__2019-12-03_17-09.csv",
"LT-IVs_testBeam__2019-12-03_19-18.csv",
"LT-IVs_testBeam__2019-12-04_14-11.csv",
"LT-IVs_testBeam__2019-12-04_15-34.csv",
"LT-IVs_testBeam__2019-12-05_17-57.csv",
"LT-IVs_testBeam__2019-12-06_21-42.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)));
myList->Add(tempTree);
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");
myTree->SetBranchAddress("Date",&Date);
myTree->SetBranchAddress("KitV",&KitV);
for (Long64_t i=0; i<myTree->GetEntries(); i++)
{
myTree->GetEntry(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;
bIndex->Fill();
}
return myTree;
}
void hvPlots() {
TTree* myTree = mergeFiles();
//myTree->Print();
//myTree->Scan();
//myTree->Draw("KitI:Index");
}
An example of what the files looks like is this:
Date/C:KitV/D:KitI/D:M1803V/D:M1803I/D:SF1902V/D:SF1902I/D:M1804V/D:M1804I/D
2019-11-29_10-33-30,-300.0,-7.538000000000001e-07,-300.0,-9.445000000000002e-07,-300.0,-9.247199999999998e-07,-300.0,-8.6902e-06
2019-11-29_10-33-41,-300.0,-7.548700000000001e-07,-300.0,-9.451e-07,-300.0,-9.246499999999999e-07,-300.0,-8.634609999999998e-06
2019-11-29_10-33-51,-300.0,-7.538000000000001e-07,-300.0,-9.449e-07,-300.0,-9.250000000000002e-07,-300.0,-8.676300000000002e-06
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?
Cheers,
Nikkie
ROOT Version: Not Provided
Platform: Not Provided