Fork me on GitHub

source: git/external/ExRootAnalysis/ExRootFilter.cc @ 77e9ae1

ImprovedOutputFileTimingllp
Last change on this file since 77e9ae1 was 77e9ae1, checked in by Pavel Demin <pavel-demin@…>, 18 months ago

set Standard to Cpp03 in .clang-format

  • Property mode set to 100644
File size: 3.3 KB
Line 
1
2/** \class ExRootFilter
3 *
4 *  Class simplifying classification and subarrays handling
5 *
6 *  \author P. Demin - UCL, Louvain-la-Neuve
7 *
8 */
9
10#include "ExRootAnalysis/ExRootFilter.h"
11#include "ExRootAnalysis/ExRootClassifier.h"
12
13#include "TObjArray.h"
14#include "TSeqCollection.h"
15
16#include <iostream>
17#include <sstream>
18#include <stdexcept>
19
20using namespace std;
21
22typedef map<Int_t, TObjArray *> TCategoryMap;
23typedef map<ExRootClassifier *, pair<Bool_t, TCategoryMap> > TClassifierMap;
24
25ExRootFilter::ExRootFilter(const TSeqCollection *collection) :
26  fCollection(collection)
27{
28  fIter = fCollection->MakeIterator();
29}
30
31//------------------------------------------------------------------------------
32
33ExRootFilter::~ExRootFilter()
34{
35  TClassifierMap::iterator itMap;
36  TCategoryMap::iterator itSubMap;
37  for(itMap = fMap.begin(); itMap != fMap.end(); ++itMap)
38  {
39    for(itSubMap = itMap->second.second.begin();
40        itSubMap != itMap->second.second.end(); ++itSubMap)
41    {
42      delete(itSubMap->second);
43    }
44  }
45
46  delete fIter;
47}
48
49//------------------------------------------------------------------------------
50
51void ExRootFilter::Reset(ExRootClassifier *classifier)
52{
53  TClassifierMap::iterator itMap;
54  TCategoryMap::iterator itSubMap;
55  if(classifier)
56  {
57    itMap = fMap.find(classifier);
58    if(itMap != fMap.end())
59    {
60      itMap->second.first = kTRUE;
61      for(itSubMap = itMap->second.second.begin();
62          itSubMap != itMap->second.second.end(); ++itSubMap)
63      {
64        itSubMap->second->Clear();
65      }
66    }
67  }
68  else
69  {
70    for(itMap = fMap.begin(); itMap != fMap.end(); ++itMap)
71    {
72      itMap->second.first = kTRUE;
73      for(itSubMap = itMap->second.second.begin();
74          itSubMap != itMap->second.second.end(); ++itSubMap)
75      {
76        itSubMap->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 itSubMap;
90  pair<TCategoryMap::iterator, bool> pairSubMap;
91  pair<TClassifierMap::iterator, bool> pairMap;
92
93  TClassifierMap::iterator itMap = fMap.find(classifier);
94  if(itMap == fMap.end())
95  {
96    pairMap = fMap.insert(make_pair(classifier, make_pair(kTRUE, TCategoryMap())));
97    if(!pairMap.second)
98    {
99      throw runtime_error("can't insert category map");
100    }
101
102    itMap = pairMap.first;
103  }
104
105  if(itMap->second.first)
106  {
107    itMap->second.first = kFALSE;
108    fIter->Reset();
109    while((element = fIter->Next()) != 0)
110    {
111      result = classifier->GetCategory(element);
112      if(result < 0) continue;
113      itSubMap = itMap->second.second.find(result);
114      if(itSubMap == itMap->second.second.end())
115      {
116        array = new TObjArray(fCollection->GetSize());
117        pairSubMap = itMap->second.second.insert(make_pair(result, array));
118        if(!pairSubMap.second)
119        {
120          throw runtime_error("can't insert category");
121        }
122
123        itSubMap = pairSubMap.first;
124      }
125      itSubMap->second->Add(element);
126    }
127  }
128
129  itSubMap = itMap->second.second.find(category);
130  return (itSubMap != itMap->second.second.end()) ? itSubMap->second : 0;
131}
132
133//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.