19#include "trg/klm/modules/klmtrigger/ntuples_full.h"
23auto & get_IO_csv_handle()
27 std::string dump_path;
28 std::map<std::string, std::optional<std::ofstream>> files;
39void save(std::string filename, T&& content)
41 if (content.empty()) {
44 auto& o_file = get_IO_csv_handle().files[filename];
53 throw std::runtime_error(
"unable to open file: " + filename);
55 o_file = std::move(ofs);
57 *o_file <<
"gevent_number";
58 const auto& row = content[0];
60 nt::ntuple_for_each(row,
62 *o_file <<
"," << ele.get_name();
72 for (
const auto& row : content) {
73 *o_file << get_IO_csv_handle().event_nr;
74 nt::ntuple_for_each(row,
76 *o_file <<
',' << ele.v;
87void save_internal(std::string source_file,
int lineno, std::string variable_name, T&& content)
89 if (!get_IO_csv_handle().do_dump) {
92 auto itterA = source_file.find_last_of(
"\\");
93 auto itterB = source_file.find_last_of(
"/");
94 itterB = itterB < source_file.size() ? itterB : 0;
95 itterA = itterA < source_file.size() ? itterA : 0;
96 auto itter = std::max(itterA, itterB);
98 auto file = source_file.substr(itter + 1);
100 file = get_IO_csv_handle().dump_path + file +
"_" + std::to_string(lineno) +
"_" + variable_name +
".csv";
105#ifdef __DO_CSV_PRINTOUT__
106#define __CSV__WRITE_W_lINE__(x) save_internal(__FILE__, __LINE__, #x, x)
107#define __CSV__WRITE__(x) save_internal(__FILE__, 0, #x, x)
111#define __CSV__WRITE_W_lINE__(x) do {} while (false)
112#define __CSV__WRITE__(x) do {} while (false)