source: trunk/src/ExRootFilter.cc@ 13

Last change on this file since 13 was 2, checked in by Pavel Demin, 16 years ago

first commit

File size: 3.1 KB
Line 
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
22ExRootFilter::ExRootFilter(const TSeqCollection *collection) :
23 fCollection(collection)
24{
25 fIter = fCollection->MakeIterator();
26}
27
28//------------------------------------------------------------------------------
29
30ExRootFilter::~ExRootFilter()
31{
32 TClassifierMap::iterator it_map;
33 TCategoryMap::iterator it_submap;
34 for(it_map = fMap.begin(); it_map != fMap.end(); ++it_map)
35 {
36 for(it_submap = it_map->second.second.begin();
37 it_submap != it_map->second.second.end(); ++it_submap)
38 {
39 delete (it_submap->second);
40 }
41 }
42
43 delete fIter;
44}
45
46//------------------------------------------------------------------------------
47
48void ExRootFilter::Reset(ExRootClassifier *classifier)
49{
50 TClassifierMap::iterator it_map;
51 TCategoryMap::iterator it_submap;
52 if(classifier)
53 {
54 it_map = fMap.find(classifier);
55 if(it_map != fMap.end())
56 {
57 it_map->second.first = kTRUE;
58 for(it_submap = it_map->second.second.begin();
59 it_submap != it_map->second.second.end(); ++it_submap)
60 {
61 it_submap->second->Clear();
62 }
63 }
64 }
65 else
66 {
67 for(it_map = fMap.begin(); it_map != fMap.end(); ++it_map)
68 {
69 it_map->second.first = kTRUE;
70 for(it_submap = it_map->second.second.begin();
71 it_submap != it_map->second.second.end(); ++it_submap)
72 {
73 it_submap->second->Clear();
74 }
75 }
76 }
77}
78
79//------------------------------------------------------------------------------
80
81TObjArray *ExRootFilter::GetSubArray(ExRootClassifier *classifier, Int_t category)
82{
83 Int_t result;
84 TObject *element;
85 TObjArray *array;
86 TCategoryMap::iterator it_submap;
87 pair<TCategoryMap::iterator, bool> pair_submap;
88 pair<TClassifierMap::iterator, bool> pair_map;
89
90 TClassifierMap::iterator it_map = fMap.find(classifier);
91 if(it_map == fMap.end())
92 {
93 pair_map = fMap.insert(make_pair(classifier, make_pair(kTRUE, TCategoryMap())));
94 if(!pair_map.second) throw FilterExeption();
95
96 it_map = pair_map.first;
97 }
98
99 if(it_map->second.first)
100 {
101 it_map->second.first = kFALSE;
102 fIter->Reset();
103 while((element = fIter->Next()) != 0)
104 {
105 result = classifier->GetCategory(element);
106 if(result < 0) continue;
107 it_submap = it_map->second.second.find(result);
108 if(it_submap == it_map->second.second.end())
109 {
110 array = new TObjArray(fCollection->GetSize());
111 pair_submap = it_map->second.second.insert(make_pair(result, array));
112 if(!pair_submap.second) throw FilterExeption();
113
114 it_submap = pair_submap.first;
115 }
116 it_submap->second->Add(element);
117 }
118 }
119
120 it_submap = it_map->second.second.find(category);
121 return (it_submap != it_map->second.second.end()) ? it_submap->second : 0;
122}
123
124//------------------------------------------------------------------------------
125
Note: See TracBrowser for help on using the repository browser.