Added a new base class for common objects
authorpulvir <pulvir@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 18 Nov 2010 18:11:27 +0000 (18:11 +0000)
committerpulvir <pulvir@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 18 Nov 2010 18:11:27 +0000 (18:11 +0000)
PWG2/RESONANCES/AliRsnTarget.cxx [new file with mode: 0644]
PWG2/RESONANCES/AliRsnTarget.h [new file with mode: 0644]

diff --git a/PWG2/RESONANCES/AliRsnTarget.cxx b/PWG2/RESONANCES/AliRsnTarget.cxx
new file mode 100644 (file)
index 0000000..978a1b7
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// *** Class AliRsnTarget ***
+//
+// Base class used wherever it is needed to check the class type of 
+// an object (daughter, mother, event) which could be used for 
+// cut checking or value computing.
+// Since most of these operation are implemented into classes that 
+// operate on any of such objects, then this class helps in making sure
+// that the object being processed corresponds to what is expected.
+//
+
+#include "AliRsnEvent.h"
+#include "AliRsnDaughter.h"
+#include "AliRsnMother.h"
+
+#include "AliRsnTarget.h"
+
+ClassImp(AliRsnTarget)
+
+//_____________________________________________________________________________
+Bool_t AliRsnTarget::TargetOK(TObject *object)
+{
+//
+// This method compares the target type stored as data member
+// with the type of the object passed as argument, and returns
+// kTRUE or kFALSE depending if they match or not.
+//
+
+  // fails by default if a NULL pointer is passed
+  if (!object)
+  {
+    AliError("Object is NULL");
+    return kFALSE;
+  }
+
+  // checks if the object is correct by dynamic casting
+  switch (fTargetType)
+  {
+    case kDaughter:
+      if (dynamic_cast<AliRsnDaughter*>(object) == 0x0)
+      {
+        AliError(Form("[%s] Target mismatch: expected 'AliRsnDaughter', passed '%s'", GetName(), object->ClassName()));
+        Print();
+        return kFALSE;
+      }
+      break;
+    case kMother:
+      if (dynamic_cast<AliRsnMother*>(object) == 0x0)
+      {
+        AliError(Form("[%s] Target mismatch: expected 'AliRsnMother', passed '%s'", GetName(), object->ClassName()));
+        Print();
+        return kFALSE;
+      }
+      break;
+    case kEvent:
+      if (dynamic_cast<AliRsnEvent*>(object) == 0x0)
+      {
+        AliError(Form("[%s] Target mismatch: expected 'AliRsnEvent', passed '%s'", GetName(), object->ClassName()));
+        Print();
+        return kFALSE;
+      }
+      break;
+    default:
+      return kTRUE;
+  }
+  
+  return kTRUE;
+}
+
+//______________________________________________________________________________
+Char_t AliRsnTarget::GetTargetTypeChar() const
+{
+//
+// Returns a single character identifying the cut target type.
+//
+
+  switch (fTargetType) 
+  {
+    case kDaughter: return 'D';
+    case kMother: return 'M';
+    case kEvent: return 'E';
+    default: return 'X';
+  }
+}
+
+//______________________________________________________________________________
+const char* AliRsnTarget::GetTargetTypeName() const
+{
+//
+// Returns a string with the name of the cut target type-
+//
+
+  switch (fTargetType) 
+  {
+    case kDaughter: return "Daughter";
+    case kMother: return "Mother";
+    case kEvent: return "Event";
+    default: return "Undefined";
+  }
+}
diff --git a/PWG2/RESONANCES/AliRsnTarget.h b/PWG2/RESONANCES/AliRsnTarget.h
new file mode 100644 (file)
index 0000000..1936d9d
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// *** Class AliRsnTarget ***
+//
+// Base class used wherever it is needed to check the class type of 
+// an object (daughter, mother, event) which could be used for 
+// cut checking or value computing.
+// Since most of these operation are implemented into classes that 
+// operate on any of such objects, then this class helps in making sure
+// that the object being processed corresponds to what is expected.
+//
+
+#ifndef ALIRSNTARGET_H
+#define ALIRSNTARGET_H
+
+#include "TNamed.h"
+
+class AliRsnTarget : public TNamed
+{
+  public:
+  
+    enum ETargetType
+    {
+      kDaughter,
+      kMother,
+      kEvent,
+      kTargetTypes
+    };
+
+    AliRsnTarget() : fTargetType(kTargetTypes) { /*nothing*/ }
+    AliRsnTarget(const char *name, ETargetType type) : TNamed(name, ""), fTargetType(type) { /*nothing*/ }
+    AliRsnTarget(const AliRsnTarget& copy) : TNamed(copy), fTargetType(copy.fTargetType) { /*nothing*/ }
+    AliRsnTarget& operator=(const AliRsnTarget& copy) { TNamed::operator=(copy); fTargetType = copy.fTargetType; return (*this); }
+    virtual ~AliRsnTarget() { /*nothing*/ }
+    
+    Bool_t         IsTarget(ETargetType targetType)  {return (fTargetType == targetType);}
+    ETargetType    GetTargetType() const             {return fTargetType;}
+    Char_t         GetTargetTypeChar() const;
+    const char*    GetTargetTypeName() const;
+    void           SetTargetType(ETargetType type)   {fTargetType = type;}
+    Bool_t         TargetOK(TObject *object);
+
+  protected:
+  
+    ETargetType fTargetType;  // target type selected for this object
+    
+    // ROOT dictionary
+    ClassDef(AliRsnTarget, 1)
+};
+
+typedef AliRsnTarget::ETargetType RSNTARGET;
+
+#endif