Logo ROOT   6.08/07
Reference Guide
TTableMap.cxx
Go to the documentation of this file.
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 
18 //////////////////////////////////////////////////////////////////////////////
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 
55 
56 TTableMap::TTableMap(const TTable *table)
57  : fTable(table)
58 {
59  //to be documented
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// UInt_t R__s, R__c;
64 
65 void TTableMap::Streamer(TBuffer &R__b)
66 {
67  TArrayL vecIO;
68  if (R__b.IsReading()) {
69  Version_t v = R__b.ReadVersion();
70  if (v) { }
71  // read Table
72  R__b >> fTable;
73  // Read index array
74  vecIO.Streamer(R__b);
75  Int_t n = vecIO.GetSize();
76  Int_t i = 0;
77  reserve(n);
78  Long_t *thisArr = vecIO.GetArray();
79  for (i=0; i<n; i++,thisArr++) push_back(*thisArr);
80  } else {
81  // Write TTable
82  assert(IsValid());
83  R__b.WriteVersion(IsA());
84  R__b << fTable;
85  // Write index array
86  TTableMap::iterator ptr = begin();
87  vecIO.Adopt(size(),&(*ptr));
88  vecIO.Streamer(R__b);
89  vecIO.fArray=0; // we should not destroy the real array
90  }
91 }
Bool_t IsReading() const
Definition: TBuffer.h:83
const Long_t * GetArray() const
Definition: TArrayL.h:45
short Version_t
Definition: RtypesCore.h:61
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
int Int_t
Definition: RtypesCore.h:41
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
void Adopt(Int_t n, Long_t *array)
Adopt array arr into TArrayL, i.e.
Definition: TArrayL.cxx:81
Int_t GetSize() const
Definition: TArray.h:49
SVector< double, 2 > v
Definition: Dict.h:5
Array of longs (32 or 64 bits per element).
Definition: TArrayL.h:29
Long_t * fArray
Definition: TArrayL.h:32
long Long_t
Definition: RtypesCore.h:50
#define ClassImp(name)
Definition: Rtypes.h:279
Definition: TTable.h:52
const TTable * fTable
Definition: TTableMap.h:39
Bool_t IsValid() const
Definition: TTableMap.h:64
const Int_t n
Definition: legend1.C:16
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0