ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/TriggerName.h
(Generate patch)

Comparing UserCode/MitAna/DataTree/interface/TriggerName.h (file contents):
Revision 1.3 by loizides, Tue Dec 2 09:30:11 2008 UTC vs.
Revision 1.7 by loizides, Wed Dec 2 23:18:26 2009 UTC

# Line 14 | Line 14
14   #include <string>
15   #include <TObject.h>
16   #include <TString.h>
17 #include <THashTable.h>
17   #include "MitAna/DataTree/interface/DataBase.h"
18  
19   namespace mithep
# Line 22 | Line 21 | namespace mithep
21    class TriggerName : public DataBase
22    {
23      public:
24 <      TriggerName() : fId(0) {}
24 >      TriggerName() : fId(0), fHash(0) {}
25        TriggerName(const char *name, UShort_t id) :
26          fName(name), fId(id), fHash(fName.Hash()) {}
27        TriggerName(const std::string &name, UShort_t id) :
28          fName(name), fId(id), fHash(fName.Hash()) {}
29        TriggerName(const TString &name, UShort_t id) :
30          fName(name), fId(id), fHash(fName.Hash()) {}
32      ~TriggerName() {}
31  
32 <      UShort_t              Id()      const { return fId; }
33 <      const char           *GetName() const { return fName; }
34 <      ULong_t               Hash()    const { return fHash; }
35 <      const char           *Name()    const { return fName; }
32 >      Int_t                     Compare(const TObject *o) const;  
33 >      UShort_t              Id()         const { return fId;   }
34 >      Bool_t                IsSortable() const { return kTRUE; }
35 >      const char           *GetName()    const { return fName; }
36 >      ULong_t               Hash()       const { return fHash; }
37 >      const char           *Name()       const { return fName; }
38 >      EObjType              ObjType()    const { return kTriggerName; }      
39        void                  Print(Option_t *opt="") const;
40  
41      protected:
# Line 42 | Line 43 | namespace mithep
43        UShort_t              fId;          //id
44        UInt_t                fHash;        //hash
45  
46 <    ClassDef(TriggerName, 2) // Trigger name class
46 <  };
47 <
48 < //--------------------------------------------------------------------------------------------------
49 < // TriggerTable
50 < //
51 < // A convenient THashTable for storage of TriggerNames (not streamable).
52 < //
53 < // Authors: C.Loizides
54 < //--------------------------------------------------------------------------------------------------
55 <  class TriggerTable : public THashTable
56 <  {
57 <    public:
58 <      TriggerTable(Int_t capacity = TCollection::kInitHashTableCapacity, Int_t rehash = 0) :
59 <        THashTable(capacity,rehash) {}
60 <      ~TriggerTable() {}
61 <
62 <      const TriggerName *Get(const char *name)   const;
63 <      UShort_t           GetId(const char *name) const;
64 <      using TCollection::Print;
65 <      void               Print(Option_t *opt="") const;
46 >    ClassDef(TriggerName, 1) // Trigger name class
47    };
48   }
49  
50   //--------------------------------------------------------------------------------------------------
51 < inline const mithep::TriggerName *mithep::TriggerTable::Get(const char *name) const
71 < {
72 <  // Return TriggerName pointer for given name.
73 <
74 <  return dynamic_cast<const TriggerName *>(FindObject(name));
75 < }
76 <
77 < //--------------------------------------------------------------------------------------------------
78 < inline UShort_t mithep::TriggerTable::GetId(const char *name) const
51 > inline Int_t mithep::TriggerName::Compare(const TObject *o) const
52   {
53 <  // Return trigger id of trigger with given name.
54 <
55 <  const mithep::TriggerName *tn = Get(name);
56 <  if (tn)
57 <    return tn->Id();
58 <  
59 <  Error("GetId", "TriggerName for %s not found. Returning 65535.", name);
60 <  return 65535;
53 >  // Default compare function for sorting according to transverse momentum.
54 >  // Returns -1 if this object is smaller than given object, 0 if objects are
55 >  // equal and 1 if this is larger than given object.
56 >
57 >  const mithep::TriggerName *t = dynamic_cast<const mithep::TriggerName *>(o);
58 >  if (!t)
59 >    return 1;
60 >
61 >  Double_t myid = Id();
62 >  Double_t id   = t->Id();
63 >  if (myid<id)
64 >    return -1;
65 >  else if (id<myid)
66 >    return +1;
67 >  return 0;
68   }
89
69   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines