Hello ROOTworld
After several hours playing around and reading the digest...
In the attached example scripts, I "succeeded" in filling a TTree in one
process
(treeprod.C) and reading it at the same time in another (treecons.C). Or
rather, reading the
number of entries in the TTree is fine, but when I try to read the value
of the branch variable
("mult") I get nonsense, unless I do a TTree::Draw("mult") in which case
I get the correct
spectrum and subsequent calls to TTree::GetEntry(i) followed by cout <<
mult give the
right value.
In other words, when the 2 scripts are running I get, on the treeprod()
terminal:
13th event... Mult=41
14th event... Mult=15
15th event... Mult=23
16th event... Mult=24
17th event... Mult=48
18th event... Mult=12
...
and on the treecons() terminal :
Got new event: event number 13 + Mult=1079526108
<TCanvas::MakeDefCanvas>: created default TCanvas with name c1
Got new event: event number 14 + Mult=41
Got new event: event number 15 + Mult=15
Got new event: event number 16 + Mult=23
Got new event: event number 17 + Mult=24
Got new event: event number 18 + Mult=48
Got new event: event number 19 + Mult=12
...
Oh, in fact I've just noticed that the value of "mult" is one event
behind the correct value as well!
Without the "Draw" line in treecons I get
Got new event: event number 13 + Mult=1079526108
Got new event: event number 14 + Mult=1079526108
Got new event: event number 15 + Mult=1079526108
Got new event: event number 16 + Mult=1079526108
Got new event: event number 17 + Mult=1079526108
Got new event: event number 18 + Mult=1079526108
etc. etc.
Can somebody help please ?
Also, is it possible to share the TTree in this way and still write it
to disk ?
Because when I tried to open the TMapFile after stopping the scripts I
was informed
(quite logically) that said file is not a TFile... Is it just a buffer
of sorts ?
What I actually want to be able to do is to store incoming data
acquisition events in a TTree
whilst an independent process triggered by a certain type of event would
then look back through
all the previously stored events for some correlation. Is this the best
(only) way to do it ?
Sorry if this is just too basic (again)
Thanks for any help
John
--
John D. Frankland <mailto:frankland@ganil.fr>
Beam Coordinator
GANIL
B.P. 55027
14076 CAEN Cedex 05
*tel:* +33 (0)231454628
*fax:* +33 (0)231454665
//$Id: indra2root.C,v 1.4 2003/10/06 22:16:15 franklan Exp $
// Lecture d'un fichier d'evenements INDRA et transformation en arbre ROOT
//
#ifndef __CINT__
#include <cstdio>
#include <Riostream.h>
#include <fstream>
#endif
#include "TMapFile.h"
#include "TTree.h"
#include "TRandom.h"
#include "TSystem.h"
//
// Fabriquer un arbre de Events
//
void treeprod()
{
TMapFile *fi = TMapFile::Create("treeprod.map","RECREATE",1000000,
"Memory mapped TTree");
TTree *mt=new TTree("Arbre","Arbre d'Event");
mt->SetDirectory(0);
fi->Add(mt, "Arbre");
int mult;
mt->Branch("mult",&mult,"mult/I");
mt->Print();
fi->Print();
int i=0;
while(1){
mult = gRandom->Integer(50);
mt->Fill();
i++;
cout << i << "th event... Mult=" << mult << endl;
fi->Update();
gSystem->Sleep(1000);
}
}
#ifndef __CINT__
#include <cstdio>
#include <Riostream.h>
#include <fstream>
#endif
#include "TMapFile.h"
#include "TTree.h"
#include "TSystem.h"
#include "TCanvas.h"
void treecons()
{
TMapFile *fi = TMapFile::Create("treeprod.map");
int old_entries = 0;
int mult;
TTree* arbmap = 0;
while(1){
arbmap = (TTree*)fi->Get("Arbre", arbmap);
if(arbmap->GetEntries() > old_entries){
old_entries = arbmap->GetEntries();
cout << "Got new event: event number " << old_entries;
arbmap->SetBranchAddress("mult",&mult);
arbmap->GetEntry(old_entries);
cout << " + Mult=" << mult<<endl;
arbmap->Draw("mult");
gPad->Modified();
gPad->Update();
}
if(gSystem->ProcessEvents()) break;
}
}
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:16 MET