FEDRA emulsion software from the OPERA Collaboration
TIndexCell Class Reference

sort collection with attributes More...

#include <TIndexCell.h>

Inheritance diagram for TIndexCell:
Collaboration diagram for TIndexCell:

Public Member Functions

Int_t Add (Int_t narg, Long_t varg[])
 
Int_t Add (Long_t p1)
 
TIndexCellAt (Int_t idx) const
 
TIndexCell const * At (Int_t narg, Int_t vind[]) const
 
Int_t Compare (const TObject *obj) const
 
Int_t ComparePatterns (Int_t nind, Long_t vdiff[], TIndexCell *cin, Int_t strip=0)
 
Int_t ComparePatterns (Int_t nind, TIndexCell *cin, Int_t srtip=0)
 
void Delete ()
 
void Drop ()
 
void Drop (int i)
 
void DropButFirst (int level)
 
void DropButLast (int level)
 
int DropCouples (int level)
 
TIndexCellFind (Int_t narg, Long_t varg[]) const
 
TIndexCellFind (Long_t p1) const
 
TIndexCellFindAdd (Long_t p1)
 
Int_t GetEntries () const
 
Int_t GetValues (Int_t level, Int_t vind[], Long_t val[]) const
 
ULong_t Hash () const
 
Bool_t IsEqual (const TObject *obj) const
 
Bool_t IsSortable () const
 
TObjArray * List () const
 
Int_t MaxN (Int_t level) const
 
Int_t MaxN (Int_t level, Int_t vind[]) const
 
Long_t MaxV (Int_t level) const
 
Long_t MaxV (Int_t level, Int_t vind[]) const
 
Int_t MinN (Int_t level) const
 
Int_t MinN (Int_t level, Int_t vind[]) const
 
Long_t MinV (Int_t level) const
 
Long_t MinV (Int_t level, Int_t vind[]) const
 
Int_t N () const
 
Int_t N (Int_t level) const
 
Int_t Nlevels () const
 
void Print (Option_t *) const
 
void PrintPopulation (int level) const
 
void PrintStat () const
 
void Purge (int level)
 
void SetName (const char *varlist)
 
void SetValue (Long_t p1)
 
void Shift (Int_t n, Long_t vshift[])
 
void Shift (Long_t vshift)
 
void Sort (Int_t upto=kMaxInt)
 
 TIndexCell ()
 
 TIndexCell (const TIndexCell &c)
 
 TIndexCell (Long_t p1)
 
Long_t Value () const
 
 ~TIndexCell ()
 

Private Attributes

TObjArray * fList
 list of TIndexCell's More...
 
Long_t fValue
 hash value More...
 

Friends

class TIndexCellIter
 
class TIndexCellIterV
 

Detailed Description

sort collection with attributes

//////////////////////////////////////////////////////////////////////// // TIndexCell // // sort collection with attributes // // ////////////////////////////////////////////////////////////////////////

Constructor & Destructor Documentation

◆ TIndexCell() [1/3]

TIndexCell::TIndexCell ( )
inline
31:fValue(0) { fList=0; }
Long_t fValue
hash value
Definition: TIndexCell.h:26
TObjArray * fList
list of TIndexCell's
Definition: TIndexCell.h:28

◆ TIndexCell() [2/3]

TIndexCell::TIndexCell ( Long_t  p1)
inline
32:fValue(p1) { fList=0; }

◆ TIndexCell() [3/3]

TIndexCell::TIndexCell ( const TIndexCell c)

◆ ~TIndexCell()

TIndexCell::~TIndexCell ( )
44{
45 Delete();
46}
void Delete()
Definition: TIndexCell.cpp:49

Member Function Documentation

◆ Add() [1/2]

Int_t TIndexCell::Add ( Int_t  narg,
Long_t  varg[] 
)
603{
604 if(narg==1) return Add( varg[0] );
605 else {
606 TIndexCell *b=FindAdd(varg[0]);
607 narg--;
608 return b->Add( narg, varg+1 );
609 }
610}
sort collection with attributes
Definition: TIndexCell.h:19
TIndexCell * FindAdd(Long_t p1)
Definition: TIndexCell.cpp:575
Int_t Add(Int_t narg, Long_t varg[])
Definition: TIndexCell.cpp:602

