Ignore:
Timestamp:
01/14/09 12:31:37 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MMath.cc

    r9195 r9219  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.42 2008-12-21 18:09:49 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.43 2009-01-14 12:31:36 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    324324Double_t MMath::MedianDev(Long64_t n, const Long64_t *a) { Double_t med; return MedianDevImp(n, a, med); }
    325325
     326// ------------------------------------------------------------------------
     327//
     328// Re-sort an array. Intsead of returning an index (like TMath::Sort)
     329// the array contents are sorted.
     330//
     331template <class Size, class Element> void MMath::ReSortImp(Size n, Element *a, Bool_t down)
     332{
     333    Element *cpy = new Element[n];
     334    Int_t   *pos = new Int_t[n];
     335
     336    memcpy(cpy, a, n*sizeof(Element));
     337
     338    TMath::Sort(n, a, pos, down);
     339
     340    Int_t *idx = pos;
     341
     342    for (Element *ptr=a; ptr<a+n; ptr++)
     343        *ptr = cpy[*idx++];
     344
     345    delete cpy;
     346    delete pos;
     347}
     348
     349void MMath::ReSort(Long64_t n, Short_t  *a, Bool_t down) { ReSortImp(n, a, down); }
     350void MMath::ReSort(Long64_t n, Int_t    *a, Bool_t down) { ReSortImp(n, a, down); }
     351void MMath::ReSort(Long64_t n, Float_t  *a, Bool_t down) { ReSortImp(n, a, down); }
     352void MMath::ReSort(Long64_t n, Double_t *a, Bool_t down) { ReSortImp(n, a, down); }
     353
    326354// --------------------------------------------------------------------------
    327355//
  • trunk/MagicSoft/Mars/mbase/MMath.h

    r8989 r9219  
    1717{
    1818    Double_t GaussProb(Double_t x, Double_t sigma=1, Double_t mean=0);
     19
     20    template <class Size, class Element> void ReSortImp(Size n, Element *a, Bool_t down=kFALSE);
     21    void ReSort(Long64_t n, Short_t  *a, Bool_t down=kFALSE);
     22    void ReSort(Long64_t n, Int_t    *a, Bool_t down=kFALSE);
     23    void ReSort(Long64_t n, Float_t  *a, Bool_t down=kFALSE);
     24    void ReSort(Long64_t n, Double_t *a, Bool_t down=kFALSE);
    1925
    2026    template <class Size, class Element> Double_t MedianDevImp(Size n, const Element *a) { Double_t med; return MedianDevImp(n, a, med); }
Note: See TracChangeset for help on using the changeset viewer.