Do not assume operator==/!=() is a member function.
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveHOMERSourceMap.h
CommitLineData
a15e6d7d 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
9
10#ifndef AliEveAliEveHOMERSourceMap_H
11#define AliEveAliEveHOMERSourceMap_H
12
13#include "AliEveHOMERSource.h"
14
15#include <TNamed.h>
16
17#include <map>
18
19class AliEveHOMERSourceMap : public TNamed
20{
21protected:
22 struct iterator_imp_base
23 {
24 virtual ~iterator_imp_base() {}
25
25c3aaf7 26 virtual const AliEveHOMERSource::SourceId& id() const = 0;
27 virtual const AliEveHOMERSource::SourceState& state() const = 0;
a15e6d7d 28 virtual AliEveHOMERSource::SourceState& state() = 0;
29
25c3aaf7 30 virtual iterator_imp_base* clone() const = 0;
a15e6d7d 31
32 virtual iterator_imp_base& operator++() = 0;
25c3aaf7 33 virtual bool operator!=(const iterator_imp_base& o) const = 0;
a15e6d7d 34
25c3aaf7 35 virtual TString description() const = 0;
a15e6d7d 36 };
37
38public:
39 struct iterator
40 {
41 iterator_imp_base* m_imp;
42
43 iterator() : m_imp(0) {}
c61a7285 44 iterator(const iterator& it) : m_imp(it.m_imp->clone()) {}
a15e6d7d 45 iterator(iterator_imp_base* imp) : m_imp(imp) {}
46 ~iterator() { delete m_imp; }
47
48 iterator& operator= (const iterator& o) { delete m_imp; m_imp = o.m_imp->clone(); return *this; }
49 bool operator!=(const iterator& o) { return m_imp->operator!=(*o.m_imp); }
50
51 const AliEveHOMERSource::SourceId& id() { return m_imp->id(); }
52 AliEveHOMERSource::SourceState& state() { return m_imp->state(); }
53
54 Int_t level();
55 TString description() { return m_imp->description(); }
56
57 iterator& operator++() { m_imp->operator++(); return *this; }
58 iterator& skip_children()
59 {
60 Int_t lvl = level();
61 do operator++(); while (level() > lvl);
62 return *this;
63 }
64 };
65
66 iterator begin() { return iterator(iterator_imp_begin()); }
67 iterator end() { return iterator(iterator_imp_end()); }
68
69 enum ESourceGrouping_e { kSG_ByDet, kSG_ByType };
70
71protected:
72 ESourceGrouping_e fGrouping; // Not used so far ...
73
74 virtual iterator_imp_base* iterator_imp_new() = 0; // Not used so far ...
75 virtual iterator_imp_base* iterator_imp_begin() = 0;
76 virtual iterator_imp_base* iterator_imp_end() = 0;
77
78public:
79 AliEveHOMERSourceMap(ESourceGrouping_e grouping);
80 virtual ~AliEveHOMERSourceMap() {}
81
82 static AliEveHOMERSourceMap* Create(ESourceGrouping_e grouping);
83
84 virtual void FillMap(TList* handles, Bool_t def_state) = 0;
85
86 void PrintXXX();
87
88 ClassDef(AliEveHOMERSourceMap, 0);
89};
90
91/******************************************************************************/
92
93class AliEveHOMERSourceMapByDet : public AliEveHOMERSourceMap
94{
95protected:
96 typedef std::map<AliEveHOMERSource::SourceId,
97 AliEveHOMERSource::SourceState,
98 AliEveHOMERSource::SourceId::CmpByDet> Map_t;
99 typedef Map_t::iterator Map_i;
100
101 Map_t fMap;
102
103 struct iterator_imp : public iterator_imp_base,
104 public Map_i
105 {
106 iterator_imp() : Map_i() {}
107 iterator_imp(Map_i mi) : Map_i(mi) {}
108 virtual ~iterator_imp() {}
109
25c3aaf7 110 virtual const AliEveHOMERSource::SourceId& id() const { return Map_i::operator*().first; }
111 virtual const AliEveHOMERSource::SourceState& state() const { return Map_i::operator*().second; }
a15e6d7d 112 virtual AliEveHOMERSource::SourceState& state() { return Map_i::operator*().second; }
113
25c3aaf7 114 virtual iterator_imp* clone() const
a15e6d7d 115 { return new iterator_imp(*this); }
116
117 virtual iterator_imp& operator++()
118 { Map_i::operator++(); return *this; }
119
25c3aaf7 120 virtual bool operator!=(const iterator_imp_base& rhs) const
121 { const Map_i &lhs = *this; return lhs != dynamic_cast<const Map_i&>(rhs); }
a15e6d7d 122
25c3aaf7 123 virtual TString description() const;
a15e6d7d 124 };
125
126 void insert(AliEveHOMERSource::SourceId& sid, AliEveHOMERSource::SourceState& sst, Bool_t def_state);
127
128 virtual iterator_imp_base* iterator_imp_new() { return new iterator_imp; }
129 virtual iterator_imp_base* iterator_imp_begin() { return new iterator_imp(fMap.begin()); }
130 virtual iterator_imp_base* iterator_imp_end() { return new iterator_imp(fMap.end()); }
131
132public:
133 AliEveHOMERSourceMapByDet(ESourceGrouping_e grouping);
134 virtual ~AliEveHOMERSourceMapByDet() {}
135
136 virtual void FillMap(TList* handles, Bool_t def_state);
137
138 // ClassDef(AliEveHOMERSourceMapByDet, 1);
139};
140
141/******************************************************************************/
142
143class AliEveHOMERSourceMapByType : public AliEveHOMERSourceMap
144{
145protected:
146 typedef std::map<AliEveHOMERSource::SourceId,
147 AliEveHOMERSource::SourceState,
148 AliEveHOMERSource::SourceId::CmpByType> Map_t;
149 typedef Map_t::iterator Map_i;
150
151 Map_t fMap;
152
153 struct iterator_imp : public iterator_imp_base,
154 public Map_i
155 {
156 iterator_imp() : Map_i() {}
157 iterator_imp(Map_i mi) : Map_i(mi) {}
158 virtual ~iterator_imp() {}
159
25c3aaf7 160 virtual const AliEveHOMERSource::SourceId& id() const { return Map_i::operator*().first; }
161 virtual const AliEveHOMERSource::SourceState& state() const { return Map_i::operator*().second; }
a15e6d7d 162 virtual AliEveHOMERSource::SourceState& state() { return Map_i::operator*().second; }
163
25c3aaf7 164 virtual iterator_imp* clone() const
a15e6d7d 165 { return new iterator_imp(*this); }
166
167 virtual iterator_imp& operator++()
168 { Map_i::operator++(); return *this; }
169
25c3aaf7 170 virtual bool operator!=(const iterator_imp_base& rhs) const
171 { const Map_i &lhs = *this; return lhs != dynamic_cast<const Map_i&>(rhs); }
a15e6d7d 172
25c3aaf7 173 virtual TString description() const;
a15e6d7d 174 };
175
176 void insert(AliEveHOMERSource::SourceId& sid, AliEveHOMERSource::SourceState& sst, Bool_t def_state);
177
178 virtual iterator_imp_base* iterator_imp_new() { return new iterator_imp; }
179 virtual iterator_imp_base* iterator_imp_begin() { return new iterator_imp(fMap.begin()); }
180 virtual iterator_imp_base* iterator_imp_end() { return new iterator_imp(fMap.end()); }
181
182public:
183 AliEveHOMERSourceMapByType(ESourceGrouping_e grouping);
184 virtual ~AliEveHOMERSourceMapByType() {}
185
186 virtual void FillMap(TList* handles, Bool_t def_state);
187
188 // ClassDef(AliEveHOMERSourceMapByType, 1);
189};
190
191#endif