Using : 3.03/02, Compiled for solarisCC5, Solaris 5.9
Hi all,
I would like some some help with using TEventList and TChain.
Skeleton of code to create list :
int MakeList()
{
//Compressed Scanning Data event class
TChain *chain = new TChain("Crystal B"); //Chain the tree "Crystal B"
chain->Add("/home/crash6/gamma/karl/ScanB1.root");
if (chain == 0) return 0;
chain->Add("/home/crash6/gamma/karl/ScanB2.root");
if (chain == 0) return 0;
Int_t nevents = Int_t(chain->GetEntries());
printf("\n %d events",nevents);
//===============================================
// Specify address where to read the event object
// The event was stored in a branch called "Prototype"
//===============================================
//object must be created before setting the branch address
ProtoExoScan *Data = new ProtoExoScan();
//Super branch
chain->SetBranchAddress("ProtoType", &Data);
//Make an event list and file to store it
Int_t comp = 5; // by default all files compressed
TEventList *elist =
new TEventList("elist","Events with # segments with E > THRESH = 1",5000);
TFile *efile = new TFile("elist2.root","RECREATE",
"nSegs = 1 event list");
efile->SetCompressionLevel(comp);
//Loop over all chained events.....
for (nGood = jentry=0; jentry < nevents; jentry++) {
ientry = chain->LoadTree(jentry);//ientry :entry number in the current file
//////////////////////////////////////////////////////
//Examine ALL Data
nb = chain->GetEntry(jentry); nbytes += nb;
Data->GetData(&x, &y, &TrigE, &TrigT, &segE[0], &segT[0], &pulse[0][0]);
if ( ((TrigE >= 6337) && (TrigE <= 6355)) ||
((TrigE >= 550) && (TrigE <= 565)) ) {
elist->Enter(chain->GetChainEntryNumber(ientry));
}
elist->Write();
efile->Close();
return jentry;
}
======================================================================
This appears to work in the simple case :
int CheckList()
{
//read in created list
TFile *efile = new TFile("elist2.root","READ");
TEventList *elist = (TEventList*) efile->Get("elist");
//TEventList elist = efile->Get("elist");
if (elist) elist->SetDirectory(0);
nevents = Int_t(elist->GetN());
printf("\n %d events in list",nevents);
//Loop over all chained events.....
for (jentry=0; jentry < 20; jentry++) {
entry = elist->GetEntry(jentry);
printf("\n %d %d",jentry,entry);
}
return jentry;
}
========================================================================
But I can't get it to work with a Chain : The following
hangs up at the end of the first root file.....
Suggestions ?
int ReadTree()
{
#ifdef __CINT__
//Load class if needed
if (!TClassTable::GetDict("ProtoExoScan")) {
gSystem.Load("libProtoExoScan.so");
}
#endif
gROOT->SetBatch(kTRUE);
//read in created list
TFile *efile = new TFile("elist2.root","READ");
TEventList *elist = (TEventList*) efile->Get("elist");
//TEventList elist = efile->Get("elist");
if (elist) elist->SetDirectory(0);
//Compressed Scanning Data event class
TChain *chain = new TChain("Crystal B"); //Chain the tree "Crystal B"
chain->Add("/home/crash6/gamma/karl/ScanB1.root");
if (chain == 0) return 0;
chain->Add("/home/crash6/gamma/karl/ScanB2.root");
if (chain == 0) return 0;
chain->Add("/home/crash6/gamma/karl/ScanB3.root");
if (chain == 0) return 0;
chain->Add("/home/crash6/gamma/karl/ScanB4.root");
if (chain == 0) return 0;
Int_t nevents = Int_t(chain->GetEntries());
printf("\n %d events in total",nevents);
//chain->SetEventList(elist);
nevents = Int_t(elist->GetN());
printf("\n %d events in list",nevents);
//===============================================
// Specify address where to read the event object
// The event was stored in a branch called "Prototype"
//===============================================
//object must be created before setting the branch address
ProtoExoScan *Data = new ProtoExoScan();
//Super branch : CompData
chain->SetBranchAddress("ProtoType", &Data);
Int_t entry, jentry, ientry;
Int_t nbytes = 0;
Int_t nb = 0;
//Loop over all chained events.....
for (nGood = jentry=0; jentry < nevents; jentry++) {
ientry = chain->LoadTree(jentry);
//////////////////////////////////////////////////////
//Examine ALL Data
entry = elist->GetEntry(jentry);
nb = chain->GetEntry(entry); nbytes += nb;
Data->GetData(&x, &y, &TrigE, &TrigT, &segE[0], &segT[0], &pulse[0][0]);
//assign position...
Data->GetPosition(&x, &y);
hPosition->Fill(x,y);
:
blah blah blah
:
}
}
return jentry;
}
Cheers,
Karl
==========================================================================
CEA Saclay, DAPNIA/SPhN Phone : (33) 01 69 08 7553
Bat 703 - l'Orme des Merisiers Fax : (33) 01 69 08 7584
F-91191 Gif-sur-Yvette E-mail : khauschild@cea.fr
France karl_hauschild@yahoo.co.uk
WWW: http://www-dapnia.cea.fr/Sphn
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:43 MET