tde_cmap_utils.h
Go to the documentation of this file.
1 #ifndef __TDE_CMAP_UTILS__
2 #define __TDE_CMAP_UTILS__
3 
4 #include <iostream>
5 #include <set>
6 #include <vector>
7 #include <utility>
8 #include <tuple>
9 
10 namespace dune { namespace tde {
11  const short ch_per_kel = 32;
12  const short ch_per_amc = 64;
13 
14  typedef struct kel_connector
15  {
17  {
18  _id = -1;
19  _view = -1;
20  _reverse = false;
21  _first_view_ch = 0;
22  }
23 
24  kel_connector( int id, int view, bool reverse, int first_view_ch )
25  {
26  _id = id;
27  _view = view;
28  _reverse = reverse;
29  _first_view_ch = first_view_ch;
30  }
31 
32  void print() const{
33  std::cout<<"KEL "<<_id<<" : view "<<_view
34  <<" reverse order "<<_reverse
35  <<" first view ch for this connector "<<_first_view_ch<<std::endl;
36  }
37 
38  bool operator < (const kel_connector &other) const { return _id < other._id; }
39 
40  int _id;
41  int _view;
42  bool _reverse;
44 
45  } kel_connector;
46 
47  typedef std::set<kel_connector> connectors;
48 
49  //
50  typedef struct crp_connectors
51  {
52 
53  crp_connectors( int crp, int views ){
54  _crp = crp;
55  _view_kels.resize( views );
56  }
57 
58  //
59  size_t views() const { return _view_kels.size(); }
60 
61  //
62  size_t nch_view( int iview ) const {
63  size_t nch = 0;
64  if( iview >= (int)_view_kels.size())
65  return nch;
66  auto nkel = _view_kels[iview];
67  nch = nkel * ch_per_kel;
68  return nch;
69  }
70 
71  void add_connector( int id, int view, bool reverse, int first_view_ch ){
72  _kels.insert( kel_connector( id, view, reverse, first_view_ch ) );
73  }
74 
75  int _crp;
76  connectors _kels;
77  std::vector< int > _view_kels;
79 
80  //
81  typedef struct crate
82  {
83  crate(int id, int cards){
84  _id = id;
85  _cards = cards;
86  }
87 
88  //
89  void add_crp_connection( int icrp, int fslot,
90  const std::vector<int> &kel_ids )
91  {
92  auto nconn = kel_ids.size();
93  if( nconn % 2 ){
94  std::cout<<"number of connectors is not even\n";
95  return;
96  }
97 
98  if( fslot < (int)_crp_conn.size() && !_crp_conn.empty() ){
99  std::cout<<"cannot overwrite the existing connection\n";
100  return;
101  }
102 
103  int islot = fslot;
104  for( size_t i=0;i<kel_ids.size();i+=2 ){
105  int kel_1 = kel_ids[i];
106  int kel_2 = kel_ids[i+1];
107 
108  if( islot >= _cards ){
109  std::cout<<"slot "<<islot<<" does not exist\n";
110  break;
111  }
112  _crp_conn.emplace_back(islot, icrp, kel_1, kel_2 );
113  islot++;
114  }
115  }
116 
117  //
118  int _id;
119  int _cards;
120  std::vector< std::tuple< int, int, int, int> > _crp_conn;
121  } crate;
122 
123  } //tde
124 }//dune
125 
126 #endif
void add_connector(int id, int view, bool reverse, int first_view_ch)
size_t nch_view(int iview) const
crate(int id, int cards)
void add_crp_connection(int icrp, int fslot, const std::vector< int > &kel_ids)
std::vector< std::tuple< int, int, int, int > > _crp_conn
std::vector< int > _view_kels
struct dune::tde::crp_connectors crp_connectors
std::set< kel_connector > connectors
struct dune::tde::crate crate
const short ch_per_amc
crp_connectors(int crp, int views)
const short ch_per_kel
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
Definition: qstring.cpp:11649
kel_connector(int id, int view, bool reverse, int first_view_ch)
bool operator<(const kel_connector &other) const
QTextStream & endl(QTextStream &s)