Re: Histos from two files

From: Rene Brun <>
Date: Thu, 22 Jun 2006 15:53:24 +0200

Could you explain what you intend to do with the statement:  temp1->Write("temp2.root");

It could be that what you want to do is simply this:

void temp() {

 TFile *temp1, *temp2;
 TH1D *A, *B;

 temp1=new TFile("temp1.root","recreate");  A=new TH1D("A","plot1",10,0,10);
 A->Fill(5,1); //etc
 delete temp1;
 delete A;

 temp1=new TFile("temp1.root");
 temp2=new TFile("temp2.root","update");  B = (TH1*)temp1->Get("A");
 B->Fill(6,2.5); //etc
 delete temp1;
 delete temp2;
 delete B;

Rene Brun

Dr. John Krane wrote:
> Hi everyone,
> I am working with several thousand histograms at a time. The first
> set "A" is created from info in a database. The second set "B" is
> created from info in the first set of histograms. I have a set of
> code that works by consulting the db, creating set A, then immediately
> creating set B, and writing one big (big!) histogram file to disk. It
> takes 10 minutes to run.
> I want to make histo set A and save it to disk. Then anytime I update
> my analysis, I read in set A, create set B within a second histo file,
> and save only B back to disk at that time (leaving the file with set A
> unchanged on disk). This should be simple, but when I do it I get
> Error in <TFile::ReadBuffer>: error reading all requested bytes from
> file output_index_1996.root, got 0 of 18287
> R__unzip: error in header
> ...a few thousand times. So I have given up and am trying a new
> plan. (But if you are really curious about the above problem, email
> me directly!) My new plan is to read in set A, create histogram set B
> in that same file, and save the whole mess to a big (big!) histo file
> with a new name. This too seems like it should be easy, but it keeps
> failing.
> Could somebody please tell me what is wrong with the following toy
> code? I want to see "plot1 exists!" but all I ever see is
> "Error in <TFile::TFile>: file temp2.root does not exist
> I assure you I have tried several combinations (of the original plan
> and the new plan) but I am very frustrated. I am using Root version
> 4.04/02g, which is admittedly old, but I don't think such basic
> functionality TFile has been changed much has it?
> - John
> #include <iostream>
> #include <TFile.h>
> #include <TH1D.h>
> void temp() {
> TFile *temp1;
> TH1D *plot1;
> temp1=new TFile("temp1.root","recreate");
> plot1=new TH1D("plot1","plot1",10,0,10);
> temp1->Write();
> temp1->Close();
> temp1=0;
> temp1=new TFile("temp1.root","update");
> temp1->Write("temp2.root");
> temp1->Close();
> temp1=0;
> temp1=new TFile("temp2.root");
> plot1=0;
> if (temp1!=0) plot1=(TH1D*)gDirectory->FindObjectAny("plot1");
> if (plot1!=0) cerr<<"plot1 exists!"<<endl;
> else cerr<<"FAILED"<<endl;
> }
Received on Thu Jun 22 2006 - 15:53:29 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:59 MET