Histos from two files

From: Dr. John Krane <jkrane_at_netzero.com>
Date: Wed, 21 Jun 2006 15:27:23 -0500


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 FAILED". 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?

#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;

}

-- 

Dr. John Krane
http://jkrane.home.comcast.net

Stock Options Financier, Physicist, ...and Adventurer
Received on Wed Jun 21 2006 - 22:27:32 MEST

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