Changeset 19561


Ignore:
Timestamp:
07/11/19 17:15:32 (5 years ago)
Author:
(none)
Message:
Replace cast to MyClonesArray with making fData an MClonesArray
Location:
trunk/Mars/msim
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/msim/MPhotonEvent.cc

    r19355 r19561  
    101101//
    102102//
    103 //   Version 1:
     103//   Version 2:
    104104//   ----------
    105105//    - First implementation
     106//    - fData is now A MClonesArray to avoid casting issues on some compilers
    106107//
    107108/////////////////////////////////////////////////////////////////////////////
     
    127128using namespace std;
    128129
    129 // ==========================================================================
    130 
    131 class MyClonesArray : public TClonesArray
    132 {
    133 public:
    134     TObject **FirstRef() { return fCont; }
    135 
    136     // --------------------------------------------------------------------------
    137     //
    138     // This is an extremly optimized version of ExpandCreateFast. It only resets
    139     // the marker for the last element (fLast) to n-1 and doen't change anything
    140     // else. This implicitly assumes that the stored objects don't allocate
    141     // memory. It does not necessarily mean that the slots after fLast
    142     // are empty (set to 0). This is what is assumed in the TClonesArray.
    143     // We also don't call Changed() because it would reset Sorted. If the
    144     // array was sorted before it is also sorted now. You MUST make sure
    145     // that you only set n in a range for which valid entries have been
    146     // created before (e.g. by ExpandCreateFast).
    147     //
    148     void FastShrink(Int_t n)
    149     {
    150         fLast = n - 1;
    151     }
    152 
    153     // --------------------------------------------------------------------------
    154     //
    155     // This is a optimized (faster) version of Delete which deletes consequtive
    156     // entries from index idx1 to idx2 (both included) and calls their
    157     // destructor. Note that there is no range checking done!
    158     //
    159     void FastRemove(Int_t idx1, Int_t idx2)
    160     {
    161         // Remove object at index idx.
    162 
    163         //if (!BoundsOk("RemoveAt", idx1)) return 0;
    164         //if (!BoundsOk("RemoveAt", idx2)) return 0;
    165 
    166         Long_t dtoronly = TObject::GetDtorOnly();
    167 
    168         idx1 -= fLowerBound;
    169         idx2 -= fLowerBound;
    170 
    171         for (TObject **obj=fCont+idx1; obj<=fCont+idx2; obj++)
    172         {
    173             if (!*obj)
    174                 continue;
    175 
    176             if ((*obj)->TestBit(kNotDeleted)) {
    177                 // Tell custom operator delete() not to delete space when
    178                 // object fCont[i] is deleted. Only destructors are called
    179                 // for this object.
    180                 TObject::SetDtorOnly(*obj);
    181                 delete *obj;
    182             }
    183 
    184             *obj = 0;
    185             // recalculate array size
    186         }
    187         TObject::SetDtorOnly((void*)dtoronly);
    188 
    189         if (idx1<=fLast && fLast<=idx2)
    190         {
    191             do {
    192                 fLast--;
    193             } while (fLast >= 0 && fCont[fLast] == 0);
    194         }
    195 
    196         Changed();
    197     }
    198 
    199 
    200     //void SetSorted() { fSorted = kTRUE; }
    201 
    202     // --------------------------------------------------------------------------
    203     //
    204     // This is an optimized version of Sort which doesn't check the
    205     // IsSortable flag before. It only sorts the entries from 0
    206     // to GetEntriesFast().
    207     //
    208     void UncheckedSort()
    209     {
    210         if (fSorted)
    211             return;
    212 
    213         const Int_t nentries = GetEntriesFast();
    214         if (nentries <= 0)
    215             return;
    216 
    217         QSort(GetObjectRef(First()), fKeep->GetObjectRef(fKeep->First()),
    218               0, TMath::Min(nentries, kMaxInt-fLowerBound));
    219 
    220         fSorted = kTRUE;
    221     }
    222 };
    223 
    224 // ==========================================================================
    225130
    226131// --------------------------------------------------------------------------
     
    274179
    275180    // Just set fLast = n -1
    276     static_cast<MyClonesArray&>(fData).FastShrink(n);
     181    fData.FastShrink(n);
    277182    return fData.GetEntriesFast();
    278183}
     
    370275    {
    371276        o=fData.UncheckedAt(n);
    372         static_cast<MyClonesArray&>(fData).FastShrink(n+1);
     277        fData.FastShrink(n+1);
    373278    }
    374279    else
     
    396301        fData.UnSort();
    397302
    398     static_cast<MyClonesArray&>(fData).UncheckedSort(); /*Sort(GetEntriesFast())*/
     303    fData.UncheckedSort();
     304    // fData.Sort(fData.GetEntriesFast());
    399305}
    400306
  • trunk/Mars/msim/MPhotonEvent.h

    r19338 r19561  
    1111
    1212#include <iosfwd>
     13#include "MClonesArray.h"
    1314
    1415using namespace std;
     
    2122{
    2223private:
    23     TClonesArray fData;
     24    MClonesArray fData;
    2425
    2526public:
     
    4142    Double_t GetMeanT() const;
    4243
    43     TClonesArray &GetArray() { return fData; }
    44     const TClonesArray &GetArray() const { return fData; }
     44    MClonesArray &GetArray() { return fData; }
     45    const MClonesArray &GetArray() const { return fData; }
    4546
    4647    Bool_t AsciiWrite(ostream &out) const;
     
    7172    //void Clear(Option_t * = NULL);
    7273
    73     ClassDef(MPhotonEvent, 1) //Container to store the raw Event Data
     74    ClassDef(MPhotonEvent, 2) //Container to store the raw Event Data
    7475};
    7576
  • trunk/Mars/msim/Makefile

    r9518 r19561  
    2828           MSimAtmosphere.cc \
    2929           MSimAbsorption.cc \
    30            MSimPointingPos.cc
     30           MSimPointingPos.cc \
     31           MClonesArray.cc
    3132
    3233############################################################
  • trunk/Mars/msim/SimLinkDef.h

    r9351 r19561  
    1818#pragma link C++ class MSimMMCS+;
    1919
     20#pragma link C++ class MClonesArray-; // - needed as custom streamer is already implemented
     21
    2022#endif
Note: See TracChangeset for help on using the changeset viewer.