Belle II Software development
b2klm-numberToIndex.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9/* KLM headers. */
10#include <klm/dataobjects/KLMChannelArrayIndex.h>
11
12/* Basf2 headers. */
13#include <framework/logging/Logger.h>
14
15/* C++ headers. */
16#include <cstdlib>
17#include <iostream>
18
19using namespace Belle2;
20
21int main(int argc, char* argv[])
22{
23 /* Print the usage message if --help or -h are used. */
24 if (argc == 1 or std::string(argv[1]) == "--help" or std::string(argv[1]) == "-h") {
25 std::cout << "Usage: " << argv[0] << " [CHANNEL1] [CHANNEL2] ... [CHANNELN]\n\n"
26 " This tool converts the given channel numbers into the corresponding channel indexes.\n"
27 " A basf2 FATAL message is printed if a channel number does not exist.\n";
28 return 0;
29 }
30 /* Print the error messages when needed. */
31 int nChannels = argc - 1;
32 /* cppcheck-suppress knownConditionTrueFalse */
33 if (nChannels == 0) {
34 B2ERROR("There are no channels to convert.");
35 return 0;
36 }
37 /* Convert the channel number into the channel index. */
38 const KLMChannelArrayIndex* channelArrayIndex = &(KLMChannelArrayIndex::Instance());
39 for (int i = 1; i <= nChannels; ++i) {
40 KLMChannelNumber number = std::atoi(argv[i]);
41 uint16_t index = channelArrayIndex->getIndex(number);
42 B2INFO("Channel number: " << number << " ==> Channel index: " << index);
43 }
44 return 0;
45}
KLM channel array index.
static const KLMChannelArrayIndex & Instance()
Instantiation.
uint16_t getIndex(uint16_t number) const
Get element index.
uint16_t KLMChannelNumber
Channel number.
Abstract base class for different kinds of events.