19#include <boost/program_options.hpp>
22#include <TTreeReader.h>
23#include <TTreeReaderValue.h>
36std::tuple<TFile*, TTreeReader*>
loadData(
const std::string inFile)
40 TFile*
f = TFile::Open(inFile.c_str(),
"READ");
41 if (!
f ||
f->IsZombie()) {
42 LOG(error) <<
"opening file " << inFile <<
" failed";
46 TTreeReader*
r =
new TTreeReader(
"o2sim",
f);
48 LOG(error) <<
"tree o2sim not found";
52 return std::make_tuple(
f,
r);
56int size(
const std::map<
int, std::vector<int>>& badChannels)
62 for (
const auto&
channels : badChannels) {
74 auto [dataFile, dataReader] =
loadData(inFile);
75 TTreeReaderValue<o2::mch::StatusMap> statusMap(*dataReader,
"statusmaps");
80 std::map<int, std::vector<int>> currentBadChannels{};
82 while (dataReader->Next()) {
96 if (badChannels == currentBadChannels) {
102 LOGP(info,
"TF [{}, {}]: the status map contains {} bad channels in {} detection element{} (using statusMask=0x{:x})",
103 firstTF, lastTF,
size(currentBadChannels), currentBadChannels.size(), currentBadChannels.size() > 1 ?
"s" :
"",
mask);
108 currentBadChannels = badChannels;
112 LOGP(info,
"TF [{}, {}]: the status map contains {} bad channels in {} detection element{} (using statusMask=0x{:x})",
113 firstTF, lastTF,
size(currentBadChannels), currentBadChannels.size(), currentBadChannels.size() > 1 ?
"s" :
"",
mask);
123 auto [dataFile, dataReader] =
loadData(inFile);
124 TTreeReaderValue<o2::mch::StatusMap> statusMap(*dataReader,
"statusmaps");
126 if (dataReader->SetEntry(iTF) != TTreeReader::kEntryValid) {
127 LOGP(error,
"invalid TF index {} (number of TFs = {})", iTF, dataReader->GetEntries());
131 LOGP(info,
"status map content for TF {} with statusMask=0x{:x}:", iTF,
mask);
133 for (
const auto& status : *statusMap) {
134 if ((
mask & status.second) != 0) {
135 auto channel = status.first;
136 if (!channel.isValid()) {
137 LOGP(error,
"invalid channel with status {}", status.second);
139 LOGP(info,
"{} status {}",
asString(channel), status.second);
152 auto [dataFile, dataReader] =
loadData(inFile);
153 TTreeReaderValue<o2::mch::StatusMap> statusMap(*dataReader,
"statusmaps");
155 if (dataReader->SetEntry(iTF) != TTreeReader::kEntryValid) {
156 LOGP(error,
"invalid TF index {} (number of TFs = {})", iTF, dataReader->GetEntries());
162 for (
const auto& status : *statusMap) {
163 auto channel = status.first;
164 if (!channel.isValid()) {
165 LOG(error) <<
"invalid channel";
167 if ((
mask & status.second) != 0) {
168 const auto c =
o2::mch::DsChannelId(channel.getSolarId(), channel.getElinkId(), channel.getChannel());
175 LOGP(info,
"the reject list contains {} bad channels (using statusMask=0x{:x})", bv.size(),
mask);
185 std::map<std::string, std::string> md;
187 LOGP(info,
"storing MCH RejectList (valid from {} to {}) to MCH/Calib/RejectList",
196 po::variables_map vm;
197 po::options_description
usage(
"Usage");
208 auto tnow = std::chrono::system_clock::now().time_since_epoch();
209 using namespace std::chrono_literals;
210 auto tend = tnow + 24
h;
211 uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(tnow).count();
212 uint64_t
end = std::chrono::duration_cast<std::chrono::milliseconds>(tend).count();
218 (
"help,h",
"produce help message")
219 (
"ccdb,c",po::value<std::string>(&
ccdbUrl)->default_value(
"http://localhost:6464"),
"ccdb url")
220 (
"starttimestamp,st",po::value<uint64_t>(&startTS)->default_value(now),
"timestamp for query or put - (default=now)")
221 (
"endtimestamp,et", po::value<uint64_t>(&endTS)->default_value(
end),
"end of validity (for put) - default=1 day from now")
222 (
"infile,f",po::value<std::string>(&inFile)->default_value(
"mchstatusmaps.root"),
"input file of StatusMap objects")
223 (
"tf,i", po::value<size_t>(&iTF)->default_value(0),
"index of the TF to process")
224 (
"mask,m", po::value<uint32_t>(&
mask)->default_value(defaultMask),
"mask to apply to the statusMap to produce the RejectList")
225 (
"print,p",po::bool_switch(&
print),
"print the content of the input file without processing it")
226 (
"dump,d",po::bool_switch(&
dump),
"dump the raw content of the input file without processing it")
230 po::options_description cmdline;
233 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
235 if (vm.count(
"help")) {
236 LOG(info) <<
"This program converts a StatusMap to a RejectList CCDB object";
243 }
catch (boost::program_options::error& e) {
244 LOG(error) << e.what();
std::string asString(TDataMember const &dm, char *pointer)
std::vector< o2::mch::DsChannelId > BadChannelsVector
Class for time synchronization of RawReader instances.
int storeAsTFileAny(const T *obj, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const
void init(std::string const &hosts)
void dump(const std::string what, DPMAP m, int verbose)
GLsizeiptr const void GLenum usage
std::map< int, std::vector< int > > applyMask(const o2::mch::StatusMap &statusMap, uint32_t mask)
BadChannelsVector statusMap2RejectList(const std::string inFile, const size_t iTF, const uint32_t mask)
std::tuple< TFile *, TTreeReader * > loadData(const std::string inFile)
void printContent(const std::string inFile, const uint32_t mask)
void dumpContent(const std::string inFile, const size_t iTF, const uint32_t mask)
void uploadRejectList(const std::string ccdbUrl, uint64_t startTS, uint64_t endTS, const BadChannelsVector &bv)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< ChannelData > channels