58 TEventList::TEventList(): TNamed()
73 TEventList::TEventList(
const char *name,
const char *title, Int_t initsize, Int_t delta)
74 :TNamed(name,title), fReapply(kFALSE)
77 if (initsize > 100) fSize = initsize;
79 if (delta > 100) fDelta = delta;
82 fDirectory = gDirectory;
83 if (fDirectory) fDirectory->Append(
this);
89 TEventList::TEventList(
const TEventList &list) : TNamed(list)
94 fList =
new Long64_t[fSize];
95 for (Int_t i=0; i<fN; i++)
96 fList[i] = list.fList[i];
97 fReapply = list.fReapply;
104 TEventList::~TEventList()
106 delete [] fList; fList = 0;
107 if (fDirectory) fDirectory->Remove(
this);
116 void TEventList::Add(
const TEventList *alist)
119 Int_t an = alist->GetN();
121 Long64_t *alst = alist->GetList();
123 fList =
new Long64_t[an];
124 for (i=0;i<an;i++) fList[i] = alst[i];
129 Int_t newsize = fN + an;
130 Long64_t *newlist =
new Long64_t[newsize];
134 while (alpos < an && fList[i] > alst[alpos]) {
135 newlist[newpos] = alst[alpos];
139 if (alpos < an && fList[i] == alst[alpos]) alpos++;
140 newlist[newpos] = fList[i];
144 newlist[newpos] = alst[alpos];
153 TCut orig = GetTitle();
154 TCut added = alist->GetTitle();
155 TCut updated = orig || added;
156 SetTitle(updated.GetTitle());
162 Bool_t TEventList::Contains(Long64_t entry)
164 if (GetIndex(entry) < 0)
return kFALSE;
171 Bool_t TEventList::ContainsRange(Long64_t entrymin, Long64_t entrymax)
173 Long64_t imax = TMath::BinarySearch(fN,fList,entrymax);
176 if (fList[imax] < entrymin)
return kFALSE;
183 void TEventList::DirectoryAutoAdd(TDirectory* dir)
191 void TEventList::Enter(Long64_t entry)
194 fList =
new Long64_t[fSize];
199 if (fN>0 && entry==fList[fN-1])
return;
201 Int_t newsize = TMath::Max(2*fSize,fN+fDelta);
202 Resize(newsize-fSize);
204 if(fN==0 || entry>fList[fN-1]) {
208 Int_t pos = TMath::BinarySearch(fN, fList, entry);
209 if(pos>=0 && entry==fList[pos])
212 memmove( &(fList[pos+1]), &(fList[pos]), 8*(fN-pos));
222 Long64_t TEventList::GetEntry(Int_t index)
const
224 if (!fList)
return -1;
225 if (index < 0 || index >= fN)
return -1;
235 Int_t TEventList::GetIndex(Long64_t entry)
const
237 Long64_t nabove, nbelow, middle;
240 while(nabove-nbelow > 1) {
241 middle = (nabove+nbelow)/2;
242 if (entry == fList[middle-1])
return middle-1;
243 if (entry < fList[middle-1]) nabove = middle;
244 else nbelow = middle;
252 void TEventList::Intersect(
const TEventList *alist)
257 Long64_t *newlist =
new Long64_t[fN];
261 if (alist->GetIndex(fList[i]) >= 0) {
262 newlist[newpos] = fList[i];
270 TCut orig = GetTitle();
271 TCut removed = alist->GetTitle();
272 TCut updated = orig && removed;
273 SetTitle(updated.GetTitle());
279 Int_t TEventList::Merge(TCollection *list)
281 if (!list)
return -1;
287 while ((el = (TEventList*)next())) {
288 if (!el->InheritsFrom(TEventList::Class())) {
289 Error(
"Add",
"Attempt to add object of class: %s to a %s",el->ClassName(),this->ClassName());
293 nevents += el->GetN();
302 void TEventList::Print(Option_t *option)
const
304 printf(
"EventList:%s/%s, number of entries =%d, size=%d\n",GetName(),GetTitle(),fN,fSize);
305 if (!strstr(option,
"all"))
return;
309 char *line =
new char[100];
310 snprintf(line,100,
"%5d : ",0);
315 snprintf(line,100,
"%5d : ",i);
318 snprintf(element,10,
"%7lld ",fList[i]);
319 strlcat(line,element,100);
321 if (nbuf) printf(
"%s\n",line);
328 void TEventList::Reset(Option_t *)
336 void TEventList::Resize(Int_t delta)
338 if (!delta) delta = fDelta;
340 Long64_t *newlist =
new Long64_t[fSize];
341 for (Int_t i=0;i<fN;i++) newlist[i] = fList[i];
351 void TEventList::SetDirectory(TDirectory *dir)
353 if (fDirectory == dir)
return;
354 if (fDirectory) fDirectory->Remove(
this);
356 if (fDirectory) fDirectory->Append(
this);
362 void TEventList::SetName(
const char *name)
366 if (fDirectory) fDirectory->Remove(
this);
368 if (fDirectory) fDirectory->Append(
this);
374 void TEventList::Sort()
376 Int_t *index =
new Int_t[fN];
377 Long64_t *newlist =
new Long64_t[fSize];
379 TMath::Sort(fN,fList,index);
382 newlist[i] = fList[ind];
384 for (i=fN;i<fSize;i++) {
395 void TEventList::Streamer(TBuffer &b)
399 Version_t R__v = b.ReadVersion(&R__s, &R__c);
402 b.ReadClassBuffer(TEventList::Class(),
this, R__v, R__s, R__c);
403 ResetBit(kMustCleanup);
412 Int_t *tlist =
new Int_t[fSize];
413 b.ReadFastArray(tlist,fN);
414 fList =
new Long64_t[fSize];
415 for (Int_t i=0;i<fN;i++) fList[i] = tlist[i];
418 ResetBit(kMustCleanup);
419 b.CheckByteCount(R__s, R__c, TEventList::IsA());
423 b.WriteClassBuffer(TEventList::Class(),
this);
430 void TEventList::Subtract(
const TEventList *alist)
435 Long64_t *newlist =
new Long64_t[fN];
439 if (alist->GetIndex(fList[i]) < 0) {
440 newlist[newpos] = fList[i];
448 TCut orig = GetTitle();
449 TCut removed = alist->GetTitle();
450 TCut updated = orig && !removed;
451 SetTitle(updated.GetTitle());
457 TEventList& TEventList::operator=(
const TEventList &list)
460 TNamed::operator=(list);
461 if (fSize < list.fSize) {
463 fList =
new Long64_t[list.fSize];
467 fDelta = list.fDelta;
468 for (Int_t i=0; i<fN; i++)
469 fList[i] = list.fList[i];
477 TEventList operator+(
const TEventList &list1,
const TEventList &list2)
479 TEventList newlist = list1;
487 TEventList operator-(
const TEventList &list1,
const TEventList &list2)
489 TEventList newlist = list1;
490 newlist.Subtract(&list2);
497 TEventList operator*(
const TEventList &list1,
const TEventList &list2)
499 TEventList newlist = list1;
500 newlist.Intersect(&list2);