ODIN
collector.h
1 /***************************************************************************
2  collector.h - description
3  -------------------
4  begin : Sun Jan 14 2007
5  copyright : (C) 2000-2021 by Thies Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef RECOCOLLECTOR_H
19 #define RECOCOLLECTOR_H
20 
21 
22 #include "step.h"
23 
35 class RecoCollectorBase : public RecoStep {
36 
37  protected:
38 
41 
42 
50  bool completed(const RecoCoord& coord, unsigned int custom_count);
51 
56  bool calculate_count(RecoQueryContext& context, const RecoCoord& inmask, const RecoCoord& outmask);
57 
58 
59  private:
60 
61  CoordCountMap todo; // coordinate always refers to the output of functor, i.e. after applying 'modify_coord'
62  Mutex todomutex;
63 
64  unsigned int count; // initialized in query/calculate_count, assumed to be the same for all coordinates
65 
66  STD_string label_cache; // label() might not be available in destructor
67 };
68 
69 
70 
71 
73 
74 
75 /*
76  * Template class to collect data in one or more dimensions.
77  * The rank of the input data is given by 'Nin'. The particular input dimension are given
78  * in 'In' by a specialization of 'RecoDim'. The numer of dimensions to collect data
79  * for is given in 'Ncoll' and specified in 'Coll' by a specialization of 'RecoDim'.
80  * The resulting data array will have the collected dimensions leftmost, i.e.
81  * if In=i1,i2 and Coll=c1, the resulting array will have dimensions (c1,i1,i2)
82  * If 'use_numof' is set to 'true', the numof of the collected indices will be used
83  * for the count instead of using a count map.
84  */
85 template<unsigned int Nin, class In, unsigned int Ncoll, class Coll, bool use_numof=false>
86 class RecoCollector : public RecoCollectorBase, public Labeled {
87 
88  public:
89  RecoCollector(const STD_string& coll_label) : Labeled(coll_label) {}
90 
91  private:
92 
93  // implementing virtual functions of RecoStep
94  STD_string label() const {return get_label();}
95  STD_string description() const {return "Collect data in one or more dimensions";}
96  bool process(RecoData& rd, RecoController& controller);
97  RecoCoord input_coord() const {return In::preset_coord(RecoIndex::collected);}
98  void modify_coord(RecoCoord& coord) const {Coll::modify(RecoIndex::collected,coord);}
99  bool query(RecoQueryContext& context);
100  RecoStep* allocate() const {return new RecoCollector(get_label());}
101  void init() {}
102 
103 
104  typedef STD_map<RecoCoord, ComplexData<Nin+Ncoll> > DataMap;
105  DataMap datamap; // the data collected
106  Mutex mutex;
107 
108 };
109 
110 
114 #endif
115 
Labeled(const STD_string &label="unnamed")
Definition: tjlabel.h:38
const STD_string & get_label() const
Definition: tjlabel.h:48
Definition: tjthread.h:46
bool calculate_count(RecoQueryContext &context, const RecoCoord &inmask, const RecoCoord &outmask)
bool completed(const RecoCoord &coord, unsigned int custom_count)
averagecoll, chancoll, chanrepcoll, chanrepslicecoll, cyclecoll, driftcoll, echocoll,...
Definition: collector.h:86
STD_map< RecoCoord, UInt > CoordCountMap
Definition: index.h:364