Logo ROOT  
Reference Guide
TEntryListBlock.h
Go to the documentation of this file.
1// @(#)root/tree:$Id$
2// Author: Anna Kreshuk 27/10/2006
3
4/*************************************************************************
5 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// TEntryListBlock
14//
15// Used internally in TEntryList to store the entry numbers.
16//
17// There are 2 ways to represent entry numbers in a TEntryListBlock:
18// 1) as bits, where passing entry numbers are assigned 1, not passing - 0
19// 2) as a simple array of entry numbers
20// In both cases, a UShort_t* is used. The second option is better in case
21// less than 1/16 of entries passes the selection, and the representation can be
22// changed by calling OptimizeStorage() function.
23// When the block is being filled, it's always stored as bits, and the OptimizeStorage()
24// function is called by TEntryList when it starts filling the next block. If
25// Enter() or Remove() is called after OptimizeStorage(), representation is
26// again changed to 1).
27//
28// Operations on blocks (see also function comments):
29// - Merge() - adds all entries from one block to the other. If the first block
30// uses array representation, it's changed to bits representation only
31// if the total number of passing entries is still less than kBlockSize
32// - GetEntry(n) - returns n-th non-zero entry.
33// - Next() - return next non-zero entry. In case of representation 1), Next()
34// is faster than GetEntry()
35//
36//////////////////////////////////////////////////////////////////////////
37
38#ifndef ROOT_TEntryListBlock
39#define ROOT_TEntryListBlock
40
41#include "TObject.h"
42
44{
45 protected:
46 Int_t fNPassed; ///< number of entries in the entry list (if fPassing=0 - number of entries
47 ///< not in the entry list
48 Int_t fN; ///< size of fIndices for I/O =fNPassed for list, fBlockSize for bits
49 UShort_t *fIndices; ///<[fN]
50 Int_t fType; ///<0 - bits, 1 - list
51 Bool_t fPassing; ///<1 - stores entries that belong to the list
52 ///<0 - stores entries that don't belong to the list
53 UShort_t fCurrent; ///<! to fasten Contains() in list mode
54 Int_t fLastIndexQueried; ///<! to optimize GetEntry() in a loop
55 Int_t fLastIndexReturned; ///<! to optimize GetEntry() in a loop
56
57 void Transform(Bool_t dir, UShort_t *indexnew);
58
59 public:
60
61 enum { kBlockSize = 4000 }; //size of the block, 4000 UShort_ts
63 TEntryListBlock(const TEntryListBlock &eblock);
66
67 Bool_t Enter(Int_t entry);
68 Bool_t Remove(Int_t entry);
69 Int_t Contains(Int_t entry);
70 void OptimizeStorage();
72 Int_t Next();
73 Int_t GetEntry(Int_t entry);
75 Int_t GetType() { return fType; }
77 virtual void Print(const Option_t *option = "") const;
78 void PrintWithShift(Int_t shift) const;
79
80 ClassDef(TEntryListBlock, 1) //Used internally in TEntryList to store the entry numbers
81
82};
83
84#endif
unsigned short UShort_t
Definition: RtypesCore.h:36
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:326
Used by TEntryList to store the entry numbers.
Int_t fLastIndexQueried
! to optimize GetEntry() in a loop
void OptimizeStorage()
If there are < kBlockSize or >kBlockSize*15 entries, change to an array representation.
UShort_t * fIndices
[fN]
Int_t Next()
Return the next non-zero entry Faster than GetEntry() function.
TEntryListBlock & operator=(const TEntryListBlock &rhs)
void Transform(Bool_t dir, UShort_t *indexnew)
Transform the existing fIndices.
Int_t fType
0 - bits, 1 - list
Int_t fNPassed
number of entries in the entry list (if fPassing=0 - number of entries not in the entry list
~TEntryListBlock()
Destructor.
Int_t GetNPassed()
Returns the number of entries, passing the selection.
void PrintWithShift(Int_t shift) const
Print the indices of this block + shift (used from TEntryList::Print()) to print the current values.
Bool_t Enter(Int_t entry)
If the block has already been optimized and the entries are stored as a list and not as bits,...
Bool_t Remove(Int_t entry)
Remove entry #entry If the block has already been optimized and the entries are stored as a list and ...
Int_t fN
size of fIndices for I/O =fNPassed for list, fBlockSize for bits
Int_t fLastIndexReturned
! to optimize GetEntry() in a loop
Bool_t fPassing
1 - stores entries that belong to the list 0 - stores entries that don't belong to the list
UShort_t fCurrent
! to fasten Contains() in list mode
TEntryListBlock()
Default c-tor.
Int_t Contains(Int_t entry)
True if the block contains entry #entry.
virtual void Print(const Option_t *option="") const
Print the entries in this block.
Int_t GetEntry(Int_t entry)
Return entry #entry.
Int_t Merge(TEntryListBlock *block)
Merge with the other block Returns the resulting number of entries in the block.
Mother of all ROOT objects.
Definition: TObject.h:37
constexpr size_t block
Definition: BatchHelpers.h:29