Changeset 17765 for trunk/Mars/mbase


Ignore:
Timestamp:
05/02/14 16:19:33 (10 years ago)
Author:
tbretz
Message:
If one function takes a pointer the other one should as well, offsets and sizes can by definition not be negtaive, so do not allow negative values -- the compiler warning could have told you already; simplified the logic.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mbase/MArrayF.h

    r17682 r17765  
    170170
    171171    template<class T>
    172     void Add(T *src, Int_t n, Int_t p=0, Float_t m=1.)
    173     {
    174         // under these 3 conditions, we return immediately, because they either make no sense,
    175         // or result in an invariant array.
    176         if (p >= fN)
    177         {
    178             // maybe throw a warning, because p >= fN makes no sense at all
    179             return;
    180         }
    181         if ( n <= 0)
    182         {
    183             return;
    184         }
    185         if (m == 0.)
    186         {
    187             return;
    188         }
    189         if (src == NULL)
    190         {
    191             return;
    192         }
    193 
    194         Float_t *dest = fArray + p;
    195         Float_t *end  = dest;
    196         if (n < fN-p)
    197         {
    198             end += n;
    199         }
    200         else
    201         {
    202             end += fN-p;
    203         }
     172        void Add(const T *src, UInt_t n, UInt_t beg=0, Float_t scale=1)
     173    {
     174        if (!src || beg >= fN)
     175            return;
     176
     177        Float_t *ptr = fArray+beg;
     178        const Float_t *end  = beg+n>fN ? fArray+fN : ptr+n;
    204179
    205180        // we treat the case m==1. special, in order to speed up the code a bit
    206181        // since when m==1. the multiplication can be omitted and this should be a bit faster then.
    207         if (m == 1.)
    208         {
    209             while (dest<end)
    210                 *dest++ += *src++;
     182        if (scale==1)
     183        {
     184            while (ptr<end)
     185                *ptr++ += *src++;
    211186        }
    212187        else
    213188        {
    214             while (dest<end)
    215                 *dest++ += (*src++) * m;
     189            while (ptr<end)
     190                *ptr++ += (*src++) * m;
    216191        }
    217192    }
    218193
    219194    template<class T>
    220         void AddClipped(Double_t th, T src, Int_t n, Int_t p=0)
    221     {
    222         Float_t *dest = fArray + p;
    223         Float_t *end  = dest   + n;
    224 
    225         while (dest<end)
    226             *dest++ += TMath::Min(*src++, th);
     195        void AddClipped(Double_t th, const T *src, UInt_t n, UInt_t beg=0)
     196    {
     197        if (!src || beg>=fN)
     198            return;
     199
     200        Float_t *ptr = fArray + beg;
     201        const Float_t *end  = beg+n>fN ? fArray+fN : ptr+n;
     202
     203        while (ptr<end)
     204            *ptr++ += TMath::Min(*src++, th);
    227205    }
    228206
Note: See TracChangeset for help on using the changeset viewer.