source: trunk/src/ExRootFilter.cc

Last change on this file was 22, checked in by Pavel Demin, 14 years ago

add workaround for a typedef related bug in the latest rootcint

File size: 3.2 KB
RevLine 
[2]1
2/** \class ExRootFilter
3 *
4 * Class simplifying classification and subarrays handling
5 *
6 * $Date: 2008-06-04 13:57:55 $
7 * $Revision: 1.1 $
8 *
9 *
10 * \author P. Demin - UCL, Louvain-la-Neuve
11 *
12 */
13
14#include "ExRootAnalysis/ExRootFilter.h"
15#include "ExRootAnalysis/ExRootClassifier.h"
16
17#include "TSeqCollection.h"
18#include "TObjArray.h"
19
20using namespace std;
21
[22]22typedef map<Int_t, TObjArray*> TCategoryMap;
23typedef map<ExRootClassifier*, pair<Bool_t, TCategoryMap> > TClassifierMap;
24
[2]25ExRootFilter::ExRootFilter(const TSeqCollection *collection) :
26 fCollection(collection)
27{
28 fIter = fCollection->MakeIterator();
29}
30
31//------------------------------------------------------------------------------
32
33ExRootFilter::~ExRootFilter()
34{
35 TClassifierMap::iterator it_map;
36 TCategoryMap::iterator it_submap;
37 for(it_map = fMap.begin(); it_map != fMap.end(); ++it_map)
38 {
39 for(it_submap = it_map->second.second.begin();
40 it_submap != it_map->second.second.end(); ++it_submap)
41 {
42 delete (it_submap->second);
43 }
44 }
45
46 delete fIter;
47}
48
49//------------------------------------------------------------------------------
50
51void ExRootFilter::Reset(ExRootClassifier *classifier)
52{
53 TClassifierMap::iterator it_map;
54 TCategoryMap::iterator it_submap;
55 if(classifier)
56 {
57 it_map = fMap.find(classifier);
58 if(it_map != fMap.end())
59 {
60 it_map->second.first = kTRUE;
61 for(it_submap = it_map->second.second.begin();
62 it_submap != it_map->second.second.end(); ++it_submap)
63 {
64 it_submap->second->Clear();
65 }
66 }
67 }
68 else
69 {
70 for(it_map = fMap.begin(); it_map != fMap.end(); ++it_map)
71 {
72 it_map->second.first = kTRUE;
73 for(it_submap = it_map->second.second.begin();
74 it_submap != it_map->second.second.end(); ++it_submap)
75 {
76 it_submap->second->Clear();
77 }
78 }
79 }
80}
81
82//------------------------------------------------------------------------------
83
84TObjArray *ExRootFilter::GetSubArray(ExRootClassifier *classifier, Int_t category)
85{
86 Int_t result;
87 TObject *element;
88 TObjArray *array;
89 TCategoryMap::iterator it_submap;
90 pair<TCategoryMap::iterator, bool> pair_submap;
91 pair<TClassifierMap::iterator, bool> pair_map;
92
93 TClassifierMap::iterator it_map = fMap.find(classifier);
94 if(it_map == fMap.end())
95 {
96 pair_map = fMap.insert(make_pair(classifier, make_pair(kTRUE, TCategoryMap())));
97 if(!pair_map.second) throw FilterExeption();
98
99 it_map = pair_map.first;
100 }
101
102 if(it_map->second.first)
103 {
104 it_map->second.first = kFALSE;
105 fIter->Reset();
106 while((element = fIter->Next()) != 0)
107 {
108 result = classifier->GetCategory(element);
109 if(result < 0) continue;
110 it_submap = it_map->second.second.find(result);
111 if(it_submap == it_map->second.second.end())
112 {
113 array = new TObjArray(fCollection->GetSize());
114 pair_submap = it_map->second.second.insert(make_pair(result, array));
115 if(!pair_submap.second) throw FilterExeption();
116
117 it_submap = pair_submap.first;
118 }
119 it_submap->second->Add(element);
120 }
121 }
122
123 it_submap = it_map->second.second.find(category);
124 return (it_submap != it_map->second.second.end()) ? it_submap->second : 0;
125}
126
127//------------------------------------------------------------------------------
128
Note: See TracBrowser for help on using the repository browser.