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