Re: File conflict in Windows

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Mon, 12 Feb 2007 16:30:35 +0100


It looks like you are reinventing the wheel ! This functionality is already implemented in teh standard ROOT TTreeViewer. Just click on the Refresh button if you want to see a new view of a file written by another process.

I have posted many times to this list the 2 short macros below showing how to read a file
being written by another process (and yes, this does not work on Windows). Run treew.C in process 1 and treer.c in process 2.

Rene Brun

void treew() {
  TFile f("junk.root","recreate");
  TNtuple *ntuple = new TNtuple("ntuple","Demo","px:py:pz:random:i");   Float_t px, py, pz;
  for ( Int_t i=0; i<10000000; i++) {

     gRandom->Rannor(px,py);
     pz = px*px + py*py;
     Float_t random = gRandom->Rndm(1);
     ntuple->Fill(px,py,pz,random,i);
     if (i%1000 == 1) ntuple->AutoSave("SaveSelf");
  }
}

void treer() {

   TFile f("junk.root");
   TTree *ntuple = (TTree*)f.Get("ntuple");    TCanvas c1;
   Int_t first = 0;
   while(1) {

      if (first == 0) ntuple->Draw("px>>hpx", "","",10000000,first);
      else            ntuple->Draw("px>>+hpx","","",10000000,first);
      first = (Int_t)ntuple->GetEntries();
      c1.Update();
      gSystem->Sleep(1000); //sleep 1 second
      ntuple->Refresh();

   }
}

Tom Roberts wrote:
>
> Fine, Valeri wrote:
>> Thank you for your information about Linux file system. This must be
>> taken in account of course.
>>> the other process(es) will just see the old contents.
>>
>> Wow !!!
>> I am not sure whether this is what the Tom wanted.
>
> Well, I'm not sure what I want, either.
>
> What I definitely DON'T want is Windows' current behavior with my
> code, as it forces the user to remember to close the file in Root
> before re-running the simulation that over-writes the file. On Linux
> and Mac the user must re-open the file after overwriting it (not so bad).
>
> My new plan will work the same on all OSs (which is a boon): In Root
> I'll remember the filename and TNtuple name (rather than a pointer to
> the always-open TNtuple), and open the file and TNtuple only while
> using it. When the user has the mouse held down on a slider I'll keep
> them open until mouse release (my HistoRoot class provides sliders for
> interactive cuts on the histograms, as in the old HistoScope program).
> This way when the simulation is re-run, the user need not re-open the
> file, or close it, just create a new histogram which will use the
> current contents of the file. To prevent moving a slider on an old
> histogram from switching it to the new data, I'll disable the sliders
> if the modification time of the file has changed, giving an error
> messagebox.
>
>
>> For me this is a little bit confusing Normally If I open the file
>> with one and the same name I do want to see one and the same data.
>> You claim this is not the case under Linux. The result depends of
>> some sort of luck.
>
> This is well known and documented for Linux. Windows' behavior is also
> well known and documented. They are different. Personally I prefer the
> Linux way, but that's mostly due to experience than any objective
> criteria. It's been almost a decade since I have done any Windows C++
> development, and the difference caught me by surprise (:-)).
>
>
> Tom Roberts
>
>
>> Anyway, the Windows and Linux file system behave differently and I
>> had proposed the approach that may have made the application behavior
>> consistent across of the platforms, had I ?
>>
>>> It is a shame that Windows cannot cope with deleted open files.
>>
>> For the record.
>> I said Windows File System does provide such feature too. It is not
>> provided "by default".
>>
>>
>> My best regards, Valeri
>>
>>
>> ________________________________
>>
>> From: Roland Kuhn [mailto:rkuhn_at_e18.physik.tu-muenchen.de]
>> Sent: Mon 2/12/2007 3:47 AM
>> To: Fine, Valeri
>> Cc: Tom Roberts; ROOT Talk
>> Subject: Re: [ROOT] File conflict in Windows
>>
>>
>>
>> Hi Valeri!
>>
>> On 12 Feb 2007, at 00:12, Fine, Valeri wrote:
>>
>>>> While the file is open in Root, I cannot delete it using Windows
>>>> explorer.
>>> Do you think it is unreasonable?
>>> There are two scenarios
>>> 1. Either you can not change (delete, write append ...) the file
>>> that had been open by some program
>>> or
>>> 2. You can, but that program should not try to access the file
>>> anymore or crash.
>>>
>>> The average Linux file system doesn't provide such level of the
>>> protection. I would like to call your attention that this is the
>>> feature of the Windows file system rather the concrete Windows
>>> application.
>>>
>> I just verified that ROOT v5.14.00b does "access; lstat; unlink;
>> access; open" on the file, which is safe on all Unix-like systems,
>> because the file created by open is independent from the one unlinked
>> before. So, using TFile(..., "RECREATE") is a safe way of writing a
>> new data set, irrespective of the fact whether the file is open in
>> another process or not: the other process(es) will just see the old
>> contents. It is a shame that Windows cannot cope with deleted open
>> files.
>>
>> Ciao,
>> Roland
>>
>> --
>> TU Muenchen, Physik-Department E18, James-Franck-Str., 85748 Garching
>> Telefon 089/289-12575; Telefax 089/289-12570
>> --
>> CERN office: 892-1-D23 phone: +41 22 7676540 mobile: +41 76 487 4482
>> --
>> Any society that would give up a little liberty to gain a little
>> security will deserve neither and lose both. - Benjamin Franklin
>> -----BEGIN GEEK CODE BLOCK-----
>> Version: 3.12
>> GS/CS/M/MU d-(++) s:+ a-> C+++ UL++++ P+++ L+++ E(+) W+ !N K- w--- M
>> + !V Y+
>> PGP++ t+(++) 5 R+ tv-- b+ DI++ e+++>++++ h---- y+++
>> ------END GEEK CODE BLOCK------
>>
>>
>>
>>
Received on Mon Feb 12 2007 - 16:30:42 CET

This archive was generated by hypermail 2.2.0 : Mon Feb 12 2007 - 23:50:01 CET