PDDPChannelMap.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: PDDPChannelMap
3 // Plugin Type: service (art v3_02_06)
4 // File: PDDPChannelMap_service.cc
5 //
6 // Generated at Thu Jul 18 10:29:03 2019 by Vyacheslav Galymov using cetskelgen
7 // from cetlib version v3_07_02.
8 //
9 //
10 // Classes to facility channel order translation between different
11 // representations
12 //
13 // seqn - unique counter to give channel data position in the record
14 // crate - utca crate number starting
15 // card - AMC card number
16 // cardch - AMC card channel number
17 // crp - CRP number
18 // view - view number (0/1)
19 // viewch - view channel number
20 //
21 // Boost multi_index_container provides interface to search and order various
22 // indicies. The container structure is defined in DPChannelTable, which has
23 // the following interfaces:
24 // - raw sequence index, tag IndexRawSeqn
25 // - crate number, tag IndexCrate, to get all channels to a given crate
26 // - crate number and card number, tag IndexCrateCard,
27 // to get all channels for a given card in a crate
28 // - crate, card, and channel number, tag IndexCrateCardChan, to access
29 // a given channel of a given card in a given crate
30 // - CRP index, tag IndexCrp, to access channels assigned to a given CRP
31 // - CRP index and view index, tag IndexCrpView, to access channels assigned to
32 // a given view in a specified CRP
33 // - CRP index, view index, and channel number, tag IndexCrpViewChan, to access
34 // a given view channel in a given CRP
35 //
36 ////////////////////////////////////////////////////////////////////////
37 
38 #ifndef __PDDP_CHANNEL_MAP_H__
39 #define __PDDP_CHANNEL_MAP_H__
40 
43 #include "fhiclcpp/ParameterSet.h"
44 
45 #include <boost/multi_index_container.hpp>
46 #include <boost/multi_index/ordered_index.hpp>
47 #include <boost/multi_index/composite_key.hpp>
48 #include <boost/multi_index/hashed_index.hpp>
49 #include <boost/multi_index/identity.hpp>
50 #include <boost/multi_index/mem_fun.hpp>
51 #include <boost/range/iterator_range.hpp>
52 #include <boost/tuple/tuple.hpp>
53 #include <boost/optional.hpp>
54 
55 #include <set>
56 #include <vector>
57 #include <string>
58 
59 //
60 using namespace boost::multi_index;
61 
62 //
63 namespace dune
64 {
65  //
67  {
68  private:
69  unsigned seqn_;
70  unsigned short crate_, card_, cardch_;
71  unsigned short crp_, view_, viewch_;
72  //bool exists_;
73  unsigned short state_;
74 
75  public:
76 
78  DPChannelId( unsigned seqn,
79  unsigned short crate, unsigned short card, unsigned short cardch,
80  unsigned short crp, unsigned short view, unsigned short viewch,
81  unsigned short state = 0 ) :
82  seqn_(seqn), crate_(crate), card_(card), cardch_(cardch), crp_(crp), view_(view), viewch_(viewch), state_(state) {;}
83 
84  bool operator<(const DPChannelId &rhs) const { return seqn_ < rhs.seqn_; }
85 
86  const unsigned seqn() const { return seqn_; }
87  const unsigned short crate() const { return crate_; }
88  const unsigned short card() const { return card_; }
89  const unsigned short cardch() const { return cardch_; }
90  const unsigned short crp() const { return crp_; }
91  const unsigned short view() const { return view_; }
92  const unsigned short viewch() const { return viewch_; }
93  const unsigned short state() const { return state_; }
94  const bool exists() const { return (state_ == 0); }
95  };
96 
97 
98  //
99  // define multi_index container to implement channel mapping
100  //
101 
102  // container tags
103  struct IndexRawSeqn{};
104  struct IndexRawSeqnHash{}; // hashed
105  struct IndexCrate{}; // hashed
106  struct IndexCrateCard{}; // hashed
107  struct IndexCrateCardChan{}; // ordered
109  struct IndexCrp{}; // hashed
110  struct IndexCrpView{}; // hashed
111  struct IndexCrpViewChan{}; // ordered
113 
114  // boost multi index container
115  typedef multi_index_container<
116  DPChannelId,
117  indexed_by<
118  ordered_unique< tag<IndexRawSeqn>, const_mem_fun< DPChannelId, const unsigned, &DPChannelId::seqn > >,
119  hashed_unique< tag<IndexRawSeqnHash>, const_mem_fun< DPChannelId, const unsigned, &DPChannelId::seqn > >,
120  hashed_non_unique< tag<IndexCrate>, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::crate > >,
121  hashed_non_unique< tag<IndexCrateCard>, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::crate >, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::card > > >,
122  ordered_unique< tag<IndexCrateCardChan>, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::crate >, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::card >, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::cardch > > >,
123  hashed_unique< tag<IndexCrateCardChanHash>, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::crate >, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::card >, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::cardch > > >,
124  hashed_non_unique< tag<IndexCrp>, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::crp > >,
125  hashed_non_unique< tag<IndexCrpView>, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::crp >, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::view > > >,
126  ordered_unique< tag<IndexCrpViewChan>, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::crp >, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::view >, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::viewch > > >,
127  hashed_unique< tag<IndexCrpViewChanHash>, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::crp >, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::view >, const_mem_fun< DPChannelId, const unsigned short, &DPChannelId::viewch > > >
128  >
130 
131  //
132  //
133  //
135  public:
137  // The compiler-generated destructor is fine for non-base
138  // classes without bare pointers or other resource use.
139 
140  std::string getMapName() const { return mapname_; }
141 
142  // old style map functions
143  int MapToCRP(int seqch, int &crp, int &view, int &chv) const;
144  int MapToDAQ(int crp, int view, int chv, int &seqch) const;
145 
146  // //
147  // retrive various map data //
148  // //
149 
150  // from seq num in raw data file
151  boost::optional<DPChannelId> find_by_seqn( unsigned seqn ) const;
152  std::vector<DPChannelId> find_by_seqn( unsigned from, unsigned to ) const;
153 
154  // from crate info
155  std::vector<DPChannelId> find_by_crate( unsigned crate, bool ordered = true ) const;
156  std::vector<DPChannelId> find_by_crate_card( unsigned crate, unsigned card,
157  bool ordered = true ) const;
158  boost::optional<DPChannelId> find_by_crate_card_chan( unsigned crate,
159  unsigned card, unsigned chan ) const;
160  // from CRP info
161  std::vector<DPChannelId> find_by_crp( unsigned crp, bool ordered = true ) const;
162  std::vector<DPChannelId> find_by_crp_view( unsigned crp, unsigned view, bool ordered = true ) const;
163  boost::optional<DPChannelId> find_by_crp_view_chan( unsigned crp,
164  unsigned view, unsigned chan ) const;
165 
166  unsigned ncrates() const { return ncrates_; }
167  unsigned ncrps() const { return ncrps_; }
168  unsigned ntot() const { return ntot_; }
169  unsigned ncards( unsigned crate ) const;
170  unsigned nviews( unsigned crp ) const;
171 
172  //
173  void print( std::vector<DPChannelId> &vec );
174 
175  std::set< unsigned > get_crateidx(){ return crateidx_; }
176  std::set< unsigned > get_crpidx(){ return crpidx_; }
177 
178  private:
179 
180  //
181  void clearMap();
182 
183  void initMap( std::string mapname, unsigned ncrates = 1,
184  unsigned ncards = 10, unsigned nviews = 1 );
185 
186  void add( unsigned seq, unsigned crate, unsigned card, unsigned cch,
187  unsigned crp, unsigned view, unsigned vch, unsigned short state = 0);
188 
189  template<typename Index,typename KeyExtractor>
190  std::size_t cdistinct(const Index& i, KeyExtractor key)
191  {
192  std::size_t res = 0;
193  for(auto it=i.begin(),it_end=i.end();it!=it_end;)
194  {
195  ++res;
196  it = i.upper_bound( key(*it) );
197  }
198  return res;
199  }
200 
201  // simple map
202  void simpleMap( unsigned ncrates, unsigned ncards, unsigned nviews );
203 
204  // ProtoDUNE DP map with 2 CRPs + 2 x 2 anodes
205  void pddp2crpMap();
206 
207  // ProtoDUNE DP map with 4 CRPs instrumented
208  void pddp4crpMap();
209 
210  // Just remove by hand channels which do not exists here
211  // since I do not want to be bothered anymore with this ...
212  std::vector<DPChannelId> filter( std::vector<DPChannelId> &sel ) const
213  {
214  std::vector<DPChannelId> res;
215  for( auto &c : sel )
216  if( c.exists() ) res.push_back( c );
217  return res;
218  }
219 
220  //
222 
224  std::set< unsigned > crateidx_;
225  std::set< unsigned > crpidx_;
226  unsigned ncrates_;
227  unsigned ncrps_;
228  unsigned ntot_;
229  unsigned nch_;
230  };
231 } //namespace dune
232 
234 #endif
DPChannelId(unsigned seqn, unsigned short crate, unsigned short card, unsigned short cardch, unsigned short crp, unsigned short view, unsigned short viewch, unsigned short state=0)
unsigned short state_
unsigned short crate_
std::string string
Definition: nybbler.cc:12
const unsigned short crate() const
Coord add(Coord c1, Coord c2)
Definition: restypedef.cpp:23
const unsigned short card() const
std::set< unsigned > get_crpidx()
std::set< unsigned > crateidx_
unsigned ntot() const
const bool exists() const
const unsigned seqn() const
unsigned ncrps() const
unsigned int Index
bool operator<(const DPChannelId &rhs) const
const unsigned short viewch() const
std::vector< DPChannelId > filter(std::vector< DPChannelId > &sel) const
const unsigned short crp() const
def key(type, name=None)
Definition: graph.py:13
struct dune::tde::crate crate
#define DECLARE_ART_SERVICE(svc, scope)
const unsigned short state() const
std::size_t cdistinct(const Index &i, KeyExtractor key)
const unsigned short view() const
p
Definition: test.py:223
std::set< unsigned > get_crateidx()
DPChannelTable chanTable
std::string getMapName() const
multi_index_container< DPChannelId, indexed_by< ordered_unique< tag< IndexRawSeqn >, const_mem_fun< DPChannelId, const unsigned,&DPChannelId::seqn > >, hashed_unique< tag< IndexRawSeqnHash >, const_mem_fun< DPChannelId, const unsigned,&DPChannelId::seqn > >, hashed_non_unique< tag< IndexCrate >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::crate > >, hashed_non_unique< tag< IndexCrateCard >, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::crate >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::card > > >, ordered_unique< tag< IndexCrateCardChan >, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::crate >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::card >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::cardch > > >, hashed_unique< tag< IndexCrateCardChanHash >, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::crate >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::card >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::cardch > > >, hashed_non_unique< tag< IndexCrp >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::crp > >, hashed_non_unique< tag< IndexCrpView >, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::crp >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::view > > >, ordered_unique< tag< IndexCrpViewChan >, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::crp >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::view >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::viewch > > >, hashed_unique< tag< IndexCrpViewChanHash >, composite_key< DPChannelId, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::crp >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::view >, const_mem_fun< DPChannelId, const unsigned short,&DPChannelId::viewch > > > > > DPChannelTable
unsigned ncrates() const
const unsigned short cardch() const
std::set< unsigned > crpidx_
unsigned short viewch_