I am attempting to read data from a file, create histograms, and write the histograms to a root file. I get a bus error when I attempt to write the histograms, or when I attempt to write the root file. Any ideas?
In your code you would need to use an array of TH1F pointer rather than an array of TH1F object. In the following I simplified your code given that you do not need the histogram past one iteration and that the histogram are automatically owned by the current directory (and written by the call to file.Write()):[code]#include #include #include “TH1F.h” #include “TFile.h” #include
using namespace std;
int createRootFile()
{
fstream ROCDelay25OutputFile_(“testoutputat44-2.txt”, ios::in);
if(!ROCDelay25OutputFile_.good()){
cout << “could not open the file” << endl;
assert(0);
}
string tmpROC, tmpDelay, tmpString;
int tmp;
float tmpDAC, tmpResult;
[quote] is there any need to delete the histograms since they are new objects?[/quote]No need. The histogram are ‘owned’ by the TFile (and will be deleted when the TFile is ‘closed’; See the ‘Object Ownership’ chapter in the User’s Guide.