Hi Anton, I am using the autosave mechanism in a similar context and think I might see the source of your problem. You need to delete the current tree from memory before attempting to read the next tree, e.g. gDirectory -> Delete("CHICSiTree"); Otherwise, the File.Get("CHICSiTree") command will retrieve the tree already in local memory without bothering to see if a new version exists in the file. Good luck, Sue Anton Fokin wrote: > Hi Rene, > > thanks for the reply, but it looks like it doesn't work for me... > > I have one process which opens a root file with "RECREATE" option and > constantly fills a tree. Autosave is set to 100 events and I call > gDirectory->SaveSelf() after each event. See the code lines below: > > // open a file > > EventFile = new TFile(EventFileName,"RECREATE"); > EventFile->SetCompressionLevel(0); > > // create a tree > > fTree = new TTree("CHICSiTree",title); > fTree->SetAutoSave(100); > fTree->Branch("Event", "TCHICSiEvent", &fEvent, 64000, 1); > > // inside the main loop > > fTree->Fill(); > gDirectory->SaveSelf(); > > Another process is a macro reading the tree. It works but the number of > events is always the same. On the other hand if I open and close file, it > works as expected, filling histograms "on-line"... I tryed to put different > lines in the macro in different places. Nothing helps... > > { > gROOT->Reset(); > > TH1F *Hist[32]; > > char Name[128]; > char Title[128]; > > for(Int_t i=0;i<32;i++) { > > sprintf(Name,"Detector%d",i+1); > sprintf(Title,"%d ",i+1); > > Hist[i] = new TH1F(Name,Title,100,0,100); > Hist[i]->SetStats(kFALSE); > } > > printf("\n\n-- CHICSi on-line macro demo --\n\n"); > > Short_t RingNumber; > > RQuantInputDescriptor * InputDescriptor = new RQuantInputDescriptor(); > InputDescriptor->SetNParam(1); > > InputDescriptor->SetParamName(0,"Ring number:"); > InputDescriptor->SetParam(0,10); > > new RQuantInputFrame(InputDescriptor, gClient->GetRoot(), > gRQuantMainFrame, 600, 400); > > RingNumber = InputDescriptor->GetParam(0); > > TCHICSiEvent* Event = new TCHICSiEvent(); > > TFile File("/home/anton/data/run001.root"); > TTree* Tree = (TTree*) File.Get("CHICSiTree"); > > TBranch* Branch = Tree->GetBranch("Event"); > Branch->SetAddress(&Event); > > Int_t FirstEvent = 0; > while (!gPreviewFrame->IsStopMacro()) { > > gDirectory->ReadKeys(); > > Tree = (TTree*) File.Get("CHICSiTree"); > > Branch = Tree->GetBranch("Event"); > Branch->SetAddress(&Event); > > Int_t NEvent = Int_t(Tree->GetEntries()); > Int_t NTrack; > Short_t Ring; > > printf("NEvent = %d\n",NEvent); > > for(Int_t EventCount=FirstEvent;EventCount<NEvent;EventCount++) { > Tree->GetEvent(EventCount); > > NTrack = Event->GetNTrack(); > for(Int_t TrackCount=0;TrackCount<NTrack;TrackCount++) { > Track = Event->GetTrack(TrackCount); > Ring = Track->GetRing(); > > if (Ring == RingNumber) > Hist[Track->GetRow()-1]->Fill(Track->GetdEHigh(),1); > } > > if (!(EventCount%1)) > gSystem->ProcessEvents(); > } > > gSystem->ProcessEvents(); > > FirstEvent = NEvent; > > TCanvas *Canvas; > if (gROOT->FindObject("PreviewCanvas")) { > Canvas = PreviewCanvas; > Canvas->cd(); > Canvas->Clear(); > } > else > Canvas = new TCanvas("Canvas","CHICSi event tree demo",1300,500); > > Canvas->Divide(8,4); > > for(Int_t i=0;i<32;i++) { > Canvas->cd(i+1); > Hist[i]->Draw(); > } > > Canvas->Modified(); > Canvas->Update(); > > gSystem->Sleep(1000); > > } > > File.Close(); > > printf("Macro execution terminated. Exiting...\n"); > } > > -----Original Message----- > From: owner-roottalk@pcroot.cern.ch > [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Rene Brun > Sent: Tuesday, May 02, 2000 6:43 PM > To: KOSU_FOKIN@garbo.lucas.lu.se > Cc: roottalk@pcroot.cern.ch > Subject: Re: [ROOT] Locking root files > > Hi Anton, > > look at > > http://root.cern.ch/root/html/TDirectory.html#TDirectory:ReadKeys > http://root.cern.ch/root/html/TDirectory.html#TDirectory:SaveSelf > > Rene Brun > > KOSU_FOKIN@garbo.lucas.lu.se wrote: > > > > Hi rooters, > > > > is there an opportunity to "lock" a root file? I have an event > > logger, which writes events in a root file and a client, which > > reads and process them. It works fine until logger performs > > autosave of a root tree and the client tryes to recover keys > > from "not closed" file at the same time. Then everything crashes. > > > > Any suggestions? > > > > /Anton
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:24 MET