Dear Rene and other root developers,
I have this problem:
reading.C is a simple macro that wants to combine together automatically some histograms, saved in different .root files.
The list of root file to read is also added: histofile.txt
Into another file is written what are the histograms to combine.
(because the limit of 3 files to upload, i didn’t upload it, but in this case
is a simple on line file: hgaus (the example histogram tha i have created))
The macro reads the input files, avoids what starts with // and tries to print the contnent of the files loaded.
At this point root ends with this message:
Root > .L reading.C+
Info in : unmodified script has already been compiled and loaded
root [3] Comb_HISTO1(“histofile.txt”,“histotodraw.txt”)
File input: histo1.root
File input: histo2.root
File input: histo3.root
Histo to draw: hgaus
histo1.root
TFile: name=, title=, option=
*** Break *** segmentation violation
(no debugging symbols found)
Using host libthread_db library “/lib/tls/libthread_db.so.1”.
Attaching to program: /proc/27427/exe, process 27427
(no debugging symbols found)…done.
(no debugging symbols found)…done.
[Thread debugging using libthread_db enabled]
[New Thread -1208981824 (LWP 27427)]
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
0x0034e7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1 0x07d7b473 in __waitpid_nocancel () from /lib/tls/libc.so.6
#2 0x07d25359 in do_system () from /lib/tls/libc.so.6
#3 0x0077f78d in system () from /lib/tls/libpthread.so.0
#4 0x00a8c985 in TUnixSystem::Exec () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#5 0x00a8cddd in TUnixSystem::StackTrace () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#6 0x00a8ae26 in TUnixSystem::DispatchSignals () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#7 0x00a88e4d in SigHandler () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#8 0x00a8f345 in sighandler () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#9
#10 0x04cd759b in Comb_HISTO1 () from /mnt/homedisk0_mnt/users/risso/offline/Echidna/./reading_C.so
#11 0x04cd78ef in G__filem733Sr__0_1716 () from /mnt/homedisk0_mnt/users/risso/offline/Echidna/./reading_C.so
#12 0x01002c02 in Cint::G__ExceptionWrapper () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#13 0x010bd8d7 in G__call_cppfunc () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#14 0x010ab704 in G__interpret_func () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#15 0x01097f1e in G__getfunction () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#16 0x0108d599 in G__getitem () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#17 0x0108bdc9 in G__getexpr () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#18 0x010d759e in G__exec_function () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#19 0x010dfa6a in G__exec_statement () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#20 0x01070e24 in G__exec_tempfile_core () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#21 0x01071018 in G__exec_tempfile_fp () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#22 0x010e8d60 in G__process_cmd () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCint.so
#23 0x009e6f61 in TCint::ProcessLine () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#24 0x00912820 in TApplication::ProcessLine () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#25 0x00306e3c in TRint::HandleTermInput () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libRint.so
#26 0x00305612 in TTermInputHandler::Notify () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libRint.so
#27 0x003072b8 in TTermInputHandler::ReadNotify () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libRint.so
#28 0x00a8b278 in TUnixSystem::CheckDescriptors () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#29 0x00a8a146 in TUnixSystem::DispatchOneEvent () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#30 0x00999686 in TSystem::InnerLoop () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#31 0x00999626 in TSystem::Run () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#32 0x00913054 in TApplication::Run () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libCore.so
#33 0x003067f0 in TRint::Run () from /mnt/g2fs1_mnt/cern/root_5.14.00//lib/libRint.so
#34 0x08048d4b in main ()[/quote]
So, what is my fault?
If a create one by one TFile It works, but if I do this, I lose the possibility
of a dynamic macro.
I hope to have been clear in my exposistion
Best Regards
Paolo
p.s. my root version is 5.14/00e, CINT 5.16.16 on an SLC 4 machine
p.p.s. you can clone histo1.root to obtain histo2.root histo3.root, i was blocked to upload them because 3 file limit
histofile.txt (41 Bytes)
reading.C (2.56 KB)
histo1.root (5.48 KB)
pcanal
April 20, 2007, 4:58pm
2
Hi,
The problem is that you define: //Local variables
TFile *f_histos2;
f_histos2 = new TFile[nomi_histofile.size()];
as a single object, but use it as an array: f_histos2[file_loop].Print();
f_histos2[file_loop].GetListOfKeys()->Print();
Cheers,
Philippe
Thank you for your help, but I don’t know how to use an array of
TFiles in this istuation.
An suggestion to correct it?
pcanal
April 23, 2007, 5:11pm
4
Hi,
You could reorganize your code so that you only need one file open at a time or you could use a TObjArray or a TList or your favorite STL containers.
Philippe
Dear Phileippe, I have done it !
But now I have antoher problem!
I don’t understand why, if I create a “good” TFile array,
when I open a file it gives me no stats and when i do
f_histos2[file_loop].GetListOfKeys()->Print();
It hangs.
Here the full code:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstring>
#include "TNtuple.h"
#include "TFile.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TTree.h"
#include "TChain.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TF1.h"
#include "TStyle.h"
void Comb_HISTO(char *histofile,char* histotodraw){
char char_buffer[150];
vector <string> nomi_file;
vector <string> nomi_histo;
FILE *histo_file;
histo_file = fopen(histofile,"r");
FILE *histo_to_draw;
histo_to_draw = fopen(histotodraw,"r");
//REad list of root files
while ( fscanf(histo_file,"%s\n",char_buffer) > -1){
string dummystring;
dummystring = char_buffer;
if(dummystring.substr(0,2) == "//" ) continue;
cout << "File input: " << dummystring << endl;
nomi_file.push_back(char_buffer);
}
if (nomi_file.size() == 0) {
cout << "!! ERROR NO USABLE FILES" << endl;
return;
}
//read list of histo to combine together
while ( fscanf(histo_to_draw,"%s\n",char_buffer) > -1){
string dummystring;
dummystring = char_buffer;
if(dummystring.substr(0,2) == "//" ) continue;
cout << "Histo to draw: " << dummystring << endl;
nomi_histo.push_back(char_buffer);
}
if (nomi_histo.size() == 0) {
cout << "!! ERROR NO USABLE HISTO" << endl;
return;
}
//Local variables
vector <string>::iterator histo_iter;
//TFile *f_histos;
size_t file_array_size(nomi_file.size());
TFile *f_histos2 = new TFile[file_array_size];
TH1F *histos;
histos = new TH1F[nomi_histo.size()];
vector <string>::iterator file_iter;
int file_loop=0;
for(file_iter=nomi_file.begin();file_iter!=nomi_file.end();file_iter++){
cout << *file_iter << endl;
char dummy_name[((*file_iter).size())+1];
sprintf(dummy_name,"%s",(*file_iter).c_str());
cout << dummy_name << endl;
f_histos2[file_loop].Open( (*file_iter).c_str(),"READ");
f_histos2[file_loop].Print();
f_histos2[file_loop].GetListOfKeys()->Print();
cout << " #### " << endl << endl;;
file_loop++;
}
}
It seems that it doesn’t like an array of Tfiles
Thanks for your help and patience!
pcanal
April 24, 2007, 7:12pm
6
Instead of TFile *f_histos2 = new TFile[file_array_size];
....
f_histos2[file_loop].Open( (*file_iter).c_str(),"READ");
UseTFile **f_histos2 = new TFile*[file_array_size];
....
f_histos2[file_loop] = TFile::Open( (*file_iter).c_str(),"READ");
Philippe.