00001 // @(#)root/table:$Id: TTableMap.cxx 27657 2009-02-28 04:51:36Z pcanal $ 00002 // Author: Valery Fine(fine@bnl.gov) 01/03/2001 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. * 00006 * Copyright (C) 2001 [BNL] Brookhaven National Laboratory. * 00007 * All rights reserved. * 00008 * * 00009 * For the licensing terms see $ROOTSYS/LICENSE. * 00010 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00011 *************************************************************************/ 00012 00013 #include "TArrayL.h" 00014 #include "TTableMap.h" 00015 00016 ////////////////////////////////////////////////////////////////////////////// 00017 // TTableMap class is helper class to keep the list of the referencs to the 00018 // TTable rows and iterate over it. 00019 // TTableMap is a persistent class. 00020 // The pointer to the TTableMap object may be used as an element 00021 // of the TTable row and saved with the table all together. 00022 // 00023 // For example, the track table may contain a member to the "map" of the hits 00024 // struct { 00025 // float helix; 00026 // TTableMap *hits; 00027 // } tracks_t; 00028 // 00029 // // Create track table: 00030 // LArTrackTable *tracks = new LArTrackTable(...); 00031 // 00032 // // Get pointer to the hit table 00033 // LArHitTable *hits = GiveMeHits(); 00034 // // Loop over all tracks 00035 // LArTrackTable::iterator track = tracks->begin(); 00036 // LArTrackTable::iterator last = tracks->end(); 00037 // for (;track != last;track++) { 00038 // // Find all hits of this track 00039 // LArHitTable::iterator hit = hits->begin(); 00040 // LArHitTable::iterator lastHit = hits->end(); 00041 // Long_t hitIndx = 0; 00042 // // Create an empty list of this track hits 00043 // (*track).hits = new TTableMap(hits); 00044 // for(;hit != lastHit;hit++,hitIndx) { 00045 // if (IsMyHit(*hit)) { // add this hit index to the current track 00046 // (*track).hits->push_back(hitIndx); 00047 // } 00048 // } 00049 // } 00050 //___________________________________________________________________ 00051 00052 ClassImp(TTableMap) 00053 00054 TTableMap::TTableMap(const TTable *table) 00055 : fTable(table) 00056 { 00057 //to be documented 00058 } 00059 00060 //___________________________________________________________________ 00061 void TTableMap::Streamer(TBuffer &R__b) 00062 { 00063 // UInt_t R__s, R__c; 00064 TArrayL vecIO; 00065 if (R__b.IsReading()) { 00066 Version_t v = R__b.ReadVersion(); 00067 if (v) { } 00068 // read Table 00069 R__b >> fTable; 00070 // Read index array 00071 vecIO.Streamer(R__b); 00072 Int_t n = vecIO.GetSize(); 00073 Int_t i = 0; 00074 reserve(n); 00075 Long_t *thisArr = vecIO.GetArray(); 00076 for (i=0; i<n; i++,thisArr++) push_back(*thisArr); 00077 } else { 00078 // Write TTable 00079 assert(IsValid()); 00080 R__b.WriteVersion(IsA()); 00081 R__b << fTable; 00082 // Write index array 00083 TTableMap::iterator ptr = begin(); 00084 vecIO.Adopt(size(),&(*ptr)); 00085 vecIO.Streamer(R__b); 00086 vecIO.fArray=0; // we should not destroy the real array 00087 } 00088 }