Hi guys,
sorry for still newbie questions but, I think, I will never be friend of this software.
However, I made a code that keeps a of root file, extract values from it and, after making stuff, it write them on another root file (I implement this in a bash file to keep a series of root file with same structure). I do this:
#include <TH1.h>
#include <TH1F.h>
#include <TH1D.h>
#include <TH2.h>
#include <TChain.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TH1F.h>
#include <TFile.h>
#include <TObject.h>
#include <TMath.h>
#include <TTree.h>
#include <TBranch.h>
#include <TLeaf.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;
// OUTPUT-Definitions
TFile *histoFile = new TFile(argv[1],"RECREATE");
TTree *t2 = new TTree("t2","");
// declaration of some variable
int Nsel0=0, Nsel1=0, Nsel2=0, Nsel3=0;
//Input file definition and its variable extraction
TFile *fopen=TFile::Open(argv[2]);
TTree *myt1=(TTree*)fopen->Get("t1");
int accepted = 0;
unsigned long int nentries = myt1->GetEntries();
myt1->SetBranchAddress("variable",&variable);
***** stuff *****
for(unsigned long int i=0; i<nentries; i++){
*** stuff ***
t2->Branch("Variable",&Variable,"Variable/D");
t2->Fill();
}
t2-> Write();
histoFile->cd();
histoFile->Write();
histoFile->Close();
This worked but gave an Error saying that the the argv[2] file is not writable… even if the output came out in the wirte way.
I did not know the nature of the error, so I have tried to change the definition of the input file in:
TFile fopen(argv[2]);
TTree *myt1=(TTree*)fopen.Get("t1");
This did not work so I came back to the previous stage but it gave me this segmentation fault
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f796e97c60c in waitpid () from /lib64/libc.so.6
#1 0x00007f796e8f9f62 in do_system () from /lib64/libc.so.6
#2 0x00007f79738f7619 in TUnixSystem::StackTrace() () from /software/centos-7-x86_64/root/5.34.38/lib/libCore.so
#3 0x00007f79738f923c in TUnixSystem::DispatchSignals(ESignals) () from /software/centos-7-x86_64/root/5.34.38/lib/libCore.so
#4 <signal handler called>
#5 main (argc=<optimized out>, argv=0x7ffeab7ef918) at /folder/code.cc:76
===========================================================
The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5 main (argc=<optimized out>, argv=0x7ffeab7ef918) at /folder/code.cc:76
===========================================================
`
The strange thing is that before it worked and after coming back to the same code, it did not work anymore. So, I guess there should be some cleaning operation (I tried to look around and this is the only suggestion that I got) that I have to do but don’t know what.
Putting some flags around I found that the error is in
unsigned long int nentries = myt1->GetEntries();
but don’t know why, since before it worked.
Sorry again for these newbie questions.
Thanks in advance for the reply.
ROOT Version: 5.37-38
Platform: Unix CentOS 7.9.2009
Compiler: CINT 5.18