38 #include <boost/range.hpp> 39 #include <boost/range/adaptors.hpp> 67 unsigned ncrateInMap = p.
get<
unsigned>(
"MapCrateNb", 1);
68 unsigned ncardsInMap = p.
get<
unsigned>(
"MapCardNb", 10);
69 unsigned nviewsInMap = p.
get<
unsigned>(
"MapViewNb", 1);
72 initMap( MapName, ncrateInMap, ncardsInMap, nviewsInMap );
82 if(
mapname_.compare( mapname ) == 0 )
90 if( mapname.compare(
"pddp2crp") == 0 )
92 else if( mapname.compare(
"pddp4crp") == 0 )
117 unsigned nctot = ncards *
ncrates;
118 unsigned ncview = nctot /
nviews;
126 for(
unsigned card = 0; card < nctot; card++ )
130 if( card % ncards == 0 ) crate++;
131 if( card % ncview == 0 ) {view++; vch=0;}
133 for(
unsigned ch = 0; ch < nch; ch++ )
135 add( seqn++, crate, card % ncards, ch, crp, view, vch++);
148 std::vector<unsigned> cards_per_crate_real{5, 5, 5, 10, 5, 5, 10, 10, 10, 5};
150 std::vector<unsigned> cards_per_crate(ncrates, 10);
152 unsigned nchc = nch/2;
154 std::vector<unsigned> crpv(2*ncrp, 0);
157 std::vector<unsigned> dunetpcno = {3, 1, 0, 2};
164 std::vector<unsigned> kel_nor = { 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24 };
166 std::vector<unsigned> kel_inv = {24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7 };
175 for(
unsigned card = 0;card<
ncards;card++ )
178 if(
crate < 6 ) view = 0;
185 if( card >= 5 ) crp = 2;
190 if( card >= 5 ) crp = 3;
195 if( card >= 5 ) crp = 1;
200 if( card >= 5 ) crp = 2;
206 bool topAmcFirst =
true;
213 auto vchIt = crpv.begin() + view * ncrp + crp;
216 *vchIt = *vchIt + nchc;
219 for(
unsigned ch = cstart; ch<cstart+nchc; ch++ )
221 int idx = ch - cstart;
222 if( idx < 0 || idx >= (
int)kel.size() )
225 std::cerr<<
"I screwed this up\n";
229 unsigned vch = *vchIt + kel[ idx ];
232 int ival = -vch + 959;
235 std::cerr<<
"Bad view channel number\n";
238 vch = (unsigned)ival;
244 if(
crate >= cards_per_crate_real.size() )
250 if( card >= cards_per_crate_real[
crate ] )
255 unsigned tpc = dunetpcno[ crp ];
256 unsigned kview = (view == 0 ) ? 1:0;
257 add( seqn++,
crate, card, ch, tpc, kview, vch, state );
261 *vchIt = *vchIt - nchc;
263 *vchIt = *vchIt + nchc;
267 for(
unsigned ch = cstart; ch<cstart+nchc; ch++ )
269 int idx = ch - cstart;
270 if( idx < 0 || idx >= (
int)kel.size() )
273 std::cerr<<
"I screwed this up\n";
277 unsigned vch = *vchIt + kel[ idx ];
280 int ival = -vch + 959;
283 std::cerr<<
"Bad view channel number\n";
286 vch = (unsigned)ival;
292 if(
crate >= cards_per_crate_real.size() )
298 if( card >= cards_per_crate_real[
crate ] )
303 unsigned tpc = dunetpcno[ crp ];
304 unsigned kview = (view == 0 ) ? 1:0;
305 add( seqn++,
crate, card, ch, tpc, kview, vch, state );
311 *vchIt = *vchIt + nch;
313 *vchIt = *vchIt + nchc;
329 std::vector<unsigned> cards_per_crate(ncrates, 10);
332 std::vector<unsigned> crpv(2*ncrp, 0);
341 for(
unsigned card = 0;card<
ncards;card++ )
344 if(
crate < 6 ) view = 0;
351 if( card >= 5 ) crp = 2;
356 if( card >= 5 ) crp = 3;
361 if( card >= 5 ) crp = 1;
366 if( card >= 5 ) crp = 2;
371 auto vchIt = crpv.begin() + view * ncrp + crp;
382 for(
unsigned ch = 0; ch<nch; ch++ )
384 if( ch == nch/2 ) *vchIt = *vchIt + nch/2;
385 int tmp = apara * (ch % 32) + bpara;
388 std::cerr<<
"oh oh I screwed up\n";
392 unsigned vch = *vchIt +
tmp;
393 add( seqn++,
crate, card, ch, crp, view, vch );
396 *vchIt = *vchIt + nch/2;
406 unsigned crp,
unsigned view,
unsigned vch,
unsigned short state )
439 return boost::optional<DPChannelId>();
448 std::vector<DPChannelId> res;
452 if( boost::optional<DPChannelId>
id =
find_by_seqn( from ) )
453 res.push_back( *
id );
462 res.insert( res.begin(), first, last );
475 std::vector<DPChannelId> res(
r.first,
r.second);
480 std::vector<DPChannelId> res(
r.first,
r.second);
492 std::vector<DPChannelId> res(
r.first,
r.second);
498 std::vector<DPChannelId> res(
r.first,
r.second);
506 unsigned card,
unsigned chan )
const 512 return boost::optional<DPChannelId>();
522 std::vector<DPChannelId> res(
r.first,
r.second);
527 std::vector<DPChannelId> res(
r.first,
r.second);
539 std::vector<DPChannelId> res(
r.first,
r.second);
545 std::vector<DPChannelId> res(
r.first,
r.second);
552 unsigned view,
unsigned chan )
const 558 return boost::optional<DPChannelId>();
565 crp = view = chv = -1;
566 if( boost::optional<DPChannelId>
id =
find_by_seqn( (
unsigned)seqch ) )
568 if( !id->exists() )
return -1;
583 if( boost::optional<DPChannelId>
id =
find_by_crp_view_chan( (
unsigned)crp, (
unsigned)view, (
unsigned)chv ) )
585 if( !id->exists() )
return -1;
600 for(
DPChannelId const &ch : boost::make_iterator_range(
r ) )
602 if( !ch.exists() )
continue;
603 unsigned val = ch.card();
622 for(
DPChannelId const &ch : boost::make_iterator_range(
r ) )
624 if( !ch.exists() )
continue;
625 unsigned val = ch.view();
640 for(
auto it = vec.begin();it!=vec.end();++it )
642 unsigned seqn = it->seqn();
644 unsigned card = it->card();
645 unsigned cch = it->cardch();
646 unsigned crp = it->crp();
647 unsigned view = it->view();
648 unsigned vch = it->viewch();
649 unsigned state = it->state();
650 bool exists = it->exists();
int MapToDAQ(int crp, int view, int chv, int &seqch) const
boost::optional< DPChannelId > find_by_seqn(unsigned seqn) const
int MapToCRP(int seqch, int &crp, int &view, int &chv) const
PDDPChannelMap(fhicl::ParameterSet const &p, art::ActivityRegistry &areg)
std::set< unsigned > crateidx_
void simpleMap(unsigned ncrates, unsigned ncards, unsigned nviews)
std::vector< DPChannelId > find_by_crate_card(unsigned crate, unsigned card, bool ordered=true) const
unsigned ncards(unsigned crate) const
std::vector< DPChannelId > find_by_crp_view(unsigned crp, unsigned view, bool ordered=true) const
bool exists(std::string path)
unsigned nviews(unsigned crp) const
void add(unsigned seq, unsigned crate, unsigned card, unsigned cch, unsigned crp, unsigned view, unsigned vch, unsigned short state=0)
void swap(Handle< T > &a, Handle< T > &b)
std::vector< DPChannelId > find_by_crate(unsigned crate, bool ordered=true) const
struct dune::tde::crate crate
void initMap(std::string mapname, unsigned ncrates=1, unsigned ncards=10, unsigned nviews=1)
T get(std::string const &key) const
void print(std::vector< DPChannelId > &vec)
Q_EXPORT QTSManip setw(int w)
boost::optional< DPChannelId > find_by_crp_view_chan(unsigned crp, unsigned view, unsigned chan) const
#define DEFINE_ART_SERVICE(svc)
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
std::set< unsigned > crpidx_
boost::optional< DPChannelId > find_by_crate_card_chan(unsigned crate, unsigned card, unsigned chan) const
std::vector< DPChannelId > find_by_crp(unsigned crp, bool ordered=true) const
QTextStream & endl(QTextStream &s)