StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMultyKeyMap.h
1 #ifndef MULTYKEYMAP_H
2 #define MULTYKEYMAP_H
3 #include <vector>
4 #include <list>
6 class StMultyKeyNode;
7 class StMultyKeyMap;
8 
10 {
11 public:
12 typedef std::vector<float> FKeys_t;
13 typedef std::vector<StMultyKeyNode*> Links_t;
14 friend class StMultyKeyMap;
15 friend class StMultyKeyMapIter;
16 
17 StMultyKeyNode():mMap(0),mId(0){;}
18 virtual ~StMultyKeyNode(){;}
19 virtual const char * ClassName() const {return "StMultyKeyNode";}
20 virtual void Set(const void *obj,const float *keys){assert(0);}
21 virtual void Add(StMultyKeyNode *pair){assert(0);}
22 
23 virtual const float *GetKeys() const { return 0;}
24 virtual int GetIKey() const { assert(0);return 0;}
25 virtual void SetIKey(int ik) { assert(0) ;}
26 virtual void *GetObj () const { return 0;}
27 virtual const float *GetDow() const { assert(0);return 0;}
28 virtual const float *GetStp() const { assert(0);return 0;}
29  int MaxDeep(int *deep=0) const;
30  int GetNumb() const;
31  double Quality(int *numb=0) const;
32 virtual int ls(const char* ="" ) const;
33 virtual void Clear(const char* =0) { assert(0) ;}
34 // Non user functions
35 virtual StMultyKeyNode* Link(int jlink) const { return 0 ;}
36  StMultyKeyMap *GetMap() const { return mMap;}
37 void SetMap(StMultyKeyMap *map) { mMap = map ;}
38 int GetNKey() const;
39 int GetNBin() const;
40 private:
41 public:
42 StMultyKeyMap *mMap;
43 int mId;
44 };
45 
46 
48 {
49 friend class StMultyKeyMap;
50 friend class StMultyKeyMapIter;
51 public:
53 virtual ~StMultyKeyDivd();
54 const char *ClassName() const {return "StMultyKeyDivd";}
55 void Add(StMultyKeyNode *pair);
56 
57 int GetIKey() const { return mIKey ;}
58 void SetIKey(int ikey) { mIKey = ikey ;}
59 const float *GetDow() const { return &mDow[0];}
60 const float *GetStp() const { return &mStp[0];}
61 
62 void Clear(const char* opt=0);
63 // Non user functions
64 StMultyKeyNode *Link(int jlink) const {return mLink[jlink];}
65 protected:
66 int mIKey; //key index used on this level
67 Links_t mLink; //subtree pointers
68 FKeys_t mDow;
69 FKeys_t mStp;
70 };
71 
73 {
74 friend class StMultyKeyMap;
75 friend class StMultyKeyMapIter;
76 public:
78 virtual ~StMultyKeyPair(){;}
79 const char *ClassName() const {return "StMultyKeyPair";}
80 virtual void Set(const void *obj,const float *keys);
81 
82  const float *GetKeys() const { return &mKeys[0];}
83  void *GetObj () const { return (void*)mObj ;}
84  void Clear(const char* opt=0);
85 // Non user functionsprivate:
86 protected:
87 const void *mObj; //Some user object mapped to keys
88 FKeys_t mKeys; //keys for this object
89 };
90 
92 {
93 friend class StMultyKeyMapIter;
94 friend class StMultyKeyDivd;
95 friend class StMultyKeyPair;
96 public:
97 StMultyKeyMap(int nKeys,int nBins=10);
98 ~StMultyKeyMap();
99 void Clear(const char *opt="");
100 void Add(StMultyKeyNode* pair) {StMultyKeyDivd::Add(pair);}
101 void Add(const void *obj,const float *keys);
102 void Add(const void *obj,const double *keys);
103 const StMultyKeyNode *GetTop() const {return this;}
104  StMultyKeyNode *GetTop() {return this;}
105  int MakeTree(int keepArray=0);
106  int Size() const {return mSize;}
107  int GetNKey() const {return mNKey;}
108  int GetNBin() const {return mNBin;}
109  int GetJKey();
110 StMultyKeyNode** GetArr() {return &mArr[0];}
111 StMultyKeyPair *MakePair();
112 StMultyKeyDivd *MakeNode();
113 // statics
114 static void Test();
115 static void Test2();
116 
117 protected:
118 int mNKey;
119 int mNBin;
120 int mSize;
121 unsigned int mJKey;
122 std::vector<StMultyKeyNode*> mArr;
123 std::list<StMultyKeyPair*> mPairs;
124 std::list<StMultyKeyDivd*> mNodes;
125 };
126 
127 
129 {
130 public:
131 class myStk_t {public:const StMultyKeyNode *node; int ibin;int rite;};
132 
133  StMultyKeyMapIter(const StMultyKeyNode *node,const float *kMin=0,const float *kMax=0);
134  void Set(const StMultyKeyNode *node,const float *kMin=0,const float *kMax=0);
135  void Update(const float *kMin=0,const float *kMax=0);
136  void Reset();
137  int InitLev();
138 
140  StMultyKeyNode *operator*() const { return (StMultyKeyNode*)mStk[mLev].node;}
141  StMultyKeyMapIter &operator++();
142  int Level() const {return mLev;}
143  const StMultyKeyMapIter::myStk_t &GetStk(int lev=-1) const {return (lev<0)? mStk[mLev]:mStk[lev];}
144  float *GetKMin() const {return mKMin;}
145  float *GetKMax() const {return mKMax;}
146  const int *Touched() const {return mTouched;}
147  private:
148  int FullCheck();
149  protected:
150  mutable int mTouched[3];
151  std::vector<float> mMinMax;
152  float *mKMin;
153  float *mKMax;
154  int mNK;
155  int mNB;
156  int mLev;
157  const StMultyKeyNode* mTop;
158  std::vector<myStk_t> mStk;
159 };
160 
161 
162 inline int StMultyKeyNode::GetNKey() const { return mMap->GetNKey();}
163 inline int StMultyKeyNode::GetNBin() const { return mMap->GetNBin();}
164 #endif //MULTYKEYBINTREE_H