38 #include "cetlib_except/exception.h" 41 #include <boost/range.hpp> 42 #include <boost/range/adaptors.hpp> 66 unsigned ncrateInMap = p.
get<
unsigned>(
"MapCrateNb", 3);
67 unsigned ncardsInMap = p.
get<
unsigned>(
"MapCardNb", 10);
68 unsigned nviewsInMap = p.
get<
unsigned>(
"MapViewNb", 1);
71 initMap( MapName, ncrateInMap, ncardsInMap, nviewsInMap );
86 if(
mapname_.compare( mapname ) == 0 ) {
92 if( mapname.compare(
"vdcb1crp") == 0 ) {
119 unsigned nctot = ncards *
ncrates;
120 unsigned ncview = nctot /
nviews;
128 for(
unsigned card = 0; card < nctot; card++ )
131 if( card % ncards == 0 ) crate++;
132 if( card % ncview == 0 ) {view++; vch=0;}
134 for(
unsigned ch = 0; ch < nch; ch++ ){
135 add( seqn++, crate, card % ncards, ch, crp, view, vch++);
146 unsigned cch,
unsigned crp,
unsigned view,
147 unsigned vch,
unsigned short state )
169 return boost::optional<ChannelId>();
178 std::vector<ChannelId> res;
182 if( boost::optional<ChannelId>
id =
find_by_seqn( from ) )
183 res.push_back( *
id );
192 res.insert( res.begin(), first, last );
205 std::vector<ChannelId> res(
r.first,
r.second);
210 std::vector<ChannelId> res(
r.first,
r.second);
222 std::vector<ChannelId> res(
r.first,
r.second);
228 std::vector<ChannelId> res(
r.first,
r.second);
236 unsigned card,
unsigned chan )
const 242 return boost::optional<ChannelId>();
252 std::vector<ChannelId> res(
r.first,
r.second);
257 std::vector<ChannelId> res(
r.first,
r.second);
269 std::vector<ChannelId> res(
r.first,
r.second);
275 std::vector<ChannelId> res(
r.first,
r.second);
282 unsigned view,
unsigned chan )
const 288 return boost::optional<ChannelId>();
295 crp = view = chv = -1;
296 if( boost::optional<ChannelId>
id =
find_by_seqn( (
unsigned)seqch ) )
298 if( !id->exists() )
return -1;
313 if( boost::optional<ChannelId>
id =
find_by_crp_view_chan( (
unsigned)crp, (
unsigned)view, (
unsigned)chv ) )
315 if( !id->exists() )
return -1;
330 for(
ChannelId const &ch : boost::make_iterator_range(
r ) )
332 if( !ch.exists() )
continue;
333 unsigned val = ch.card();
352 for(
ChannelId const &ch : boost::make_iterator_range(
r ) )
354 if( !ch.exists() )
continue;
355 unsigned val = ch.view();
370 for(
auto it = vec.begin();it!=vec.end();++it )
372 unsigned seqn = it->seqn();
374 unsigned card = it->card();
375 unsigned cch = it->cardch();
376 unsigned crp = it->crp();
377 unsigned view = it->view();
378 unsigned vch = it->viewch();
379 unsigned state = it->state();
380 bool exists = it->exists();
402 vector<int> c1_kel{34, 36, 35, 38, 37, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49};
407 vector<int> c2_kel{14, 16, 15, 18, 17, 19, 20, 22, 21, 25, 23, 24, 26, 27, 28, 32, 29, 30, 31, 33};
412 vector<int> c3_kel{0, 2, 1, 5, 3, 4, 6, 7, 8, 12, 9, 10, 11, 13};
415 vector<dune::tde::crate> crates{
c1, c2, c3};
421 vector<unsigned> kel_nor = { 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9,
422 8, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24 };
424 vector<unsigned> kel_inv = {24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22,
425 23, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7 };
430 vector<int> kel_view0{1,5,8,12,15,18,21,25,28,32,35,38};
433 vector<int> kel_view1{40,41,42,43,44,45,46,47,48,49, 13,11,10,9,7,6,4,3,2,0};
435 vector<int> kel_view2{14,16,17,19,20,22,23,24,26,27,29,30,31,33,34,36,37,39};
441 for(
auto const k : kel_view0 ){
443 crp_conn.add_connector(
k, 0,
false, ch_start );
447 for(
auto const k : kel_view1 ){
450 crp_conn.add_connector(
k, 1, reverse, ch_start );
455 for(
auto const k : kel_view2 ){
457 crp_conn.add_connector(
k, 2,
false, ch_start );
467 unsigned view_na = (unsigned)nview;
468 unsigned view_na_ch = 0;
470 for(
auto const &utca : crates ) {
471 unsigned utca_id = (unsigned)utca._id;
473 auto utca_conn = utca._crp_conn;
474 auto utca_nconn = utca_conn.size();
475 auto utca_slots = (unsigned)utca._cards;
476 for(
unsigned amc = 0; amc < utca_slots; ++amc ){
478 if( amc >= utca_nconn ){
480 add( seqn++, utca_id, amc, cardch, crp_id, view_na, view_na_ch++, 1);
486 auto conn = utca_conn[ amc ];
487 unsigned islot = (unsigned)std::get<0>(conn);
489 auto kel1_id = std::get<2>(conn);
490 auto kel2_id = std::get<3>(conn);
493 <<
"Mismatch in slot and AMC index: slot " 494 << islot<<
" != amc "<<amc<<
"\n";
499 if( kel1_id < (
int)crp_conn._kels.size() ){
500 auto kel_ = std::next(crp_conn._kels.begin(), kel1_id);
501 if( kel_->_id != kel1_id ) {
503 <<
"Mismatch in KEL1 numbering\n";
506 vector<unsigned> order_ = (kel_->_reverse)? kel_inv : kel_nor;
507 unsigned iview = (unsigned)kel_->_view;
508 unsigned vch_start = (
unsigned)kel_->_first_view_ch;
510 unsigned viewch = vch_start + order_[cardch];
511 add( seqn++, utca_id, amc, cardch, crp_id, iview, viewch, 0);
516 if( kel2_id < (
int)crp_conn._kels.size() ){
517 auto kel_ = std::next(crp_conn._kels.begin(), kel2_id);
518 if( kel_->_id != kel2_id ) {
520 <<
"Mismatch in KEL2 numbering\n";
523 vector<unsigned> order_ = (kel_->_reverse)? kel_inv : kel_nor;
524 unsigned iview = (unsigned)kel_->_view;
525 unsigned vch_start = (
unsigned)kel_->_first_view_ch;
527 unsigned viewch = vch_start + order_[cardch];
528 add( seqn++, utca_id, amc, cardch + dune::tde::ch_per_kel, crp_id, iview, viewch, 0);
void add(unsigned seq, unsigned crate, unsigned card, unsigned cch, unsigned crp, unsigned view, unsigned vch, unsigned short state=0)
void initMap(std::string mapname, unsigned ncrates=1, unsigned ncards=10, unsigned nviews=1)
void add_crp_connection(int icrp, int fslot, const std::vector< int > &kel_ids)
std::vector< tde::ChannelId > find_by_crate(unsigned crate, bool ordered=true) const
void simpleMap(unsigned ncrates, unsigned ncards, unsigned nviews)
tde::ChannelTable chanTable
std::vector< tde::ChannelId > find_by_crp_view(unsigned crp, unsigned view, bool ordered=true) const
unsigned ncards(unsigned crate) const
bool exists(std::string path)
int MapToCRP(int seqch, int &crp, int &view, int &chv) const
void print(std::vector< tde::ChannelId > &vec)
void swap(Handle< T > &a, Handle< T > &b)
struct dune::tde::crate crate
boost::optional< tde::ChannelId > find_by_crate_card_chan(unsigned crate, unsigned card, unsigned chan) const
T get(std::string const &key) const
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
int MapToDAQ(int crp, int view, int chv, int &seqch) const
VDColdboxTDEChannelMapService(fhicl::ParameterSet const &p, art::ActivityRegistry &areg)
Q_EXPORT QTSManip setw(int w)
boost::optional< tde::ChannelId > find_by_seqn(unsigned seqn) const
#define DEFINE_ART_SERVICE(svc)
boost::optional< tde::ChannelId > find_by_crp_view_chan(unsigned crp, unsigned view, unsigned chan) const
std::set< unsigned > crpidx_
std::set< unsigned > crateidx_
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
std::vector< tde::ChannelId > find_by_crate_card(unsigned crate, unsigned card, bool ordered=true) const
std::vector< tde::ChannelId > find_by_crp(unsigned crp, bool ordered=true) const
unsigned nviews(unsigned crp) const
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)