CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Fireworks/Core/src/FWTEventList.cc

Go to the documentation of this file.
00001 #include "TMath.h"
00002 #include "TCut.h"
00003 
00004 #include "Fireworks/Core/interface/FWTEventList.h"
00005 
00006 //______________________________________________________________________________
00007 void FWTEventList::Add(const TEventList *alist)
00008 {
00009    // Merge contents of alist with this list.
00010    //
00011    // Both alist and this list are assumed to be sorted prior to this call
00012 
00013    Int_t i;
00014    Int_t an = alist->GetN();
00015    if (!an) return;
00016    Long64_t *alst = alist->GetList();
00017    if (!fList) {
00018       fList = new Long64_t[an];
00019       for (i=0;i<an;i++) fList[i] = alst[i];
00020       fN = an;
00021       fSize = an;
00022       return;
00023    }
00024    Int_t newsize = fN + an;
00025    Long64_t *newlist = new Long64_t[newsize];
00026    Int_t newpos, alpos;
00027    newpos = alpos = 0;
00028    for (i=0;i<fN;i++) {
00029       while (alpos < an && fList[i] > alst[alpos]) {
00030          newlist[newpos] = alst[alpos];
00031          newpos++;
00032          alpos++;
00033       }
00034       if (alpos < an && fList[i] == alst[alpos]) alpos++;
00035       newlist[newpos] = fList[i];
00036       newpos++;
00037    }
00038    while (alpos < an) {
00039       newlist[newpos] = alst[alpos];
00040       newpos++;
00041       alpos++;
00042    }
00043    delete [] fList;
00044    fN    = newpos;
00045    fSize = newsize;
00046    fList = newlist;
00047 
00048    TCut orig = GetTitle();
00049    TCut added = alist->GetTitle();
00050    TCut updated = orig || added;
00051    SetTitle(updated.GetTitle());
00052 }
00053 
00054 //______________________________________________________________________________
00055 void FWTEventList::Enter(Long64_t entry)
00056 {
00057    // Enter element entry into the list.
00058 
00059    if (!fList) {
00060       fList = new Long64_t[fSize];
00061       fList[0] = entry;
00062       fN = 1;
00063       return;
00064    }
00065    if (fN>0 && entry==fList[fN-1]) return;
00066    if (fN >= fSize) {
00067       Int_t newsize = TMath::Max(2*fSize,fN+fDelta);
00068       Resize(newsize-fSize);
00069    }
00070    if(fN==0 || entry>fList[fN-1]) {
00071       fList[fN] = entry;
00072       ++fN;
00073    } else {
00074       Int_t pos = TMath::BinarySearch(fN, fList, entry);
00075       if(pos>=0 && entry==fList[pos])
00076          return;
00077       ++pos;
00078       memmove( &(fList[pos+1]), &(fList[pos]), 8*(fN-pos));
00079       fList[pos] = entry;
00080       ++fN;
00081    }
00082 }