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