Access to TMap and TClonesArray IO
{
// root macro to access TMap from file 6/98 RXD
printf(" starting TMap access n");
gROOT->Reset();
// access root file and set up tree.
TFile f("Event.root");
TTree *T = (TTree*)f.Get("T");
// create pointer to to-be-read-in TMap and init to zero.
TMap* readMap = 0;
// set up the branch for the map and tell it where the TMap really is
TBranch *testMap = T->GetBranch("testMap");
testMap->SetAddress(&readMap);
TClonesArray* readClone = 0;
TBranch *testClone = T->GetBranch("testClone");
testClone->SetAddress(&readClone);
// the objects stored in the TMap
aKey* key;
aVal* val;
Int_t nevent = T->GetEntries();
printf(" read in file for %i events n",nevent);
for (Int_t i=0;i<nevent;i++) {
// get the whole event
T->GetEvent(i);
// set up the TMap iterator
TMapIter next(readMap);
printf(" loop over map elements n");
while (key = (aKey*)next()) {
val = (aVal*)readMap->GetValue(key);
printf("key %i val %f type %i n",key->GetKey(),val->GetVal(),
val->GetMcPart()->GetType());
}
TClonesArray& mcpart = *readClone;
for (Int_t i=0; i<4; ++i) {
printf("Particle type %i n",((McPart*)mcpart[i])->GetType());
}
}
}
ROOT page - Class index - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.