ProtoDuneChannelRanges_tool.cc
Go to the documentation of this file.
1 // ProtoDuneChannelRanges_tool.cc
2 
5 #include <iostream>
6 #include <sstream>
7 #include <iomanip>
8 
9 using std::cout;
10 using std::endl;
11 using std::string;
12 using std::ostringstream;
13 using std::istringstream;
14 using std::setw;
15 using std::setfill;
18 using IndexVector = std::vector<Index>;
19 
20 //**********************************************************************
21 
23 : m_LogLevel(ps.get<Index>("LogLevel")),
24  m_ExtraRanges(ps.get<Name>("ExtraRanges")) {
25  const Name myname = "ProtoDuneChannelRanges::ctor: ";
26  const Index ntps = 6;
27  Index nchaApa = 2560;
28  Index nfchau = 40;
29  Index nfchav = 40;
30  Index nfchax = 48;
31  Index nchau = 800;
32  Index nchav = 800;
33  Index nchaz = 480;
34  Index nchax = 2*nchaz;
35  Index nchai = nchau + nchav;
36  Index apaIdx[ntps] = {3, 5, 2, 6, 1, 4}; // Installation order.
37  string slocs[ntps] = {"US-RaS", "US-DaS", "MS-RaS", "MS-DaS", "DS-RaS", "DS-DaS"};
38  insertLen("all", 0, ntps*nchaApa, "All", "", "");
39  for ( Index itps=0; itps<ntps; ++itps ) {
40  string sitps = std::to_string(itps);
41  string siapa = std::to_string(apaIdx[itps]);
42  string labTps = "TPC set " + sitps;
43  string labApa = "APA " + siapa;
44  string sloc = slocs[itps];
45  Index ch0 = itps*nchaApa;
46  string stps = "tps" + sitps;
47  string sapa = "apa" + siapa;
48  insertLen( stps, ch0, nchaApa, labTps, sloc, labApa);
49  insertLen( sapa, ch0, nchaApa, labApa, sloc);
50  string stpp = "tpp" + sitps;
51  Index chu0 = ch0;
52  Index chv0 = chu0 + nchau;
53  Index chx10 = chv0 + nchav;
54  Index chx20 = chx10 + nchaz;
55  Index chx0 = chx10;
56  bool beamRight = 2*(itps/2) == itps;
57  Index chz0 = beamRight ? chx20 : chx10;
58  Index chc0 = beamRight ? chx10 : chx20;
59  insertLen(stpp + "u", chu0, nchau, "TPC plane " + sitps + "u", sloc, labApa);
60  insertLen(sapa + "u", chu0, nchau, "APA plane " + siapa + "u", sloc);
61  insertLen(stpp + "v", chv0, nchav, "TPC plane " + sitps + "v", sloc, labApa);
62  insertLen(sapa + "v", chv0, nchav, "APA plane " + siapa + "v", sloc);
63  insertLen(stpp + "c", chc0, nchaz, "TPC plane " + sitps + "c", sloc, labApa);
64  insertLen(sapa + "c", chc0, nchaz, "APA plane " + siapa + "c", sloc);
65  insertLen(stpp + "z", chz0, nchaz, "TPC plane " + sitps + "z", sloc, labApa);
66  insertLen(sapa + "z", chz0, nchaz, "APA plane " + siapa + "z", sloc);
67  insertLen(stpp + "i", chu0, nchai, "TPC plane " + sitps + "i", sloc, labApa);
68  insertLen(sapa + "i", chu0, nchai, "APA plane " + siapa + "i", sloc);
69  insertLen(stpp + "x", chx0, nchax, "TPC plane " + sitps + "x", sloc, labApa);
70  insertLen(sapa + "x", chx0, nchax, "APA plane " + siapa + "x", sloc);
71  Index fchu0 = chu0;
72  Index fchv0 = chv0;
73  Index fchx0 = chx10;
74  Index ifmbu = 11;
75  Index ifmbv = 20;
76  Index ifmbx = 20;
77  // Loop over FEMBS in offline order.
78  for ( Index ifmbOff=0; ifmbOff<20; ++ifmbOff ) {
79  ostringstream ssnamu;
80  ssnamu << siapa << setfill('0') << setw(2) << ifmbu << "u";
81  string namu = ssnamu.str();
82  insertLen("femb" + namu, fchu0, nfchau, "FEMB block " + namu, sloc);
83  ostringstream ssnamv;
84  ssnamv << siapa << setfill('0') << setw(2) << ifmbv << "v";
85  string namv = ssnamv.str();
86  insertLen("femb" + namv, fchv0, nfchav, "FEMB block " + namv, sloc);
87  ostringstream ssnamx;
88  ssnamx << siapa << setfill('0') << setw(2) << ifmbx << "x";
89  string namx = ssnamx.str();
90  insertLen("femb" + namx, fchx0, nfchax, "FEMB block " + namx, sloc);
91  fchu0 += nfchau;
92  fchv0 += nfchav;
93  fchx0 += nfchax;
94  ifmbu += 1;
95  if ( ifmbu > 20 ) ifmbu = 1;
96  ifmbv -= 1;
97  if ( ifmbv == 0 ) ifmbv = 20;
98  if ( ifmbOff < 9 ) ifmbx -= 1;
99  else if ( ifmbOff == 9 ) ifmbx = 1;
100  else ifmbx += 1;
101 
102  }
103  }
104  if ( m_ExtraRanges.size() ) {
107  if ( m_pExtraRanges == nullptr ) {
108  cout << myname << "WARNING: Extra range tool not found: " << m_ExtraRanges << endl;
109  }
110  }
111  if ( m_LogLevel >= 1 ) {
112  cout << myname << " LogLevel: " << m_LogLevel << endl;
113  cout << myname << " Extra range tool: " << m_ExtraRanges << endl;
114  }
115 }
116 
117 //**********************************************************************
118 
120  const Name myname = "ProtoDuneChannelRanges::runData: ";
121  if ( m_pExtraRanges != nullptr ) {
122  IndexRange rout = m_pExtraRanges->get(nam);
123  if ( rout.isValid() ) return rout;
124  }
125  // Special handling for online wire specifier fembAFFVCC
126  // We look up FEMB block fembAFFV and pick the channel corresponding to CC,
127  if ( nam.size() == 10 && nam.substr(0,4) == "femb" ) {
128  IndexRange fbran = get(nam.substr(0,8));
129  Index ifchmax = 0;
130  if ( fbran.isValid() ) {
131  char cpla = nam[7];
132  bool dirSame = true; // Is channel numbering dir same in FEMB and offline?
133  if ( cpla == 'u' ) {
134  ifchmax = 40;
135  dirSame = false;
136  } else if ( cpla == 'v' ) {
137  ifchmax = 40;
138  } else if ( cpla == 'x' || cpla == 'w') {
139  ifchmax = 48;
140  istringstream ssapa(nam.substr(4,1));
141  int iapa = 0;
142  ssapa >> iapa;
143  istringstream ssfmb(nam.substr(5,2));
144  int ifmb = 0;
145  ssfmb >> ifmb;
146  bool beamL = ifmb >= 1 && ifmb <= 10;
147  bool beamR = ifmb >= 11 && ifmb <= 20;
148  if ( beamL ) dirSame = false;
149  else if ( beamR ) dirSame = true;
150  else ifchmax = 0;
151  }
152  if ( ifchmax != fbran.size() ) {
153  cout << myname << "WARNING: FEMB block has unexpected size: "
154  << ifchmax << " != " << fbran.size() << endl;
155  ifchmax = 0;
156  }
157  string sch = nam.substr(8,2);
158  istringstream ssfch(sch);
159  Index ifch;
160  ssfch >> ifch;
161  if ( ifch > 0 && ifch <= ifchmax ) {
162  if ( dirSame ) --ifch;
163  else ifch = ifchmax - ifch;
164  Index ich = fbran.begin + ifch;
165  return IndexRange(nam, ich, ich+1, fbran.label(0) + sch, fbran.label(1));
166  }
167  }
168  }
169  IndexRangeMap::const_iterator iran = m_Ranges.find(nam);
170  if ( iran == m_Ranges.end() ) return IndexRange();
171  return iran->second;
172 }
173 
174 //**********************************************************************
175 
177 insertLen(Name nam, Index begin, Index len, Name lab, Name lab1, Name lab2) {
178  m_Ranges[nam] = IndexRange(nam, begin, begin+len, lab, lab1, lab2);
179 }
180 
181 //**********************************************************************
182 
const IndexRangeTool * m_pExtraRanges
std::vector< Index > IndexVector
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
IndexRange get(Name nam) const override
std::string string
Definition: nybbler.cc:12
Index begin
Definition: IndexRange.h:34
ChannelGroupService::Name Name
void insertLen(Name nam, Index begin, Index len, Name lab, Name lab1="", Name lab2="")
Index size() const
Definition: IndexRange.h:88
intermediate_table::const_iterator const_iterator
unsigned int Index
bool isValid() const
Definition: IndexRange.h:94
IndexRange::Name Name
static constexpr double ps
Definition: Units.h:99
Name label(Index ilab=0) const
Definition: IndexRange.h:106
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
ProtoDuneChannelRanges(fhicl::ParameterSet const &ps)
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
static DuneToolManager * instance(std::string fclname="", int dbg=1)
T * getShared(std::string name)
QTextStream & endl(QTextStream &s)
virtual IndexRange get(Name nam) const =0