Hello Rene,
Short version: I solved my problem with the original design, obviating the need to read in the histo file and save the same file to a different name.
Long version:
Although your solution occured to me, "B = (TH1*)temp1->Get("A"); " it 
was my intention to avoid several thousound Get statements.  That would 
require me to run through an entire list of histogram names.  I 
originally tried implementing code that simply opens two files and takes 
information from set A and holds that file open for the duration of the 
analysis code, saving histo set B to a new file.  As I said I got 
several thousand errors when I did that.  It is as if my pointers to set 
A became invalid half way through the analysis.  It might be that the 
C++ code was rearranging memory out from underneath me, and I didn't 
know how to stop it.  Alternate designs seemed highly inefficent no 
matter how I did things, so I retried my original idea (two files open 
at the same time, writing only set B to disk).
I was using FindObjectAny to read in my histograms from set A, rather than the Get method. A bad habit I suppose, but it let me ignore subdirectories, which made things easier (for me). I just now rewrote the code to go into the correct subdirectory and use Get, and now everything works as I designed it. No more thousands of errors, and my results match what I got before using the database technique.
Thanks again for the help.
Rene Brun wrote:
>
> 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
> A->Write();
> 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
> B->Write();
> 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
>> 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?
>>
>>    - 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;
>>
>> }
>>
>
>
>
-- Dr. John Krane http://jkrane.home.comcast.net Stock Options Financier, Physicist, ...and AdventurerReceived on Thu Jun 22 2006 - 19:52:02 MEST
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:59 MET