Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:19

0001 #include "TMath.h"
0002 #include "TCut.h"
0003 
0004 #include "Fireworks/Core/interface/FWTEventList.h"
0005 
0006 //______________________________________________________________________________
0007 void FWTEventList::Add(const TEventList *alist) {
0008   // Merge contents of alist with this list.
0009   //
0010   // Both alist and this list are assumed to be sorted prior to this call
0011 
0012   Int_t i;
0013   Int_t an = alist->GetN();
0014   if (!an)
0015     return;
0016   Long64_t *alst = alist->GetList();
0017   if (!fList) {
0018     fList = new Long64_t[an];
0019     for (i = 0; i < an; i++)
0020       fList[i] = alst[i];
0021     fN = an;
0022     fSize = an;
0023     return;
0024   }
0025   Int_t newsize = fN + an;
0026   Long64_t *newlist = new Long64_t[newsize];
0027   Int_t newpos, alpos;
0028   newpos = alpos = 0;
0029   for (i = 0; i < fN; i++) {
0030     while (alpos < an && fList[i] > alst[alpos]) {
0031       newlist[newpos] = alst[alpos];
0032       newpos++;
0033       alpos++;
0034     }
0035     if (alpos < an && fList[i] == alst[alpos])
0036       alpos++;
0037     newlist[newpos] = fList[i];
0038     newpos++;
0039   }
0040   while (alpos < an) {
0041     newlist[newpos] = alst[alpos];
0042     newpos++;
0043     alpos++;
0044   }
0045   delete[] fList;
0046   fN = newpos;
0047   fSize = newsize;
0048   fList = newlist;
0049 
0050   TCut orig = GetTitle();
0051   TCut added = alist->GetTitle();
0052   TCut updated = orig || added;
0053   SetTitle(updated.GetTitle());
0054 }
0055 
0056 //______________________________________________________________________________
0057 void FWTEventList::Enter(Long64_t entry) {
0058   // Enter element entry into the list.
0059 
0060   if (!fList) {
0061     fList = new Long64_t[fSize];
0062     fList[0] = entry;
0063     fN = 1;
0064     return;
0065   }
0066   if (fN > 0 && entry == fList[fN - 1])
0067     return;
0068   if (fN >= fSize) {
0069     Int_t newsize = TMath::Max(2 * fSize, fN + fDelta);
0070     Resize(newsize - fSize);
0071   }
0072   if (fN == 0 || entry > fList[fN - 1]) {
0073     fList[fN] = entry;
0074     ++fN;
0075   } else {
0076     Int_t pos = TMath::BinarySearch(fN, fList, entry);
0077     if (pos >= 0 && entry == fList[pos])
0078       return;
0079     ++pos;
0080     memmove(&(fList[pos + 1]), &(fList[pos]), 8 * (fN - pos));
0081     fList[pos] = entry;
0082     ++fN;
0083   }
0084 }