|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// \file ProgramTriggerMonitor.cxx |
| 12 | +/// \brief Tool that returns monitoring information about LTU triggers. |
| 13 | +/// |
| 14 | +/// \author Kostas Alexopoulos ([email protected]) |
| 15 | + |
| 16 | +#include <iostream> |
| 17 | +#include "Cru/CruBar.h" |
| 18 | +#include "ReadoutCard/ChannelFactory.h" |
| 19 | +#include "CommandLineUtilities/Options.h" |
| 20 | +#include "CommandLineUtilities/Program.h" |
| 21 | +#include <boost/format.hpp> |
| 22 | +#include <boost/property_tree/ptree.hpp> |
| 23 | + |
| 24 | +using namespace AliceO2::roc::CommandLineUtilities; |
| 25 | +using namespace AliceO2::roc; |
| 26 | +using namespace AliceO2::InfoLogger; |
| 27 | +namespace pt = boost::property_tree; |
| 28 | +namespace po = boost::program_options; |
| 29 | + |
| 30 | +class ProgramTriggerMonitor : public Program |
| 31 | +{ |
| 32 | + public: |
| 33 | + virtual Description getDescription() |
| 34 | + { |
| 35 | + return { "Trigger Monitor", "Return LTU trigger monitoring information", |
| 36 | + "roc-pkt-monitor --id 42:00.0\n" |
| 37 | + "roc-pkt-monitor --id 42:00.0 --updateable\n" }; |
| 38 | + } |
| 39 | + |
| 40 | + virtual void addOptions(boost::program_options::options_description& options) |
| 41 | + { |
| 42 | + Options::addOptionCardId(options); |
| 43 | + options.add_options()("updateable", |
| 44 | + po::bool_switch(&mOptions.updateable), |
| 45 | + "Toggle updateable output"); |
| 46 | + } |
| 47 | + |
| 48 | + virtual void run(const boost::program_options::variables_map& map) |
| 49 | + { |
| 50 | + |
| 51 | + auto cardId = Options::getOptionCardId(map); |
| 52 | + Parameters params; |
| 53 | + std::shared_ptr<BarInterface> bar; |
| 54 | + auto card = RocPciDevice(cardId).getCardDescriptor(); |
| 55 | + auto cardType = card.cardType; |
| 56 | + |
| 57 | + if (card.serialId.getSerial() == 0x7fffffff || card.serialId.getSerial() == 0x0) { |
| 58 | + std::cout << "Bad serial reported, bad card state, exiting" << std::endl; |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + if (cardType == CardType::type::Crorc) { |
| 63 | + std::cout << "Only CRU supported, exiting" << std::endl; |
| 64 | + return; |
| 65 | + } else if (cardType == CardType::type::Cru) { |
| 66 | + |
| 67 | + params = Parameters::makeParameters(cardId, 2); //status available on BAR2 |
| 68 | + bar = ChannelFactory().getBar(params); |
| 69 | + auto cruBar2 = std::dynamic_pointer_cast<CruBar>(bar); |
| 70 | + |
| 71 | + std::ostringstream table; |
| 72 | + auto formatHeader = " %-12s %-15s %-12s %-15s %-12s %-12s\n"; |
| 73 | + auto formatRow = " %-12s %-15.3f %-12s %-15.3f %-12s %-12s\n"; |
| 74 | + auto formatRowUpdateable = " %-12s %-15.3f %-12s %-15.3f %-12s %-12s"; |
| 75 | + auto header = (boost::format(formatHeader) % "HB" % "HB rate (kHz)" % "PHY" % "PHY rate (kHz)" % "SOX" % "EOX").str(); |
| 76 | + auto lineFat = std::string(header.length(), '=') + '\n'; |
| 77 | + auto lineThin = std::string(header.length(), '-') + '\n'; |
| 78 | + |
| 79 | + table << lineFat << header << lineThin; |
| 80 | + |
| 81 | + // initialize ptrees |
| 82 | + pt::ptree root; |
| 83 | + pt::ptree gbtLinks; |
| 84 | + |
| 85 | + if (mOptions.updateable) { |
| 86 | + std::cout << table.str(); // header |
| 87 | + |
| 88 | + while (!isSigInt()) { |
| 89 | + Cru::TriggerMonitoringInfo tmi = cruBar2->monitorTriggers(true); |
| 90 | + auto format = boost::format(formatRowUpdateable) % tmi.hbCount % tmi.hbRate % tmi.phyCount % tmi.phyRate % tmi.soxCount % tmi.eoxCount; |
| 91 | + std::cout << '\r' << format << std::flush; |
| 92 | + } |
| 93 | + |
| 94 | + std::cout << std::endl << lineFat; |
| 95 | + } else { |
| 96 | + Cru::TriggerMonitoringInfo tmi = cruBar2->monitorTriggers(); |
| 97 | + auto format = boost::format(formatRow) % tmi.hbCount % tmi.hbRate % tmi.phyCount % tmi.phyRate % tmi.soxCount % tmi.eoxCount; |
| 98 | + table << format << lineFat; |
| 99 | + std::cout << table.str(); |
| 100 | + } |
| 101 | + |
| 102 | + } else if (cardType != CardType::type::Cru) { |
| 103 | + std::cout << "Invalid card type" << std::endl; |
| 104 | + return; |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + private: |
| 109 | + struct OptionsStruct { |
| 110 | + bool updateable = false; |
| 111 | + } mOptions; |
| 112 | +}; |
| 113 | + |
| 114 | +int main(int argc, char** argv) |
| 115 | +{ |
| 116 | + return ProgramTriggerMonitor().execute(argc, argv); |
| 117 | +} |
0 commit comments