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