1 | #ifndef COSY_MStarList
|
---|
2 | #define COSY_MStarList
|
---|
3 |
|
---|
4 | #include <TClonesArray.h>
|
---|
5 |
|
---|
6 | #include "MStar.h"
|
---|
7 |
|
---|
8 | class MStarListIter;
|
---|
9 |
|
---|
10 | class MStarList : public TObject
|
---|
11 | {
|
---|
12 | private:
|
---|
13 | TClonesArray fStars;
|
---|
14 |
|
---|
15 | public:
|
---|
16 | MStarList() : fStars("MStar", 1000) {}
|
---|
17 |
|
---|
18 | void AddAt(Int_t idx, Double_t meanx, Double_t meany, Double_t mag)
|
---|
19 | {
|
---|
20 | new (fStars[idx]) MStar(meanx, meany, mag);
|
---|
21 | }
|
---|
22 | void Add(Double_t meanx, Double_t meany, Double_t mag)
|
---|
23 | {
|
---|
24 | AddAt(fStars.GetLast()+1, meanx, meany, mag);
|
---|
25 | }
|
---|
26 | MStar *operator[](Int_t i) { return (MStar*)fStars[i]; }
|
---|
27 |
|
---|
28 | void Reset()
|
---|
29 | {
|
---|
30 | fStars.Delete();
|
---|
31 | }
|
---|
32 |
|
---|
33 | void Delete(Int_t i) { delete fStars.RemoveAt(i); }
|
---|
34 | void Delete(MStar *obj) { delete fStars.Remove(obj); }
|
---|
35 |
|
---|
36 | Int_t GetMax() const { return fStars.GetLast()+1; }
|
---|
37 | Int_t GetRealEntries() const { return fStars.GetEntries(); }
|
---|
38 |
|
---|
39 | void RemoveTwins(Double_t radius);
|
---|
40 | };
|
---|
41 |
|
---|
42 | class MStarListIter
|
---|
43 | {
|
---|
44 | private:
|
---|
45 | MStarList *fList;
|
---|
46 |
|
---|
47 | Int_t fNumPos; // actual position in list
|
---|
48 |
|
---|
49 | Bool_t fAll; // iterate over all stars
|
---|
50 |
|
---|
51 | MStar fReference; // iterate only over stars not more than
|
---|
52 | Float_t fRadius; // fRadius away from the reference
|
---|
53 |
|
---|
54 | public:
|
---|
55 | MStarListIter(MStarList *list) : fList(list), fNumPos(0), fAll(kTRUE) {}
|
---|
56 | MStarListIter(MStarList *list, const MStar &s, Float_t r) : fList(list), fNumPos(0), fAll(kFALSE), fReference(s), fRadius(r) {}
|
---|
57 |
|
---|
58 | MStar *Next()
|
---|
59 | {
|
---|
60 | const Double_t r2 = fRadius*fRadius;
|
---|
61 |
|
---|
62 | for (int i=fNumPos; i<fList->GetMax(); i++)
|
---|
63 | {
|
---|
64 | MStar *p = (*fList)[i];
|
---|
65 |
|
---|
66 | if (!p)
|
---|
67 | continue;
|
---|
68 |
|
---|
69 | if (!fAll)
|
---|
70 | {
|
---|
71 | Double_t dx = p->GetX()-fReference.GetX();
|
---|
72 | Double_t dy = p->GetY()-fReference.GetY();
|
---|
73 |
|
---|
74 | if (dx*dx + dy*dy > r2)
|
---|
75 | continue;
|
---|
76 | }
|
---|
77 |
|
---|
78 | fNumPos = i+1;
|
---|
79 | return p;
|
---|
80 | }
|
---|
81 | return NULL;
|
---|
82 | }
|
---|
83 |
|
---|
84 | MStar *operator()() { return Next(); }
|
---|
85 |
|
---|
86 | void Reset() { fNumPos=0; }
|
---|
87 | };
|
---|
88 |
|
---|
89 | #endif
|
---|