Logo ROOT   6.16/01
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// Pin vtable
59 : fTable(table)
60{
61 //to be documented
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// UInt_t R__s, R__c;
66
67void 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}
SVector< double, 2 > v
Definition: Dict.h:5
int Int_t
Definition: RtypesCore.h:41
short Version_t
Definition: RtypesCore.h:61
long Long_t
Definition: RtypesCore.h:50
#define ClassImp(name)
Definition: Rtypes.h:363
Array of longs (32 or 64 bits per element).
Definition: TArrayL.h:27
const Long_t * GetArray() const
Definition: TArrayL.h:43
void Adopt(Int_t n, Long_t *array)
Adopt array arr into TArrayL, i.e.
Definition: TArrayL.cxx:81
Long_t * fArray
Definition: TArrayL.h:30
Int_t GetSize() const
Definition: TArray.h:47
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
Bool_t IsReading() const
Definition: TBuffer.h:83
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
const TTable * fTable
Definition: TTableMap.h:37
virtual ~TTableMap()
Definition: TTableMap.cxx:57
TTableMap(const TTable *table=0)
Definition: TTableMap.cxx:58
Bool_t IsValid() const
Definition: TTableMap.h:62
Definition: TTable.h:48
const Int_t n
Definition: legend1.C:16
void table()
Definition: table.C:85