StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TTableMap.cxx
1 // @(#)root/table:$Id$
2 // Author: Valery Fine(fine@bnl.gov) 01/03/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * Copyright (C) 2001 [BNL] Brookhaven National Laboratory. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #include "TTableMap.h"
14 
15 #include "TArrayL.h"
16 #include "TBuffer.h"
17 
19 // TTableMap class is helper class to keep the list of the referencs to the
20 // TTable rows and iterate over it.
21 // TTableMap is a persistent class.
22 // The pointer to the TTableMap object may be used as an element
23 // of the TTable row and saved with the table all together.
24 //
25 // For example, the track table may contain a member to the "map" of the hits
26 // struct {
27 // float helix;
28 // TTableMap *hits;
29 // } tracks_t;
30 //
31 // // Create track table:
32 // LArTrackTable *tracks = new LArTrackTable(...);
33 //
34 // // Get pointer to the hit table
35 // LArHitTable *hits = GiveMeHits();
36 // // Loop over all tracks
37 // LArTrackTable::iterator track = tracks->begin();
38 // LArTrackTable::iterator last = tracks->end();
39 // for (;track != last;track++) {
40 // // Find all hits of this track
41 // LArHitTable::iterator hit = hits->begin();
42 // LArHitTable::iterator lastHit = hits->end();
43 // Long_t hitIndx = 0;
44 // // Create an empty list of this track hits
45 // (*track).hits = new TTableMap(hits);
46 // for(;hit != lastHit;hit++,hitIndx) {
47 // if (IsMyHit(*hit)) { // add this hit index to the current track
48 // (*track).hits->push_back(hitIndx);
49 // }
50 // }
51 // }
52 //___________________________________________________________________
53 
54 ClassImp(TTableMap);
55 
56 // Pin vtable
57 TTableMap::~TTableMap() {}
58 TTableMap::TTableMap(const TTable *table)
59  : fTable(table)
60 {
61  //to be documented
62 }
63 
66 
67 void TTableMap::Streamer(TBuffer &R__b)
68 {
69  TArrayL vecIO;
70  if (R__b.IsReading()) {
71  Version_t v = R__b.ReadVersion();
72  if (v) { }
73  // read Table
74  R__b >> fTable;
75  // Read index array
76  vecIO.Streamer(R__b);
77  Int_t n = vecIO.GetSize();
78  Int_t i = 0;
79  reserve(n);
80  Long_t *thisArr = vecIO.GetArray();
81  for (i=0; i<n; i++,thisArr++) push_back(*thisArr);
82  } else {
83  // Write TTable
84  assert(IsValid());
85  R__b.WriteVersion(IsA());
86  R__b << fTable;
87  // Write index array
88  TTableMap::iterator ptr = begin();
89  vecIO.Adopt(size(),&(*ptr));
90  vecIO.Streamer(R__b);
91  vecIO.fArray=0; // we should not destroy the real array
92  }
93 }
Definition: TTable.h:48