Function returns array of TH1F* - Problems

Hi,

I want to do a function which returns an array of histograms TH1F* running inside a loop, and sum the return of the function at each iteration. So I created a function which returns the histograms I want but I can’t use these histograms outside the function (when I call it in the loop).

This is a simplified code of what I want to do :

std::vector< TH1F* > test()
{
std::vector< TH1F* > hist;

hist.push_back( new TH1F("hist","title",100,0.,10.) );

hist[0]->Fill(5);
hist[0]->Fill(3);
hist[1]->Fill(8);

return hist;
}




void bla()
{
std::vector < TH1F* > histogram;

 histogram.push_back(test()[0]); histogram[0]->Draw(); // try 1

 histogram = test(); histogram[0]->Draw(); // try 2

 test()[0]->Draw(); // try 3

}

(of course in my code I included all the headers…)

In the test() function the histograms are OK, I can draw them etc…
But in the bla() function I can’t do anything with the output of test(), I always have a Segmentation Violation !

Also, in my real code, the error is not a segmentation violation but it is :

Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing /export/home/zp/comin/pythia8/pythia8175/btag/ntuple0/Merging_cc_ACLiC_dict.cxx /export/home/zp/comin/pythia8/pythia8175/btag/ntuple0/Merging_cc_ACLiC_dict.h !!!
Error: /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.18-x86_64-slc5-gcc4.3/bin/rootcint: error loading headers…
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
Info in : The compiler has not found any problem with your macro.
Probably your macro uses something rootcint can’t parse.
Check root.cern.ch/viewvc/trunk/cint/doc/limitati.txt for Cint’s limitations.
*** Interpreter error recovered ***

I’m compiling with ACLiC …

Thanks for your help !

Hi,

could you:
[ul]
[li] Specify the ROOT version and the platform you are running on[/li]
[li] Post a reproducer[/li][/ul]

Danilo