8 #define TRACE_NAME "ToyDump"
10 #include "art/Framework/Core/EDAnalyzer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "canvas/Utilities/Exception.h"
16 #include "artdaq-core-demo/Overlays/FragmentType.hh"
17 #include "artdaq-core-demo/Overlays/ToyFragment.hh"
18 #include "artdaq-core/Data/ContainerFragment.hh"
19 #include "artdaq-core/Data/Fragment.hh"
54 explicit ToyDump(fhicl::ParameterSet
const& pset);
65 virtual void analyze(art::Event
const& evt);
68 std::string raw_data_label_;
69 int num_adcs_to_write_;
70 int num_adcs_to_print_;
72 uint32_t columns_to_display_on_screen_;
73 std::string output_file_name_;
79 , raw_data_label_(pset.get<std::string>(
"raw_data_label",
"daq"))
80 , num_adcs_to_write_(pset.get<int>(
"num_adcs_to_write", 0))
81 , num_adcs_to_print_(pset.get<int>(
"num_adcs_to_print", 10))
82 , binary_mode_(pset.get<bool>(
"binary_mode", true))
83 , columns_to_display_on_screen_(pset.get<uint32_t>(
"columns_to_display_on_screen", 10))
84 , output_file_name_(pset.get<std::string>(
"output_file_name",
"out.bin"))
91 art::EventNumber_t eventNumber = evt.event();
99 std::vector<std::string> fragment_type_labels{
"TOY1",
"TOY2",
"ContainerTOY1",
"ContainerTOY2" };
101 for (
auto label : fragment_type_labels)
103 art::Handle<artdaq::Fragments> fragments_with_label;
105 evt.getByLabel(raw_data_label_, label, fragments_with_label);
106 if (!fragments_with_label.isValid())
continue;
108 if (label ==
"Container" || label ==
"ContainerTOY1" || label ==
"ContainerTOY2")
110 for (
auto cont : *fragments_with_label)
113 for (
size_t ii = 0; ii < contf.
block_count(); ++ii)
115 containerFragments.push_back(contf[ii]);
116 fragments.push_back(*containerFragments.back());
122 for (
auto frag : *fragments_with_label)
124 fragments.emplace_back(frag);
130 TLOG(TLVL_INFO) <<
"Run " << evt.run() <<
", subrun " << evt.subRun()
131 <<
", event " << eventNumber <<
" has " << fragments.size()
132 <<
" fragment(s) of type TOY1 or TOY2";
134 for (
const auto& frag : fragments)
138 TLOG(TLVL_INFO) <<
fragmentTypeToString(static_cast<demo::detail::FragmentType>(frag.type())) <<
" fragment " << frag.fragmentID()
139 <<
" w/ seqID " << frag.sequenceID() <<
" and timestamp " << frag.timestamp()
142 if (frag.hasMetadata())
146 TLOG(TLVL_DEBUG) <<
"Fragment metadata: " << std::showbase <<
"Board serial number = "
149 <<
" -> max ADC value = "
153 if (num_adcs_to_write_ >= 0)
155 uint32_t numAdcs = num_adcs_to_write_;
159 TLOG(TLVL_WARNING) <<
"Asked for more ADC values to file than are in Fragment. Only writing what's here...";
163 std::ofstream output(output_file_name_, std::ios::out | std::ios::app | std::ios::binary);
164 for (uint32_t i_adc = 0; i_adc < numAdcs; ++i_adc)
171 std::ofstream output(output_file_name_, std::ios::out | std::ios::app);
172 output << fragmentTypeToString(static_cast<demo::detail::FragmentType>(frag.type())) <<
"\t" << frag.fragmentID();
174 for (uint32_t i_adc = 0; i_adc < numAdcs; ++i_adc)
176 output <<
"\t" << std::to_string(*(bb.
dataBeginADCs() + i_adc));
184 if (num_adcs_to_print_ >= 0)
186 uint32_t numAdcs = num_adcs_to_print_;
190 TLOG(TLVL_WARNING) <<
"Asked for more ADC values to file than are in Fragment. Only writing what's here...";
194 TLOG(TLVL_INFO) <<
"First " << numAdcs <<
" ADC values in the fragment:";
195 int rows = 1 + (int)((num_adcs_to_print_ - 1) / columns_to_display_on_screen_);
196 uint32_t adc_counter = 0;
197 for (
int idx = 0; idx < rows; ++idx)
199 std::ostringstream o;
201 o << std::setw(4) << std::setfill(
'.');
202 o << (idx * columns_to_display_on_screen_) <<
": ";
203 for (uint32_t jdx = 0; jdx < columns_to_display_on_screen_; ++jdx)
205 if (adc_counter >= numAdcs) {
break; }
206 o << std::setw(6) << std::setfill(
' ');
210 TLOG(TLVL_INFO) << o.str();
std::vector< Fragment > Fragments
Header::trigger_number_t hdr_trigger_number() const
std::string fragmentTypeToString(FragmentType val)
adc_t adc_value(uint32_t index)
ToyDump(fhicl::ParameterSet const &pset)
ToyDump Constructor.
uint8_t hdr_distribution_type() const
An art::EDAnalyzer module designed to display the data from demo::ToyFragment objects.
adc_t const * dataBeginADCs() const
static size_t adc_range(int daq_adc_bits)
Metadata::count_t block_count() const
std::list< FragmentPtr > FragmentPtrs
virtual ~ToyDump()
ToyDump Destructor.
virtual void analyze(art::Event const &evt)
Analyze an event. Called by art for each event in run (based on command line options) ...
size_t total_adc_values() const