◆ Add() [2/2]

Int_t TIndexCell::Add ( Long_t  p1)
591{
592 if(!fList) fList = new TObjArray();
593 else if( Find(p1) )
594 printf("WARNING: TIndexCell::Add(%ld) - object is not unique!\n",p1);
595
596 TIndexCell *b= new TIndexCell(p1);
597 fList->Add(b);
598 return 1;
599}
TIndexCell * Find(Int_t narg, Long_t varg[]) const
Definition: TIndexCell.cpp:613
TIndexCell()
Definition: TIndexCell.h:31

◆ At() [1/2]

TIndexCell * TIndexCell::At ( Int_t  idx) const
inline
75 { if(fList) return (TIndexCell*)(fList->At(idx));
76 else return 0; }

◆ At() [2/2]

TIndexCell const * TIndexCell::At ( Int_t  narg,
Int_t  vind[] 
) const

return cell located at vind[narg] address

520{
522
523 TIndexCell *b=0;
524 // TIndexCell *th=this;
525
526 if(nind>0) {
527 b = At(vind[0]);
528 if(nind==1) return b;
529 if(b) {
530 nind--;
531 return b->At(nind,vind+1);
532 }
533 }
534 else if(nind==0) return this;
535 return 0;
536}
TIndexCell const * At(Int_t narg, Int_t vind[]) const
Definition: TIndexCell.cpp:519

◆ Compare()

Int_t TIndexCell::Compare ( const TObject *  obj) const
inline
99 { if (fValue > ((TIndexCell*)obj)->Value())
100 return 1;
101 else if (fValue < ((TIndexCell*)obj)->Value())
102 return -1;
103 else
104 return 0; }
Long_t Value() const
Definition: TIndexCell.h:79

◆ ComparePatterns() [1/2]

Int_t TIndexCell::ComparePatterns ( Int_t  nind,
Long_t  vdiff[],
TIndexCell cin,
Int_t  strip = 0 
)

Compare 2 TIndexCells of the same structure and find number of common
cells at the given level and if(strip): drop all the rest (for current pattern)
vdiff - is the vector of values (levels) to be taken into account of
the length level
vdiff[i] = 0 - require value of i-th level being the same (exact comparison)
>0 - abs(value2-value1) <= vdiff[i]

82{
90
91 Int_t npat=0;
92 if(!cin) return npat;
93 if(!fList) return npat;
94 if(level<1) return npat;
95 Int_t entries = GetEntries();
96 if(entries<1) return npat;
97
98 Int_t npat0;
99 TIndexCell *c1=0;
100 TIndexCell *at=0;
101
102 npat0=npat=0;
103
104 for( int i=entries-1; i>-1; i-- ) {
105 at = At(i);
106 npat0 = npat;
107 if( vdiff[0] == 0 ) {
108 c1 = cin->Find(at->Value());
109 if( c1 ) {
110 if(level==1) {npat++;}
111 else if(level>1) {npat += at->ComparePatterns(level-1,vdiff+1,c1,strip);}
112 }
113 }
114 else if(vdiff[0] > 0 ) {
115 for( Long_t j=-vdiff[0]; j<=vdiff[0]; j++ ) {
116 c1 = cin->Find( at->Value()+j );
117 if( c1 ) {
118 if(level==1) npat++;
119 else if(level>1) {
120 npat += at->ComparePatterns(level-1,vdiff+1,c1,0);
121 }
122 }
123 }
124 }
125 //printf("level=%d i=%d, entries=%d, npat=%d, npat0=%d \n",
126 // level,i,entries,npat,npat0 );
127 if(strip) {
128 if(npat<=npat0) { fList->RemoveAt(i); at->Drop(); delete at; Sort(); }
129 }
130 }
131
132 if(strip) {
133 fList->Compress();
134 Sort();
135 }
136
137 return npat;
138}
Int_t npat
Definition: Xi2HatStartScript.C:33
void Drop()
Definition: TIndexCell.cpp:237
Int_t GetEntries() const
Definition: TIndexCell.h:82
Int_t ComparePatterns(Int_t nind, TIndexCell *cin, Int_t srtip=0)
Definition: TIndexCell.cpp:141
void Sort(Int_t upto=kMaxInt)
Definition: TIndexCell.cpp:539
TCanvas * c1
Definition: energy.C:13

