CMS 3D CMS Logo

FWTEventList.cc
Go to the documentation of this file.
1 #include "TMath.h"
2 #include "TCut.h"
3 
5 
6 //______________________________________________________________________________
7 void FWTEventList::Add(const TEventList *alist)
8 {
9  // Merge contents of alist with this list.
10  //
11  // Both alist and this list are assumed to be sorted prior to this call
12 
13  Int_t i;
14  Int_t an = alist->GetN();
15  if (!an) return;
16  Long64_t *alst = alist->GetList();
17  if (!fList) {
18  fList = new Long64_t[an];
19  for (i=0;i<an;i++) fList[i] = alst[i];
20  fN = an;
21  fSize = an;
22  return;
23  }
24  Int_t newsize = fN + an;
25  Long64_t *newlist = new Long64_t[newsize];
26  Int_t newpos, alpos;
27  newpos = alpos = 0;
28  for (i=0;i<fN;i++) {
29  while (alpos < an && fList[i] > alst[alpos]) {
30  newlist[newpos] = alst[alpos];
31  newpos++;
32  alpos++;
33  }
34  if (alpos < an && fList[i] == alst[alpos]) alpos++;
35  newlist[newpos] = fList[i];
36  newpos++;
37  }
38  while (alpos < an) {
39  newlist[newpos] = alst[alpos];
40  newpos++;
41  alpos++;
42  }
43  delete [] fList;
44  fN = newpos;
45  fSize = newsize;
46  fList = newlist;
47 
48  TCut orig = GetTitle();
49  TCut added = alist->GetTitle();
50  TCut updated = orig || added;
51  SetTitle(updated.GetTitle());
52 }
53 
54 //______________________________________________________________________________
55 void FWTEventList::Enter(Long64_t entry)
56 {
57  // Enter element entry into the list.
58 
59  if (!fList) {
60  fList = new Long64_t[fSize];
61  fList[0] = entry;
62  fN = 1;
63  return;
64  }
65  if (fN>0 && entry==fList[fN-1]) return;
66  if (fN >= fSize) {
67  Int_t newsize = TMath::Max(2*fSize,fN+fDelta);
68  Resize(newsize-fSize);
69  }
70  if(fN==0 || entry>fList[fN-1]) {
71  fList[fN] = entry;
72  ++fN;
73  } else {
74  Int_t pos = TMath::BinarySearch(fN, fList, entry);
75  if(pos>=0 && entry==fList[pos])
76  return;
77  ++pos;
78  memmove( &(fList[pos+1]), &(fList[pos]), 8*(fN-pos));
79  fList[pos] = entry;
80  ++fN;
81  }
82 }
virtual void Enter(Long64_t entry)
Definition: FWTEventList.cc:55
virtual void Add(const TEventList *list)
Definition: FWTEventList.cc:7
T Max(T a, T b)
Definition: MathUtil.h:44