#include #include #include #include #include #include using json = nlohmann::json; std::vector> extract_excluded(json data, int run) { // Extract a list of exclude (lo, hi) timestamps once per run // Get the exclusion list auto stable = data[std::to_string(run)]["excluded_list"]; // Create output vector of (lo, hi) and fill std::vector> times; times.reserve(stable.size()); for (auto s : stable) { times.push_back({s["start_utime"], s["stop_utime"]}); } return times; } bool is_bad(std::vector> bad_times, unsigned int time) { // Check if a timestamp is in any exclude range for each event time stamp // In ntuple maker want to store the bad_times as a member variable instead of passing it to the function for (auto bad : bad_times) { if (time > bad.first && time < bad.second) return true; } return false; } int main() { // Test // Parse the file to create a json structure std::ifstream f("runlist/faser_goodrunlist_2022_filters.json"); json data = json::parse(f); // Extract excluded times auto times = extract_excluded(data, 8975); // Check if a given timestamp is good or bad std::cout << "Should be good:" << is_bad(times, 1667388863) << std::endl; std::cout << "Should be bad :" << is_bad(times, 1667403959) << std::endl; }