◆ ComparePatterns() [2/2]

Int_t TIndexCell::ComparePatterns ( Int_t  nind,
TIndexCell cin,
Int_t  srtip = 0 
)
142{
143 Long_t *vdiff = new Long_t[level];
144 for( int i=0; i<level; i++ ) vdiff[i]=0;
145 Int_t cp = ComparePatterns( level, vdiff, cin, strip );
146 delete[] vdiff;
147 return cp;
148}
EdbSegCouple * cp
Definition: tlg2couples.C:28

◆ Delete()

void TIndexCell::Delete ( )
50{
51 if(fList) {
52 int ncc = GetEntries();
53 for(int i=0; i<ncc; i++ ) {
54 At(i)->Delete();
55 }
56 fList->Delete();
57 delete fList;
58 fList=0;
59 }
60}

◆ Drop() [1/2]

void TIndexCell::Drop ( )
238{
239 fValue=0;
240 Delete();
241}

◆ Drop() [2/2]

void TIndexCell::Drop ( int  i)

drop i-th cell on the highest level

223{
225
226 if(!fList) return;
227 TIndexCell *at = At(i);
228 if(at) {
229 at->Delete();
230 fList->RemoveAt(i);
231 delete at;
232 Sort();
233 }
234}

◆ DropButFirst()

void TIndexCell::DropButFirst ( int  level)

drop all elements except of first one in all cells on the level

177{
179
180 if(!fList) return;
181 int ncc=GetEntries();
182 if(level==0) {
183 if(ncc<2) return;
184 for(int i=ncc-1; i>0; i--) Drop(i);
185 } else if(level>0) {
186 for(int i=0; i<ncc; i++) At(i)->DropButFirst(level-1);
187 }
188}
void DropButFirst(int level)
Definition: TIndexCell.cpp:176

◆ DropButLast()

void TIndexCell::DropButLast ( int  level)

drop all elements except of last one in all cells on the level

192{
194
195 if(!fList) return;
196 int ncc=GetEntries();
197 if(level==0) {
198 if(ncc<2) return;
199 for( int i=ncc-2; i>=0; i-- ) Drop(i);
200 } else if(level>0) {
201 for(int i=0; i<ncc; i++) At(i)->DropButLast(level-1);
202 }
203}
void DropButLast(int level)
Definition: TIndexCell.cpp:191

◆ DropCouples()

int TIndexCell::DropCouples ( int  level)

drop all overoccupated cells on the level

207{
209 int count=0;
210 if(!fList) return count;
211 int ncc=GetEntries();
212 if(level==0) {
213 for(int i=ncc-1; i>-1; i--)
214 if(ncc>1) { Drop(i); count++;}
215 } else if(level>0) {
216 for(int i=0; i<ncc; i++) count+=At(i)->DropCouples(level-1);
217 }
218 return count;
219}
int DropCouples(int level)
Definition: TIndexCell.cpp:206

◆ Find() [1/2]

TIndexCell * TIndexCell::Find ( Int_t  narg,
Long_t  varg[] 
) const
614{
615 if(narg==1) return Find( varg[0] );
616 else {
617 TIndexCell *b=Find(varg[0]);
618 if(b) {
619 narg--;
620 return b->Find( narg, varg+1 );
621 }
622 }
623 return 0;
624}

◆ Find() [2/2]

TIndexCell * TIndexCell::Find ( Long_t  p1) const
628{
629 if(!fList) return 0;
630 TIndexCell a(p1);
631 if(!fList->IsSorted())
632 return (TIndexCell*)(fList->FindObject(&a));
633 Int_t i = fList->BinarySearch(&a);
634 if(i>=0) return At(i);
635 return 0;
636}
void a()
Definition: check_aligned.C:59

◆ FindAdd()

