Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-20 08:46:00

0001 #pragma once
0002 
0003 #include <cstdlib>
0004 #include <stdexcept>
0005 #include <string>
0006 
0007 #include "EventTimingProfileReport.hh"
0008 #include "NPFold.h"
0009 
0010 struct sreport
0011 {
0012     static constexpr const char* JUNCTURE = EventTimingProfileReport::JUNCTURE;
0013     static constexpr const char* RANGES = EventTimingProfileReport::RANGES;
0014 
0015     bool VERBOSE;
0016 
0017     NP* run; // dummy array that exists just to hold metadata
0018     NP* runprof;
0019     NP* ranges;
0020 
0021     NPFold* substamp;
0022     NPFold* subprofile;
0023     NPFold* submeta;
0024     NPFold* submeta_NumPhotonCollected;
0025     NPFold* subcount;
0026 
0027     sreport();
0028 
0029     NPFold* serialize() const;
0030     void import(const NPFold* fold);
0031     void save(const char* dir) const;
0032     static sreport* Load(const char* dir);
0033 
0034     std::string desc() const;
0035     std::string desc_run() const;
0036     std::string desc_runprof() const;
0037     std::string desc_ranges() const;
0038     std::string desc_substamp() const;
0039     std::string desc_subprofile() const;
0040     std::string desc_submeta() const;
0041     std::string desc_subcount() const;
0042 };
0043 
0044 inline sreport::sreport() :
0045     VERBOSE(std::getenv("sreport__VERBOSE") != nullptr),
0046     run(nullptr),
0047     runprof(nullptr),
0048     ranges(nullptr),
0049     substamp(nullptr),
0050     subprofile(nullptr),
0051     submeta(nullptr),
0052     submeta_NumPhotonCollected(nullptr),
0053     subcount(nullptr)
0054 {
0055 }
0056 
0057 inline NPFold* sreport::serialize() const
0058 {
0059     if (run == nullptr)
0060         throw std::runtime_error("sreport::serialize missing required 'run' array");
0061 
0062     NPFold* smry = new NPFold;
0063     smry->add("run", run);
0064     smry->add("runprof", runprof);
0065     smry->add("ranges", ranges);
0066     smry->add_subfold("substamp", substamp);
0067     smry->add_subfold("subprofile", subprofile);
0068     smry->add_subfold("submeta", submeta);
0069     smry->add_subfold("submeta_NumPhotonCollected", submeta_NumPhotonCollected);
0070     smry->add_subfold("subcount", subcount);
0071     return smry;
0072 }
0073 
0074 inline NP* sreport_copy_array(const NPFold* smry, const char* key, bool required)
0075 {
0076     if (smry == nullptr)
0077         throw std::runtime_error("sreport::import requires a summary fold");
0078 
0079     const NP* array = smry->get(key);
0080     if (required && array == nullptr)
0081         throw std::runtime_error(
0082             std::string("sreport::import missing required '") + key + "' array");
0083 
0084     return array ? array->copy() : nullptr;
0085 }
0086 
0087 inline void sreport::import(const NPFold* smry)
0088 {
0089     run = sreport_copy_array(smry, "run", true);
0090     runprof = sreport_copy_array(smry, "runprof", false);
0091     ranges = sreport_copy_array(smry, "ranges", false);
0092     substamp = smry->get_subfold("substamp");
0093     subprofile = smry->get_subfold("subprofile");
0094     submeta = smry->get_subfold("submeta");
0095     submeta_NumPhotonCollected = smry->get_subfold("submeta_NumPhotonCollected");
0096     subcount = smry->get_subfold("subcount");
0097 }
0098 
0099 inline void sreport::save(const char* dir) const
0100 {
0101     NPFold* smry = serialize();
0102     smry->save_verbose(dir);
0103 }
0104 
0105 inline sreport* sreport::Load(const char* dir)
0106 {
0107     NPFold*  smry = NPFold::Load(dir);
0108     sreport* report = new sreport;
0109     report->import(smry);
0110     return report;
0111 }