BlockIndexMapTool_tool.cc
Go to the documentation of this file.
1 // BlockIndexMapTool_tool.cc
2 
3 #include "BlockIndexMapTool.h"
5 
6 #include <iostream>
7 #include <iomanip>
8 
9 using std::cout;
10 using std::endl;
11 using std::setw;
12 using Name = std::string;
14 
15 //**********************************************************************
16 
18 : m_LogLevel(ps.get<Index>("LogLevel")),
19  m_Starts(ps.get<IndexVector>("Starts")),
20  m_Values(ps.get<IndexVector>("Values")),
21  m_Period(ps.get<Index>("Period")) {
22  const Name myname = "BlockIndexMapTool::ctor: ";
23  // Build teh map.
24  m_map[0] = 0;
25  for ( Index ival=0; ival<m_Starts.size(); ++ival ) {
26  Index idx = m_Starts[ival];
27  Index val = ival < m_Values.size() ? m_Values[ival] : 0;
28  m_map[idx] = val;
29  }
30  // Display the parameters.
31  if ( m_LogLevel >= 1 ) {
32  // Use largest value to set the display width for indices and values.
33  Index imax = 0;
34  for ( Index val : m_Starts ) if ( val > imax ) imax = val;
35  for ( Index val : m_Values ) if ( val > imax ) imax = val;
36  Index wid = 1;
37  Index chk = 1;
38  while ( chk < imax ) {
39  chk *=10;
40  ++wid;
41  }
42  cout << myname << " LogLevel: " << m_LogLevel << endl;
43  cout << myname << " Starts: [";
44  bool first = true;
45  for ( Index val : m_Starts ) {
46  if ( first ) first = false;
47  else cout << ", ";
48  cout << setw(wid) << val;
49  }
50  cout << "]" << endl;
51  cout << myname << " Values: [";
52  first = true;
53  for ( Index val : m_Values ) {
54  if ( first ) first = false;
55  else cout << ", ";
56  cout << setw(wid) << val;
57  }
58  cout << "]" << endl;
59  cout << myname << " Period: " << m_Period << endl;
60  }
61 }
62 
63 //**********************************************************************
64 
66  const Name myname = "BlockIndexMapTool::get: ";
67  Index kcha = m_Period ? icha%m_Period : icha;
68  return (--m_map.upper_bound(kcha))->second;
69 }
70 
71 //**********************************************************************
72 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
ChannelGroupService::Name Name
unsigned int Index
static constexpr double ps
Definition: Units.h:99
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
IndexMapTool::Index Index
int imax
Definition: tracks.py:195
std::vector< Index > IndexVector
BlockIndexMapTool(fhicl::ParameterSet const &ps)
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85
Index get(Index icha) const override
QTextStream & endl(QTextStream &s)