I am trying to run the following code,
#include <iostream>
#include<fstream>
#include<string>
#include "TObject.h"
#include <cmath>
#include "TFile.h"
#include "TTree.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TF1.h"
#include "TLorentzVector.h"
#include "TGraphErrors.h"
#include <TCanvas.h>
#include <TStyle.h>
void cpfile()
{
TFile *f = new TFile("Merged_File_Run1695831790_NANO.root");// combinedfile.root : combination of 4 root files.
TTree *Tout = (TTree*)f->Get("Events");
TFile *fout = new TFile("finalpfile1.root","RECREATE",0);
auto newtree = std::make_unique<TTree>("Events", "Events");
const int N_HGC = 454;
UInt_t run;
UInt_t luminosityBlock;
ULong64_t event;
UInt_t bunchCrossing;
Int_t nHGCCM;
Int_t nHGC;
//UShort_t HGC_adc[N_HGC];
UShort_t HGC_adc[N_HGC];
Float_t HGC_adcFlt[N_HGC];
Float_t HGC_x[N_HGC]; //[nHGC]
Float_t HGC_y[N_HGC];
Float_t HGC_energy[N_HGC];
//UChar_t HGCCM_captureBlock;
// List of branches
TBranch *b_run; //!
TBranch *b_luminosityBlock; //!
TBranch *b_event; //!
TBranch *b_bunchCrossing; //!
TBranch *b_nHGCCM;
TBranch *b_nHGC;
TBranch *b_HGC_adc;
TBranch *b_HGC_x; //!
TBranch *b_HGC_y;
TBranch *b_HGC_energy;
//TBranch *b_HGCCM_captureBlock;
Tout->SetBranchAddress("run", &run, &b_run);
Tout->SetBranchAddress("luminosityBlock", &luminosityBlock, &b_luminosityBlock);
Tout->SetBranchAddress("event", &event, &b_event);
Tout->SetBranchAddress("bunchCrossing", &bunchCrossing, &b_bunchCrossing);
Tout->SetBranchAddress("nHGCCM", &nHGCCM, &b_nHGCCM);
Tout->SetBranchAddress("nHGC", &nHGC, &b_nHGC);
Tout->SetBranchAddress("HGC_adc", HGC_adc, &b_HGC_adc);
Tout->SetBranchAddress("HGC_x", HGC_x, &b_HGC_x);
Tout->SetBranchAddress("HGC_y", HGC_y, &b_HGC_y);
Tout->SetBranchAddress("HGC_energy", HGC_energy, &b_HGC_energy);
//Tout->SetBranchAddress("HGCCM_captureBlock", &HGCCM_captureBlock, &b_HGCCM_captureBlock);
newtree->Branch("run", &run);
newtree->Branch("luminosityBlock", &luminosityBlock);
newtree->Branch("event", &event);
newtree->Branch("bunchCrossing", &bunchCrossing);
newtree->Branch("nHGCCM", &nHGCCM);
newtree->Branch("nHGC", &nHGC);
newtree->Branch("HGC_adc", HGC_adcFlt,"HGC_adc[nHGC]");
newtree->Branch("HGC_x", HGC_x,"HGC_x[nHGC]");
newtree->Branch("HGC_y", HGC_y,"HGC_Y[nHGC]");
newtree->Branch("HGC_energy", HGC_energy , "HGC_energy[nHGC]");
//newtree->Branch("HGCCM_captureBlock",&HGCCM_captureBlock);
int nevt;
nevt=Tout->GetEntries();
for (int i = 0; i < nevt; i++)
{
Tout->GetEntry(i);
for (int j = 0; j < N_HGC; j++){
HGC_adcFlt[j] = float(HGC_adc[j]);
}
newtree->Fill();
}
fout->cd();
newtree->Write();
fout->Write();
fout->Close();
}
int main(){
cpfile();
}
I compiled it using
(py38-env) :Old_Method_Files$ g++ -o cpf cpfile.cpp -pthread -std=c++17 -m64 -I/home/cms-iith/miniconda3/envs/py38-env/include `root-config --libs` `root-config --cflags`
And tried to run it using,
(py38-env) :Old_Method_Files$ ./cpf
Warning in <TClass::Init>: no dictionary for class edm::Hash<1> is available
Warning in <TClass::Init>: no dictionary for class edm::ProcessHistory is available
Warning in <TClass::Init>: no dictionary for class edm::ProcessConfiguration is available
Warning in <TClass::Init>: no dictionary for class edm::ParameterSetBlob is available
Warning in <TClass::Init>: no dictionary for class pair<edm::Hash<1>,edm::ParameterSetBlob> is available
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x0000743da11107a7 in __GI___wait4 (pid=3691756, stat_loc=stat_loc
entry=0x7ffd5fc70dd8, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1 0x0000743da11108eb in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7ffd5fc70dd8, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x0000743da10585ab in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:172
#3 0x0000743da2cb1d6d in TUnixSystem::StackTrace() () from /home/cms-iith/miniconda3/envs/py38-env/lib/libCore.so.6.26
#4 0x0000743da2caf077 in TUnixSystem::DispatchSignals(ESignals) () from /home/cms-iith/miniconda3/envs/py38-env/lib/libCore.so.6.26
#5 <signal handler called>
#6 0x0000625920e0feda in std::default_delete<TTree>::operator()(TTree*) const ()
#7 0x0000625920e0f9b8 in std::unique_ptr<TTree, std::default_delete<TTree> >::~unique_ptr() ()
#8 0x0000625920e0f5d2 in cpfile() ()
#9 0x0000625920e0f62f in main ()
===========================================================
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6 0x0000625920e0feda in std::default_delete<TTree>::operator()(TTree*) const ()
#7 0x0000625920e0f9b8 in std::unique_ptr<TTree, std::default_delete<TTree> >::~unique_ptr() ()
#8 0x0000625920e0f5d2 in cpfile() ()
#9 0x0000625920e0f62f in main ()
===========================================================
Is there something wrong with the way I am compiling it?
The codes are correct and have worked using the same commands, for the one who wrote these codes. However, I am unable to do to the same.