Dune35tChannelGroupService_service.cc
Go to the documentation of this file.
1 // Dune35tChannelGroupService.cxx
2 
4 #include <sstream>
5 #include <iomanip>
6 
7 using std::cout;
8 using std::ostream;
9 using std::endl;
10 using std::string;
11 using std::ostringstream;
12 using std::setfill;
13 using std::setw;
14 using std::vector;
15 
19 typedef vector<ChannelVector> ChannelVectorVector;
20 typedef vector<ChannelVectorVector> ChannelVectorVectorVector;
21 
22 //**********************************************************************
23 
26 : m_UseOffline(true), m_LogLevel(1) {
27  const string myname = "Dune35tChannelGroupService::ctor: ";
28  const Index nAsicPerRce = 8;
29  const Index nRegPerRce = 2;
30  const string plname[4] = {"u", "v", "z1", "z2"};
31  // Fetch parameters.
32  m_UseOffline = pset.get<bool>("UseOffline");
33  m_SplitByPlane = pset.get<bool>("SplitByPlane");
34  m_Grouping = pset.get<string>("Grouping");
35  pset.get_if_present<int>("LogLevel", m_LogLevel);
36  const Index ncha = 2048;
37  bool useAPA = m_Grouping == "APA";
38  bool useASIC = m_Grouping == "ASIC";
39  bool useRegulator = m_Grouping == "Regulator";
40  bool split = m_SplitByPlane;
41  bool off = m_UseOffline;
42  Index ngrp = 0;
44  Index npla = split ? 4 : 1;
45  for ( Index icha=0; icha<ncha; ++icha ) {
46  Index igrp = 9999;
47  Index chon = off ? m_pcms->Online(icha) : icha;
48  Index irce = m_pcms->RCEFromOnlineChannel(chon);
49  Index ipla = m_pcms->PlaneFromOnlineChannel(chon);
50  if ( useAPA ) {
51  igrp = m_pcms->APAFromOnlineChannel(chon);
52  } else if ( useASIC ) {
53  Index iasc = m_pcms->ASICFromOnlineChannel(chon);
54  igrp = nAsicPerRce*irce + iasc;
55  } else if ( useRegulator ) {
56  Index ireg = m_pcms->RegulatorFromOnlineChannel(chon);
57  igrp = nRegPerRce*irce + ireg;
58  } else {
59  cout << myname << "ERROR: Invalid group name: " << m_Grouping << endl;
60  return;
61  }
62  if ( igrp >= ngrp ) {
63  ngrp = igrp + 1;
64  vvvchans.resize(ngrp, ChannelVectorVector(npla));
65  }
66  Index iview = split ? ipla : 0;
67  vvvchans[igrp][iview].push_back(icha);
68  }
69  Name base = useAPA ? "apa" :
70  useASIC ? "asic" :
71  useRegulator ? "reg" : "Unknown";
72  //if ( useAPA ) base = "apa";
73  //if ( useASIC ) base = "asic";
74  //if ( useRegulator ) base = "reg";
75  for ( Index igrp=0; igrp<ngrp; ++igrp ) {
76  for ( Index ipla=0; ipla<npla; ++ipla ) {
77  ChannelVector& chans = vvvchans[igrp][ipla];
78  if ( chans.size() ) {
79  ostringstream ssnam;
80  ssnam << base;
81  if ( ngrp > 100 && igrp < 100 ) ssnam << "0";
82  if ( ngrp > 10 && igrp < 10 ) ssnam << "0";
83  ssnam << igrp;
84  if ( split ) ssnam << plname[ipla];
85  m_names.push_back(ssnam.str());
86  m_chanvecs.push_back(chans);
87  }
88  }
89  }
90  if ( m_LogLevel > 0 ) print();
91 }
92 
93 //**********************************************************************
94 
98 
99 //**********************************************************************
100 
102  return m_chanvecs.size();
103 }
104 
105 //**********************************************************************
106 
108  if ( igrp < m_names.size() ) return m_names[igrp];
109  return "NoSuchGroup";
110 }
111 
112 //**********************************************************************
113 
115  if ( igrp < m_chanvecs.size() ) return m_chanvecs[igrp];
116  static ChannelVector empty;
117  return empty;
118 }
119 
120 //**********************************************************************
121 
122 ostream& Dune35tChannelGroupService::print(ostream& out, string prefix) const {
123  out << prefix << "Dune35tChannelGroupService: " << endl;
124  out << prefix << " UseOffline: " << ( m_UseOffline ? "true" : "false") << endl;
125  out << prefix << " Grouping: " << m_Grouping << endl;
126  out << prefix << " SplitByPlane: " << m_SplitByPlane << endl;
127  out << prefix << " # groups: " << size() << endl;
128  out << prefix << " LogLevel: " << m_LogLevel << endl;
129  return out;
130 }
131 
132 //**********************************************************************
133 
135 
136 //**********************************************************************
Dune35tChannelGroupService(fhicl::ParameterSet const &pset)
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)
std::string string
Definition: nybbler.cc:12
struct vector vector
vector< ChannelVectorVector > ChannelVectorVectorVector
art::ServiceHandle< lbne::ChannelMapService > m_pcms
T get(std::string const &key) const
Definition: ParameterSet.h:231
bool get_if_present(std::string const &key, T &value) const
Definition: ParameterSet.h:208
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
vector< ChannelVector > ChannelVectorVector
ChannelGroupService::Index Index
ChannelGroupService::ChannelVector ChannelVector
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
std::vector< ChannelVector > ChannelVectorVector
ChannelGroupService::Name Name
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
const ChannelVector & channels(Index igrp) const
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
QTextStream & endl(QTextStream &s)
std::vector< Channel > ChannelVector