Belle II Software  release-05-01-25
b2klm-numberToIndex.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2020 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Giacomo De Pietro *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 /* KLM headers. */
12 #include <klm/dataobjects/KLMChannelArrayIndex.h>
13 
14 /* Belle 2 headers. */
15 #include <framework/logging/Logger.h>
16 
17 /* C++ headers. */
18 #include <cstdlib>
19 #include <iostream>
20 
21 using namespace Belle2;
22 
23 int main(int argc, char* argv[])
24 {
25  /* Print the usage message if --help or -h are used. */
26  if (argc == 1 or std::string(argv[1]) == "--help" or std::string(argv[1]) == "-h") {
27  std::cout << "Usage: " << argv[0] << " [CHANNEL1] [CHANNEL2] ... [CHANNELN]\n\n"
28  " This tool converts the given channel numbers into the corresponding channel indexes.\n"
29  " A basf2 FATAL message is printed if a channel number does not exist.\n";
30  return 0;
31  }
32  /* Print the error messages when needed. */
33  int nChannels = argc - 1;
34  if (nChannels == 0) {
35  B2ERROR("There are no channels to convert.");
36  return 0;
37  }
38  /* Convert the channel number into the channel index. */
39  const KLMChannelArrayIndex* channelArrayIndex = &(KLMChannelArrayIndex::Instance());
40  for (int i = 1; i <= nChannels; ++i) {
41  uint16_t number = std::atoi(argv[i]);
42  uint16_t index = channelArrayIndex->getIndex(number);
43  B2INFO("Channel number: " << number << " ==> Channel index: " << index);
44  }
45  return 0;
46 }
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::KLMChannelArrayIndex::Instance
static const KLMChannelArrayIndex & Instance()
Instantiation.
Definition: KLMChannelArrayIndex.cc:28
Belle2::KLMChannelArrayIndex
KLM channel array index.
Definition: KLMChannelArrayIndex.h:33
Belle2::KLMElementArrayIndex::getIndex
uint16_t getIndex(uint16_t number) const
Get element index.
Definition: KLMElementArrayIndex.cc:54