TIndexCell * TIndexCell::FindAdd ( Long_t  p1)
576{
577 TIndexCell *b=0;
578
579 if(!fList) fList = new TObjArray();
580 else {
581 b = Find(p1);
582 if( b ) return b;
583 }
584 b= new TIndexCell(p1);
585 fList->Add(b);
586 return b;
587}

◆ GetEntries()

Int_t TIndexCell::GetEntries ( ) const
inline
83 { if(fList) return fList->GetEntriesFast();
84 else return 0; }

◆ GetValues()

Int_t TIndexCell::GetValues ( Int_t  level,
Int_t  vind[],
Long_t  val[] 
) const

return vector of values correspondent to indexes on the given level

506{
508
509 TIndexCell const *b;
510 for( int lev=1; lev<=nind; lev++ ) {
511 b=At(lev,vind);
512 if(!b) return 0;
513 val[lev-1]=b->Value();
514 }
515 return 1;
516}

◆ Hash()

ULong_t TIndexCell::Hash ( ) const
inline
94{ return fValue; }

◆ IsEqual()

Bool_t TIndexCell::IsEqual ( const TObject *  obj) const
inline
96 { return fValue == ((TIndexCell*)obj)->Value(); }

◆ IsSortable()

Bool_t TIndexCell::IsSortable ( ) const
inline
97{ return kTRUE; }

◆ List()

TObjArray * TIndexCell::List ( ) const
inline
78{ return fList; }

◆ MaxN() [1/2]

Int_t TIndexCell::MaxN ( Int_t  level) const

return population of the maximal populated cell on the given level

470{
472 Int_t *vind = new Int_t[level];
473 Int_t max = MaxN(level,vind);
474 delete[] vind;
475 return max;
476}
Int_t MaxN(Int_t level, Int_t vind[]) const
Definition: TIndexCell.cpp:479
int max
Definition: check_shower.C:41

◆ MaxN() [2/2]

Int_t TIndexCell::MaxN ( Int_t  level,
Int_t  vind[] 
) const

return population of the maximal populated cell on the given level and cell address

TODO: check this routine

480{
483
485
486 if(level==0)
487 if(fList) return GetEntries();
488 Int_t n=-999999999, k=-999999999;
489 if(fList) {
490 if(level>0) {
491 int nentr=GetEntries();
492 for(int i=0; i<nentr; i++) {
493 k=At(i)->MaxN(level-1,vind+1);
494 if(n < k) {
495 n=k;
496 vind[0] = i;
497 }
498 }
499 }
500 }
501 return n;
502}

◆ MaxV() [1/2]

Long_t TIndexCell::MaxV ( Int_t  level) const

return maximal value on the given level

402{
404 Int_t *vind = new Int_t[level];
405 Long_t max = MaxV(level,vind);
406 delete[] vind;
407 return max;
408}
Long_t MaxV(Int_t level, Int_t vind[]) const
Definition: TIndexCell.cpp:411

◆ MaxV() [2/2]

Long_t TIndexCell::MaxV ( Int_t  level,
Int_t  vind[] 
) const

return maximal value on the given level and cell address

412{
414
415 if(level==0) return fValue;
416 Long_t n=-kMaxInt, k=-kMaxInt;
417 if(fList) {
418 if(level>0) {
419 int ncc = GetEntries();
420 for(int i=0; i<ncc; i++) {
421 k=At(i)->MaxV(level-1,vind+1);
422 if(n < k) {
423 n=k;
424 vind[0]=i;
425 }
426 }
427 }
428 }
429 return n;
430}

◆ MinN() [1/2]

Int_t TIndexCell::MinN ( Int_t  level) const

return population of the mimimal populated cell on the given level

434{
436 Int_t *vind = new Int_t[level];
437 Int_t min = MinN(level,vind);
438 delete[] vind;
439 return min;
440}
float min(TClonesArray *t)
Definition: bitview.cxx:275
Int_t MinN(Int_t level, Int_t vind[]) const
Definition: TIndexCell.cpp:443

◆ MinN() [2/2]

Int_t TIndexCell::MinN ( Int_t  level,
Int_t  vind[] 
) const

