ROOT  6.06/09
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 "TArrayL.h"
14 #include "TTableMap.h"
15 
16 //////////////////////////////////////////////////////////////////////////////
17 // TTableMap class is helper class to keep the list of the referencs to the
18 // TTable rows and iterate over it.
19 // TTableMap is a persistent class.
20 // The pointer to the TTableMap object may be used as an element
21 // of the TTable row and saved with the table all together.
22 //
23 // For example, the track table may contain a member to the "map" of the hits
24 // struct {
25 // float helix;
26 // TTableMap *hits;
27 // } tracks_t;
28 //
29 // // Create track table:
30 // LArTrackTable *tracks = new LArTrackTable(...);
31 //
32 // // Get pointer to the hit table
33 // LArHitTable *hits = GiveMeHits();
34 // // Loop over all tracks
35 // LArTrackTable::iterator track = tracks->begin();
36 // LArTrackTable::iterator last = tracks->end();
37 // for (;track != last;track++) {
38 // // Find all hits of this track
39 // LArHitTable::iterator hit = hits->begin();
40 // LArHitTable::iterator lastHit = hits->end();
41 // Long_t hitIndx = 0;
42 // // Create an empty list of this track hits
43 // (*track).hits = new TTableMap(hits);
44 // for(;hit != lastHit;hit++,hitIndx) {
45 // if (IsMyHit(*hit)) { // add this hit index to the current track
46 // (*track).hits->push_back(hitIndx);
47 // }
48 // }
49 // }
50 //___________________________________________________________________
51 
53 
54 TTableMap::TTableMap(const TTable *table)
55  : fTable(table)
56 {
57  //to be documented
58 }
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// UInt_t R__s, R__c;
62 
63 void TTableMap::Streamer(TBuffer &R__b)
64 {
65  TArrayL vecIO;
66  if (R__b.IsReading()) {
67  Version_t v = R__b.ReadVersion();
68  if (v) { }
69  // read Table
70  R__b >> fTable;
71  // Read index array
72  vecIO.Streamer(R__b);
73  Int_t n = vecIO.GetSize();
74  Int_t i = 0;
75  reserve(n);
76  Long_t *thisArr = vecIO.GetArray();
77  for (i=0; i<n; i++,thisArr++) push_back(*thisArr);
78  } else {
79  // Write TTable
80  assert(IsValid());
81  R__b.WriteVersion(IsA());
82  R__b << fTable;
83  // Write index array
84  TTableMap::iterator ptr = begin();
85  vecIO.Adopt(size(),&(*ptr));
86  vecIO.Streamer(R__b);
87  vecIO.fArray=0; // we should not destroy the real array
88  }
89 }
Bool_t IsReading() const
Definition: TBuffer.h:81
short Version_t
Definition: RtypesCore.h:61
#define assert(cond)
Definition: unittest.h:542
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
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:80
Bool_t IsValid() const
Definition: TTableMap.h:64
TClass * IsA() const
Array of longs (32 or 64 bits per element).
Definition: TArrayL.h:29
Int_t GetSize() const
Definition: TArray.h:49
Long_t * fArray
Definition: TArrayL.h:32
long Long_t
Definition: RtypesCore.h:50
Definition: TTable.h:52
const TTable * fTable
Definition: TTableMap.h:39
ClassImp(TTableMap) TTableMap
Definition: TTableMap.cxx:52
const Long_t * GetArray() const
Definition: TArrayL.h:45
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