All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PMTChannelMapDumper.cxx
Go to the documentation of this file.
1 /**
2  * @file icaruscode/Decode/ChannelMapping/PMTChannelMapDumper.cxx
3  * @brief Utility dumping the content of PMT channel mapping on screen.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  *
6  * This utility can be run with any configuration file including a configuration
7  * for `IICARUSChannel` service.
8  *
9  * It is using _art_ facilities for tool loading, but it does not run in _art_
10  * environment. So it may break without warning and without solution.
11  *
12  */
13 
14 
15 // ICARUS libraries
17 
18 // LArSoft and framework libraries
21 #include "messagefacility/MessageLogger/MessageLogger.h"
22 // #include "cetlib_except/exception.h"
23 
24 // C/C++ standard libraries
25 #include <iomanip> // std::setw()
26 #include <iostream>
27 #include <algorithm>
28 #include <numeric> // std::iota()
29 #include <array>
30 
31 
32 // -----------------------------------------------------------------------------
33 template <std::size_t KeyNo = 0U>
34 struct SortByElement {
35 
36  template <typename TupleA, typename TupleB>
37  bool operator() (TupleA const& A, TupleB const& B) const
38  { return less(A, B); }
39 
40  template <typename Tuple>
41  static decltype(auto) key(Tuple const& t) { return std::get<KeyNo>(t); }
42 
43  template <typename TupleA, typename TupleB>
44  static bool less(TupleA const& A, TupleB const& B)
45  { using std::less; return less{}(key(A), key(B)); }
46 
47 }; // SortByElement<>
48 
49 
50 // -----------------------------------------------------------------------------
51 int main(int argc, char** argv) {
52 
53  using Environment
55 
56  testing::BasicEnvironmentConfiguration config("PMTchannelMappingDumper");
57 
58  //
59  // parameter parsing
60  //
61  int iParam = 0;
62 
63  // first argument: configuration file (mandatory)
64  if (++iParam < argc)
65  config.SetConfigurationPath(argv[iParam]);
66  else {
67  std::cerr << "FHiCL configuration file path required as first argument!"
68  << std::endl;
69  return 1;
70  }
71 
72  Environment const Env { config };
73 
74  icarusDB::ICARUSChannelMapProvider const channelMapping
75  { Env.ServiceParameters("IICARUSChannelMap") };
76 
77  // hard-coded list of fragment ID; don't like it?
78  // ask for an extension of the channel mapping features.
79  std::array<unsigned int, 24U> FragmentIDs;
80  std::iota(FragmentIDs.begin(), FragmentIDs.end(), 0x2000);
81 
82  mf::LogVerbatim("PMTchannelMappingDumper") << "Fragment IDs:";
83  for (auto const [ iFragment, fragmentID]: util::enumerate(FragmentIDs)) {
84  unsigned int const effFragmentID = fragmentID & 0xFF;
85 
86  if (!channelMapping.hasPMTDigitizerID(effFragmentID)) {
87  mf::LogVerbatim("PMTchannelMappingDumper")
88  << "[" << iFragment << "] " << std::hex << fragmentID << std::dec
89  << " not found in the database (as "
90  << std::hex << effFragmentID << std::dec << ")";
91  continue;
92  }
93 
95  = channelMapping.getChannelIDPairVec(effFragmentID);
96 
97  std::sort
98  (digitizerChannels.begin(), digitizerChannels.end(), SortByElement<1U>{});
99 
100 
101  mf::LogVerbatim log("PMTchannelMappingDumper");
102  log
103  << "[" << iFragment << "] " << std::hex << fragmentID << std::dec
104  << " includes " << digitizerChannels.size()
105  << " LArSoft channels between " << digitizerChannels.front().second
106  << " and " << digitizerChannels.back().second
107  << " [board channel index in brackets]:";
108  constexpr unsigned int Cols = 8U;
109  unsigned int n = 0;
110  for(auto const [ digitizerChannel, channelID ]: digitizerChannels) {
111  if (n-- == 0) { log << "\n "; n = Cols - 1U; }
112  log << " " << std::setw(3) << channelID
113  << " [" << std::setw(3) << digitizerChannel << "]";
114  } // for channel
115 
116  } // for fragment
117 
118  return 0;
119 } // main()
120 
121 
BEGIN_PROLOG or simple_flux see Environment
Definition: genie.fcl:8
std::vector< DigitizerChannelChannelIDPair > DigitizerChannelChannelIDPairVec
static decltype(auto) key(Tuple const &t)
BEGIN_PROLOG could also be cerr
Definition of util::enumerate().
Class holding a configuration for a test environment.
void * Tuple
Definition: DBFolder.h:13
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
bool operator()(TupleA const &A, TupleB const &B) const
const DigitizerChannelChannelIDPairVec & getChannelIDPairVec(const unsigned int) const override
A test environment with some support for service providers.
void SetConfigurationPath(std::string path)
Sets the path to the configuration file.
static bool less(TupleA const &A, TupleB const &B)
int main(int argc, char **argv)
Base class for unit tests using FHiCL configuration.
float A
Definition: dedx.py:137