Opening a Root file that is bening recreated continuously

Hi,

I’ve the folllowing situation:

  1. A program that “recreates” a Root file with lots of histograms every minute;
    takes < 10 seconds to recreate.
  2. A CGI program that tries to open that file whenever requested

Now there are occasions when the two may happen at the same time, i.e the CGI
program may try to open a file which is being recreated. What is the standard
behavior of TFile::Open() in this case? Will it block and eventually open the file
when recreated/closed and continue with its work?

I’m facing with problems where lots of CGI processes start hanging when I use a slideshow which cycles over a number of ‘online’ plots. So I was wondering if the above can cause such a problem.

What could be a safe strategy in order to eliminate such problems?

Thanks,

  • Subir

Hi Subir,

What you do does not make much sense (sorry ::slight_smile:
If you recreate a file (in use by another process), it is the same situation if you delete the file.
Instead you should use the facility to update an existing file in the producer
and in the client refresh the directory whenever you want to see a new view of the file.
see comments/example in TDirectory::readKeys and TDirectory::SaveSelf

Rene

Hi Rene,

Thanks a lot. I agree it made little sense. I learnt it the hard way
as I just wanted to make use of what was available to me:(

I had a look at TDirectory::readKeys and TDirectory::SaveSelf and I guess I more
or less got the idea. I’ll give it a try right away.

Regards,

  • Subir

[quote=“brun”]Hi Subir,

What you do does not make much sense (sorry ::slight_smile:
If you recreate a file (in use by another process), it is the same situation if you delete the file.
Instead you should use the facility to update an existing file in the producer
and in the client refresh the directory whenever you want to see a new view of the file.
see comments/example in TDirectory::readKeys and TDirectory::SaveSelf

Rene[/quote]

Dear Rene,

May I ask for a little more help?

I’ve implemented the producer side as follows:

fOnlineFile1->cd(); // fOnlineFile1 file handle: open in update mode during start-up
gROOT->GetListOfCanvases()->Write();
gDirectory->SaveSelf();
gDirectory->Purge(); // keeps only the 2 most recent namecycles

This way it works fine and I can connect clients manually and extract plots
with correct timestamp. I’ve not tried it with CGI though.

Is it possible to write the objects only once in the beginning and keep updating?
I saw the ‘force’ option and thought it might be feasible, but could not make that work.

Regards,

  • Subir

[quote=“brun”]Hi Subir,

What you do does not make much sense (sorry ::slight_smile:
If you recreate a file (in use by another process), it is the same situation if you delete the file.
Instead you should use the facility to update an existing file in the producer
and in the client refresh the directory whenever you want to see a new view of the file.
see comments/example in TDirectory::readKeys and TDirectory::SaveSelf

Rene[/quote]

Subir,

Instead of:

gROOT->GetListOfCanvases()->Write(); gDirectory->SaveSelf(); gDirectory->Purge(); // keeps only the 2 most recent namecycles do

gROOT->GetListOfCanvases()->Write("",TObject::kOverwrite); gDirectory->SaveSelf();
Rene

Dear Rene,

I’m back with problems once again! Continuing from the above discussion …

The histogram producer that updates the histograms uses Root version 4.00/08
(CDF Online default) and if I use the same from a client to connect to that file, it works.
However, on the CDF online server where I use Root version 5.12/00e (that
supports png on-the-fly) I fail. Here is the transcript of two sessions,

ROOT 4.00/08

root [0] TFile file = TFile::Open("/cdf/onln/data/cdf_svt/svttest/spymon/sarkar/SVTSPYMON_TEST_current.root")
root [1] gDirectory->ReadKeys()
(Int_t)1107
root [2] gDebug=1
root [3] gDirectory->Get(“Number of Word in Input streams HF wedge 2 - B4-B5”)
TKey Reading 1563 bytes at address 1589038
(class TObject
)0x8d9b548
root [4] TCanvas c = (TCanvas)gDirectory->Get(“Number of Word in Input streams HF wedge 2 - B4-B5”)
TKey Reading 1563 bytes at address 1589038
root [5] c->GetName()
(const char* 0x8f76964)“Number of Word in Input streams HF wedge 2 - B4-B5”

root [6] gDirectory->ReadKeys()
Info in : did not find plugin for class TSystem and uri
/cdf/onln/data/cdf_svt/svttest/spymon/sarkar/SVTSPYMON_TEST_current.root
TKey Reading 150730 bytes at address 1723185
(Int_t)1107
root [7] TList list = file->GetListOfKeys();
root [8] TKey key = dynamic_cast(list->At(0));
root [9] TCanvas
canvas = dynamic_cast(key->ReadObj());
TKey Reading 1886 bytes at address 1976879
root [10] canvas->GetName()
(const char
0x8d51c1c)“EoE Errors Total (frequency) MRG_OUT_SPY b0svt09 slot 11”

ROOT 5.12/00e

root [0] TFile *file = TFile::Open("/cdf/onln/data/cdf_svt/svttest/spymon/sarkar/SVTSPYMON_TEST_current.root")
root [1] gDirectory->ReadKeys()
(Int_t)1107
root [2] TCanvas *c = dynamic_cast(file->Get(“Number of Word in Input streams HF wedge 2 - B4-B5;1”))
Error in : object tag too large, I/O buffer corrupted
Error in : object of class TPad read too few bytes: 480 instead of 3675

root [3] TList *list = file->GetListOfKeys();
root [4] list->GetSize()
(const Int_t)1107
root [5] TKey key = dynamic_cast(list->At(0));
root [6] TCanvas
canvas = dynamic_cast(key->ReadObj());
TKey Reading 1886 bytes at address 1956173
Error in : object tag too large, I/O buffer corrupted
Error in : object of class TPad read too few bytes: 493 instead of 4111

etc. Comments?

Thanks,

  • Subir

[quote=“brun”]Subir,

Instead of:

gROOT->GetListOfCanvases()->Write(); gDirectory->SaveSelf(); gDirectory->Purge(); // keeps only the 2 most recent namecycles do

gROOT->GetListOfCanvases()->Write("",TObject::kOverwrite); gDirectory->SaveSelf();
Rene[/quote]

Subir,
Could you attach a small file generated by 4.00/08 and not readable with 5.12?
It looks like your TCanvas object contains an object of a class for which
the schema evolution fails.

Rene

Dear Rene,

webserver.infn.it/cdf/Misc/SVTSP … rrent.root
is such a file.

  • Subir

[quote=“brun”]Subir,
Could you attach a small file generated by 4.00/08 and not readable with 5.12?
It looks like your TCanvas object contains an object of a class for which
the schema evolution fails.

Rene[/quote]

Hi Subir,

What you forgot to tell me is that your file was not closed correctly.
In particular the StreamerInfo record is not written at the end of the file,
preventing the automatic schema evolution algorithm to work because the
information about the classes in the file is missing.

I see that there is only a small difference in TPad between version 4.00/08 and the version 5. I changed two members from persstent to transient status
such that the current CVS will read your old file even without the StreamerInfo record.

Rene

Dear Rene,

Sorry about that. In fact now I can see that if I stop the ever-running producer
properly which in turn closes the file opened in ‘Update’ mode, version 5
works fine on the closed file.

Thanks a lot for the fix. I shall have to wait till the new version with the fix
will be installed on the Online CDF web server.

Regards,

  • Subir

[quote=“brun”]Hi Subir,

What you forgot to tell me is that your file was not closed correctly.
In particular the StreamerInfo record is not written at the end of the file,
preventing the automatic schema evolution algorithm to work because the
information about the classes in the file is missing.

I see that there is only a small difference in TPad between version 4.00/08 and the version 5. I changed two members from persstent to transient status
such that the current CVS will read your old file even without the StreamerInfo record.

Rene[/quote]