return population of the mimimal populated cell on the given level and cell address

TODO: check this routine

444{
447
449
450 if(level==0)
451 if(fList) return GetEntries();
452 Int_t n=kMaxInt, k=kMaxInt;
453 if(fList) {
454 if(level>0) {
455 int nentr=GetEntries();
456 for(int i=0; i<nentr; i++) {
457 k=At(i)->MinN(level-1,vind+1);
458 if(n > k) {
459 n=k;
460 vind[0]=i;
461 }
462 }
463 }
464 }
465 return n;
466}

◆ MinV() [1/2]

Long_t TIndexCell::MinV ( Int_t  level) const

return mimimal value on the given level

370{
372 Int_t *vind = new Int_t[level];
373 Long_t min = MinV(level,vind);
374 delete[] vind;
375 return min;
376}
Long_t MinV(Int_t level, Int_t vind[]) const
Definition: TIndexCell.cpp:379

◆ MinV() [2/2]

Long_t TIndexCell::MinV ( Int_t  level,
Int_t  vind[] 
) const

return mimimal value on the given level and vector of indexes

380{
382
383 if(level==0) return fValue;
384 Long_t n=kMaxInt, k=kMaxInt;
385 if(fList) {
386 if(level>0) {
387 int ncc = GetEntries();
388 for(int i=0; i<ncc; i++) {
389 k=At(i)->MinV(level-1,vind+1);
390 if(n > k) {
391 n=k;
392 vind[0] = i;
393 }
394 }
395 }
396 }
397 return n;
398}

◆ N() [1/2]

Int_t TIndexCell::N ( ) const

return total number of basic cells (last level where fList=0)

345{
347 int n=0;
348 int ncc = GetEntries();
349 if(!fList) n++;
350 else for(int i=0; i<ncc; i++) n += At(i)->N();
351 return n;
352}
Int_t N() const
Definition: TIndexCell.cpp:344

◆ N() [2/2]

Int_t TIndexCell::N ( Int_t  level) const

◆ Nlevels()

Int_t TIndexCell::Nlevels ( ) const

return maximal depth of nested arrays

329{
331 int n=0,k=0;
332 if(!fList) return 0;
333 else {
334 int ncc = GetEntries();
335 for(int i=0; i<ncc; i++) {
336 k = At(i)->Nlevels();
337 if(k>n) n=k;
338 }
339 }
340 return n+1;
341}
Int_t Nlevels() const
Definition: TIndexCell.cpp:328

◆ Print()

void TIndexCell::Print ( Option_t *  opt) const
293{
294 //printf(" %s = ", (this->->List()->GetName());
295 printf("%ld\n", fValue);
296
297 if(!fList) return;
298 int ncc=GetEntries();
299 for(int i=0; i<ncc; i++) {
300 printf(" %s = ",fList->GetName());
301 ((TIndexCell*)fList->At(i))->Print("");
302 }
303}
void Print(Option_t *) const
Definition: TIndexCell.cpp:292

◆ PrintPopulation()

void TIndexCell::PrintPopulation ( int  level) const
245{
246 printf("Population on the level %d\n",level);
247 if(GetEntries()>0) {
248 TIndexCellIter itr(this,level);
249 const TIndexCell *c=0;
250 TIndexCell *cn=0;
252 while( (c=itr.Next()) ) {
253 cn = hist.FindAdd((Long_t)(c->N(1)));
254 if(!cn->At(0)) cn->Add(0);
255 cn->At(0)->SetValue(cn->At(0)->Value()+1);
256 }
257 hist.Sort();
258 hist.SetName("N:entries");
259 hist.Print("");
260 }
261}
IndexCell iterator.
Definition: TIndexCell.h:110
void SetValue(Long_t p1)
Definition: TIndexCell.h:87
void hist()
Definition: init.C:23

◆ PrintStat()

