]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Adding implementations of copy contructor, assignment operator and Copy methods to...
authoraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 6 Oct 2008 09:48:01 +0000 (09:48 +0000)
committeraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 6 Oct 2008 09:48:01 +0000 (09:48 +0000)
HLT/MUON/AliHLTMUONEvent.cxx
HLT/MUON/AliHLTMUONEvent.h

index a614455196583b7a3e237efb6bb3ed2a8b6e9ed6..78003785763ecf7ac5a86ad55dd87b73b10db2c5 100644 (file)
 
 #include "AliHLTMUONEvent.h"
 #include "AliHLTMUONDecision.h"
+#include "AliLog.h"
 #include <iostream>
 
 ClassImp(AliHLTMUONEvent);
 
 
+AliHLTMUONEvent::AliHLTMUONEvent(const AliHLTMUONEvent& event) :
+       TObject(),
+       fEventId(event.fEventId),
+       fArray()
+{
+       /// Copy constructor performs a deep copy of the object.
+       
+       fEventId = event.fEventId;
+       fArray.SetOwner(kTRUE);
+       TIter next(&event.fArray);
+       TObject* obj = NULL;
+       while ( (obj = next()) != NULL )
+       {
+               fArray.Add(obj->Clone());
+       }
+}
+
+
+AliHLTMUONEvent& AliHLTMUONEvent::operator = (const AliHLTMUONEvent& event)
+{
+       /// The assignment operator performs a deep copy of the object.
+       
+       TObject::operator = (event);
+       fEventId = event.fEventId;
+       fArray.Clear();
+       TIter next(&event.fArray);
+       TObject* obj = NULL;
+       while ( (obj = next()) != NULL )
+       {
+               fArray.Add(obj->Clone());
+       }
+       return *this;
+}
+
+
 const AliHLTMUONDecision* AliHLTMUONEvent::FindDecision() const
 {
        /// Finds the decision object in the event from the list of dHLT objects.
@@ -64,3 +100,39 @@ void AliHLTMUONEvent::Print(Option_t* option) const
        for (Int_t i = 0; i < fArray.GetEntriesFast(); i++)
                if (fArray[i] != NULL) fArray[i]->Print(option);
 }
+
+
+void AliHLTMUONEvent::Clear(Option_t* option)
+{
+       /// Clears the internal array of event objects.
+       
+       fEventId = AliHLTEventID_t(-1);
+       fArray.Clear(option);
+}
+
+
+void AliHLTMUONEvent::Copy(TObject& object) const
+{
+       /// Deep copy this object to the target object.
+       /// \param object  The target object to copy to.
+       
+       if (object.IsA() != this->IsA())
+       {
+               AliError(Form("Cannot copy an object of type %s to a type of %s.",
+                       this->ClassName(), object.ClassName()
+               ));
+               return;
+       }
+       
+       TObject::Copy(object);
+       AliHLTMUONEvent& event = static_cast<AliHLTMUONEvent&>(object);
+       event.fEventId = fEventId;
+       event.fArray.Clear();
+       TIter next(&fArray);
+       TObject* obj = NULL;
+       while ( (obj = next()) != NULL )
+       {
+               event.fArray.Add(obj->Clone());
+       }
+}
+
index 04502551470b40c1b25b35a81b17263b0773dbf0..544f6c6fd3eb493c8095d4ebdb8b6f7016987249 100644 (file)
@@ -31,6 +31,12 @@ public:
                fArray.SetOwner(kTRUE);
        }
        
+       /// Copy constructor performs a deep copy of the object.
+       AliHLTMUONEvent(const AliHLTMUONEvent& event);
+       
+       /// The assignment operator performs a deep copy of the object.
+       AliHLTMUONEvent& operator = (const AliHLTMUONEvent& event);
+       
        /// Default destructor.
        virtual ~AliHLTMUONEvent() {}
        
@@ -75,6 +81,12 @@ public:
        
        /// Inherited method for printing information about all objects in the event.
        virtual void Print(Option_t* option = NULL) const;
+       
+       /// Inherited method for clearing the event.
+       virtual void Clear(Option_t* option = "");
+       
+       /// Inherited method for deep copying the event.
+       virtual void Copy(TObject& object) const;
 
 private: