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