ApaChannelGroups_tool.cc
Go to the documentation of this file.
1 // ApaChannelGroups_tool.cc
2 
3 #include "ApaChannelGroups.h"
6 #include <iostream>
7 #include <sstream>
8 #include <iomanip>
9 
10 using std::cout;
11 using std::endl;
12 using std::string;
13 using std::ostringstream;
14 using std::istringstream;
15 using std::setw;
16 using std::setfill;
18 using NameVector = std::vector<Name>;
20 using IndexVector = std::vector<Index>;
21 
22 //**********************************************************************
23 
25 : m_LogLevel(ps.get<Index>("LogLevel")),
26  m_ApaNumbers(ps.get<IndexVector>("ApaNumbers")),
27  m_IndexRangeTool(ps.get<Name>("IndexRangeTool")) {
28  const Name myname = "ApaChannelGroups::ctor: ";
29  if ( m_IndexRangeTool.size() ) {
32  if ( m_pIndexRangeTool == nullptr ) {
33  cout << myname << "WARNING: Index range tool not found: " << m_IndexRangeTool << endl;
34  }
35  } else {
36  cout << myname << "WARNING: No Index range tool name." << endl;
37  }
38  Index napa = m_ApaNumbers.size();
39  // If the APA list is empty, the detector has one unnumbered APA.
40  bool singleApa = napa == 0;
41  if ( singleApa ) {
42  napa = 1;
43  }
44  m_labels["tpss"].push_back("TPC sets");
45  m_labels["apas"].push_back("APAs");
46  NameVector soris = {"z", "c", "x", "u", "v", "i", "z1", "z2"};
47  for ( Name sori : soris ) {
48  m_labels["tpp" + sori + "s"].push_back(sori + " planes");
49  m_labels["apa" + sori + "s"].push_back(sori + " planes");
50  }
51  for ( Index itps=0; itps<napa; ++itps ) {
52  ostringstream sstps;
53  Name stps;
54  Name sapa;
55  if ( ! singleApa ) {
56  sstps << itps;
57  stps = sstps.str();
58  Index iapa = m_ApaNumbers[itps];
59  ostringstream ssapa;
60  ssapa << iapa;
61  sapa = ssapa.str();
62  }
63  m_groups["tpss"].push_back("tps" + stps);
64  m_groups["apas"].push_back("apa" + sapa);
65  for ( Name sori : soris ) {
66  m_groups["tpp" + sori + "s"].push_back("tpp" + stps + sori);
67  m_groups["apa" + sori + "s"].push_back("apa" + sapa + sori);
68  }
69  }
70  Index nfmb = 20;
71  for ( Index itps=0; itps<napa; ++itps ) {
72  Name sapa;
73  if ( ! singleApa ) {
74  Index iapa = m_ApaNumbers[itps];
75  ostringstream ssapa;
76  ssapa << iapa;
77  sapa = ssapa.str();
78  }
79  for ( Index ifmb=1; ifmb<=nfmb; ++ifmb ) {
80  ostringstream ssgrp;
81  ssgrp << "femb" << sapa;
82  if ( ifmb < 10 ) ssgrp << "0";
83  ssgrp << ifmb;
84  Name sgrp = ssgrp.str();
85  m_groups[sgrp].push_back(sgrp + "u");
86  m_groups[sgrp].push_back(sgrp + "v");
87  m_groups[sgrp].push_back(sgrp + "x");
88  Name slab = "FEMB " + sgrp.substr(4);
89  m_labels[sgrp].push_back(slab);
90  }
91  }
92  if ( m_LogLevel >= 1 ) {
93  cout << myname << " LogLevel: " << m_LogLevel << endl;
94  }
95 }
96 
97 //**********************************************************************
98 
100  const Name myname = "ApaChannelGroups::get: ";
101  if ( nam == "list" ) {
102  IndexVector grps;
103  cout << myname << "Available groups: ";
104  bool first = true;
105  for ( const auto& igrp : m_groups ) {
106  if ( first ) first = false;
107  else cout << ", ";
108  cout << igrp.first;
109  }
110  cout << endl;
111  return IndexRangeGroup();
112  }
113  if ( m_pIndexRangeTool == nullptr ) {
114  if ( m_LogLevel >= 2 ) cout << myname << "No IndexRangeTool." << endl;
115  return IndexRangeGroup();
116  }
117  GroupMap::const_iterator igrp = m_groups.find(nam);
118  if ( igrp == m_groups.end() ) {
119  if ( m_LogLevel >= 2 ) cout << myname << "Invalid group name: " << nam << endl;
120  return IndexRangeGroup();
121  }
123  for ( Name rnam : igrp->second ) {
124  rans.push_back(m_pIndexRangeTool->get(rnam));
125  }
126  NameVector labs;
127  GroupMap::const_iterator ilabs = m_labels.find(nam);
128  if ( ilabs == m_labels.end() ) return IndexRangeGroup(nam, rans);
129  return IndexRangeGroup(nam, ilabs->second, rans);
130 }
131 
132 //**********************************************************************
133 
const IndexRangeTool * m_pIndexRangeTool
std::vector< Index > IndexVector
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
std::vector< IndexRange > RangeVector
IndexRangeGroup::Index Index
ChannelGroupService::Name Name
intermediate_table::const_iterator const_iterator
IndexRangeGroup get(Name nam) const override
unsigned int Index
ApaChannelGroups(fhicl::ParameterSet const &ps)
std::vector< Index > IndexVector
IndexVector m_ApaNumbers
static constexpr double ps
Definition: Units.h:99
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::vector< Name > NameVector
std::vector< string > NameVector
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
IndexRangeGroup::Name Name
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