void TIndexCell::PrintStat ( ) const
265{
266 printf( "Ncell: %d\n", N() );
267 if(fList) printf( "Nlevels: %d %s \n", Nlevels(), List()->GetName() );
268
269 float phaseVol=1;
270 int range=0;
271 printf("level\t entries\t range\t occupancy\t minPop\t maxPop\n");
272 int nlvl=Nlevels();
273 for(int i=1; i<nlvl; i++ ) {
274 range = MaxV(i)-MinV(i)+1;
275 phaseVol *= range;
276#ifdef _WINDOWS
277 printf(" %d \t %d \t\t %d \t %f %% \t %d \t %d\n",
278#else
279 printf(" %d \t %d \t\t %d \t %f \%% \t %d \t %d\n",
280#endif
281 i,N(i),range,100.*N(i)/phaseVol, MinN(i),MaxN(i) );
282 }
283#ifdef _WINDOWS
284 printf(" %d \t %d \t\t %d \t %f %%\n",
285#else
286 printf(" %d \t %d \t\t %d \t %f \%%\n",
287#endif
288 Nlevels(),N(Nlevels()),1,100.*N(Nlevels())/phaseVol );
289}
TObjArray * List() const
Definition: TIndexCell.h:78

◆ Purge()

void TIndexCell::Purge ( int  level)

Drop branches of length < level

307{
309 if( !fList ) return;
310 if( level< 1 ) return;
311
312 int entries = GetEntries();
313 if( entries<1 ) Drop();
314 for(int i=entries-1; i>-1; i--) {
315 //if( At(i)->Nlevels() < level-1 ) { At(i)->Drop(); fList->RemoveAt(i); }
316 //??
317 if( At(i)->Nlevels()+1 < level-1 ) { At(i)->Drop(); fList->RemoveAt(i); }
318 else At(i)->Purge(level-1);
319 }
320 if(GetEntries()<1) Drop();
321 if(fList) {
322 fList->Compress();
323 Sort();
324 }
325}
void Purge(int level)
Definition: TIndexCell.cpp:306

◆ SetName()

void TIndexCell::SetName ( const char *  varlist)
550{
551 if(!fList) return;
552
553 fList->SetName(varlist);
554
555 Int_t nch = strlen(varlist);
556 if (nch <= 1) return;
557
558 const char *newvar=0;
559 int i;
560 for (i=1;i<nch;i++) {
561 if (varlist[i] == ':') {
562 if(i+1<nch) newvar=&varlist[i+1];
563 break;
564 }
565 }
566
567 if(!newvar) return;
568
569 int ncc = GetEntries();
570 for(i=0; i<ncc; i++)
571 ((TIndexCell*)fList->At(i))->SetName(newvar);
572}

◆ SetValue()

void TIndexCell::SetValue ( Long_t  p1)
inline
87{ fValue=p1; }

◆ Shift() [1/2]

void TIndexCell::Shift ( Int_t  n,
Long_t  vshift[] 
)

Shift al values of level i on the vshift[i]

64{
66
67 int ncc = GetEntries();
68 if(level==1)
69 for(int i=0;i<ncc;i++) At(i)->Shift(vshift[0]);
70 else if( level>1 ) {
71 if(!fList) return;
72 for(int i=0; i<ncc; i++ ) {
73 At(i)->Shift(vshift[0]);
74 At(i)->Shift(level-1,vshift+1);
75 }
76 }
77}
void Shift(Long_t vshift)
Definition: TIndexCell.h:39

◆ Shift() [2/2]

void TIndexCell::Shift ( Long_t  vshift)
inline
39{ SetValue( Value()+vshift ); }

◆ Sort()

void TIndexCell::Sort ( Int_t  upto = kMaxInt)
540{
541 if(fList) {
542 fList->Sort();
543 int ncc = GetEntries();
544 for(int i=0; i<ncc; i++) At(i)->Sort();
545 }
546}

◆ Value()

Long_t TIndexCell::Value ( ) const
inline
79{ return fValue; }

Friends And Related Function Documentation

◆ TIndexCellIter

friend class TIndexCellIter
friend

◆ TIndexCellIterV

friend class TIndexCellIterV
friend

Member Data Documentation

◆ fList

TObjArray* TIndexCell::fList
private

list of TIndexCell's

◆ fValue

Long_t TIndexCell::fValue
private

hash value


The documentation for this class was generated from the following files: