Moving to standard names
[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:
4b456ebb 22 // --- Inner structs ---
23
a15e6d7d 24 struct iterator_imp_base
25 {
26 virtual ~iterator_imp_base() {}
27
25c3aaf7 28 virtual const AliEveHOMERSource::SourceId& id() const = 0;
29 virtual const AliEveHOMERSource::SourceState& state() const = 0;
a15e6d7d 30 virtual AliEveHOMERSource::SourceState& state() = 0;
31
25c3aaf7 32 virtual iterator_imp_base* clone() const = 0;
a15e6d7d 33
34 virtual iterator_imp_base& operator++() = 0;
25c3aaf7 35 virtual bool operator!=(const iterator_imp_base& o) const = 0;
a15e6d7d 36
25c3aaf7 37 virtual TString description() const = 0;
a15e6d7d 38 };
39
40public:
4b456ebb 41 // --- Inner structs ---
42
a15e6d7d 43 struct iterator
44 {
45 iterator_imp_base* m_imp;
46
47 iterator() : m_imp(0) {}
c61a7285 48 iterator(const iterator& it) : m_imp(it.m_imp->clone()) {}
a15e6d7d 49 iterator(iterator_imp_base* imp) : m_imp(imp) {}
50 ~iterator() { delete m_imp; }
51
52 iterator& operator= (const iterator& o) { delete m_imp; m_imp = o.m_imp->clone(); return *this; }
53 bool operator!=(const iterator& o) { return m_imp->operator!=(*o.m_imp); }
54
55 const AliEveHOMERSource::SourceId& id() { return m_imp->id(); }
56 AliEveHOMERSource::SourceState& state() { return m_imp->state(); }
57
58 Int_t level();
59 TString description() { return m_imp->description(); }
60
61 iterator& operator++() { m_imp->operator++(); return *this; }
62 iterator& skip_children()
63 {
64 Int_t lvl = level();
65 do operator++(); while (level() > lvl);
66 return *this;
67 }
68 };
69
70 iterator begin() { return iterator(iterator_imp_begin()); }
71 iterator end() { return iterator(iterator_imp_end()); }
4b456ebb 72
a15e6d7d 73 enum ESourceGrouping_e { kSG_ByDet, kSG_ByType };
74
4b456ebb 75 // --- Interface ---
a15e6d7d 76
a15e6d7d 77 AliEveHOMERSourceMap(ESourceGrouping_e grouping);
78 virtual ~AliEveHOMERSourceMap() {}
79
80 static AliEveHOMERSourceMap* Create(ESourceGrouping_e grouping);
81
82 virtual void FillMap(TList* handles, Bool_t def_state) = 0;
83
84 void PrintXXX();
85
4b456ebb 86
87protected:
88 ESourceGrouping_e fGrouping; // Not used so far ...
89
90 virtual iterator_imp_base* iterator_imp_new() = 0; // Not used so far ...
91 virtual iterator_imp_base* iterator_imp_begin() = 0;
92 virtual iterator_imp_base* iterator_imp_end() = 0;
93
94 ClassDef(AliEveHOMERSourceMap, 0); // A map of HOMER sources.
a15e6d7d 95};
96
97/******************************************************************************/
98
99class AliEveHOMERSourceMapByDet : public AliEveHOMERSourceMap
100{
4b456ebb 101public:
102 AliEveHOMERSourceMapByDet(ESourceGrouping_e grouping);
103 virtual ~AliEveHOMERSourceMapByDet() {}
104
105 virtual void FillMap(TList* handles, Bool_t def_state);
106
a15e6d7d 107protected:
108 typedef std::map<AliEveHOMERSource::SourceId,
109 AliEveHOMERSource::SourceState,
110 AliEveHOMERSource::SourceId::CmpByDet> Map_t;
111 typedef Map_t::iterator Map_i;
112
113 Map_t fMap;
114
115 struct iterator_imp : public iterator_imp_base,
116 public Map_i
117 {
118 iterator_imp() : Map_i() {}
119 iterator_imp(Map_i mi) : Map_i(mi) {}
120 virtual ~iterator_imp() {}
121
25c3aaf7 122 virtual const AliEveHOMERSource::SourceId& id() const { return Map_i::operator*().first; }
123 virtual const AliEveHOMERSource::SourceState& state() const { return Map_i::operator*().second; }
a15e6d7d 124 virtual AliEveHOMERSource::SourceState& state() { return Map_i::operator*().second; }
125
25c3aaf7 126 virtual iterator_imp* clone() const
a15e6d7d 127 { return new iterator_imp(*this); }
128
129 virtual iterator_imp& operator++()
130 { Map_i::operator++(); return *this; }
131
25c3aaf7 132 virtual bool operator!=(const iterator_imp_base& rhs) const
133 { const Map_i &lhs = *this; return lhs != dynamic_cast<const Map_i&>(rhs); }
a15e6d7d 134
25c3aaf7 135 virtual TString description() const;
a15e6d7d 136 };
137
138 void insert(AliEveHOMERSource::SourceId& sid, AliEveHOMERSource::SourceState& sst, Bool_t def_state);
139
140 virtual iterator_imp_base* iterator_imp_new() { return new iterator_imp; }
141 virtual iterator_imp_base* iterator_imp_begin() { return new iterator_imp(fMap.begin()); }
142 virtual iterator_imp_base* iterator_imp_end() { return new iterator_imp(fMap.end()); }
143
a15e6d7d 144
4b456ebb 145 // ClassDef(AliEveHOMERSourceMapByDet, 0);
a15e6d7d 146};
147
148/******************************************************************************/
149
150class AliEveHOMERSourceMapByType : public AliEveHOMERSourceMap
151{
4b456ebb 152public:
153 AliEveHOMERSourceMapByType(ESourceGrouping_e grouping);
154 virtual ~AliEveHOMERSourceMapByType() {}
155
156 virtual void FillMap(TList* handles, Bool_t def_state);
157
a15e6d7d 158protected:
159 typedef std::map<AliEveHOMERSource::SourceId,
160 AliEveHOMERSource::SourceState,
161 AliEveHOMERSource::SourceId::CmpByType> Map_t;
162 typedef Map_t::iterator Map_i;
163
164 Map_t fMap;
165
166 struct iterator_imp : public iterator_imp_base,
167 public Map_i
168 {
169 iterator_imp() : Map_i() {}
170 iterator_imp(Map_i mi) : Map_i(mi) {}
171 virtual ~iterator_imp() {}
172
25c3aaf7 173 virtual const AliEveHOMERSource::SourceId& id() const { return Map_i::operator*().first; }
174 virtual const AliEveHOMERSource::SourceState& state() const { return Map_i::operator*().second; }
a15e6d7d 175 virtual AliEveHOMERSource::SourceState& state() { return Map_i::operator*().second; }
176
25c3aaf7 177 virtual iterator_imp* clone() const
a15e6d7d 178 { return new iterator_imp(*this); }
179
180 virtual iterator_imp& operator++()
181 { Map_i::operator++(); return *this; }
182
25c3aaf7 183 virtual bool operator!=(const iterator_imp_base& rhs) const
184 { const Map_i &lhs = *this; return lhs != dynamic_cast<const Map_i&>(rhs); }
a15e6d7d 185
25c3aaf7 186 virtual TString description() const;
a15e6d7d 187 };
188
189 void insert(AliEveHOMERSource::SourceId& sid, AliEveHOMERSource::SourceState& sst, Bool_t def_state);
190
191 virtual iterator_imp_base* iterator_imp_new() { return new iterator_imp; }
192 virtual iterator_imp_base* iterator_imp_begin() { return new iterator_imp(fMap.begin()); }
193 virtual iterator_imp_base* iterator_imp_end() { return new iterator_imp(fMap.end()); }
194
4b456ebb 195 // ClassDef(AliEveHOMERSourceMapByType, 0);
a15e6d7d 196};
197
198#endif