|
| 1 | +/////////////////////////////////////////////////////////////////////////////////////// |
| 2 | +// Class: CFODump |
| 3 | +// Module Type: EDAnalyzer |
| 4 | +// File: CFODump_module.cc |
| 5 | +// Description: Prints out DTCFragments in HWUG Packet format (see mu2e-docdb #4097) |
| 6 | +/////////////////////////////////////////////////////////////////////////////////////// |
| 7 | + |
| 8 | +#include "art/Framework/Core/EDAnalyzer.h" |
| 9 | +#include "art/Framework/Core/ModuleMacros.h" |
| 10 | +#include "art/Framework/Principal/Event.h" |
| 11 | +#include "art/Framework/Principal/Handle.h" |
| 12 | +#include "canvas/Utilities/Exception.h" |
| 13 | + |
| 14 | +#include "artdaq-core/Data/Fragment.hh" |
| 15 | +#include "artdaq-core-mu2e/Overlays/FragmentType.hh" |
| 16 | +#include "artdaq-core-mu2e/Overlays/CFOEventFragment.hh" |
| 17 | +#include "artdaq-core/Data/ContainerFragment.hh" |
| 18 | + |
| 19 | +#include "trace.h" |
| 20 | + |
| 21 | +#include <unistd.h> |
| 22 | +#include <iomanip> |
| 23 | +#include <iostream> |
| 24 | +#include <string> |
| 25 | + |
| 26 | +namespace mu2e { |
| 27 | +class CFODump; |
| 28 | +} |
| 29 | + |
| 30 | +class mu2e::CFODump : public art::EDAnalyzer |
| 31 | +{ |
| 32 | +public: |
| 33 | + explicit CFODump(fhicl::ParameterSet const& pset); |
| 34 | + virtual ~CFODump(); |
| 35 | + |
| 36 | + virtual void analyze(art::Event const& evt); |
| 37 | + |
| 38 | + virtual void beginJob(); |
| 39 | + virtual void endJob(); |
| 40 | + |
| 41 | +private: |
| 42 | + std::string binary_file_name_; |
| 43 | + bool detemu_format_; |
| 44 | + std::ofstream output_file_; |
| 45 | +}; |
| 46 | + |
| 47 | +mu2e::CFODump::CFODump(fhicl::ParameterSet const& pset) |
| 48 | + : EDAnalyzer(pset) |
| 49 | + , binary_file_name_(pset.get<std::string>("raw_output_file", "CFODump.bin")) |
| 50 | + , detemu_format_(pset.get<bool>("raw_output_in_detector_emulator_format", false)) |
| 51 | +{} |
| 52 | + |
| 53 | +mu2e::CFODump::~CFODump() {} |
| 54 | + |
| 55 | +void mu2e::CFODump::endJob() |
| 56 | +{ |
| 57 | + output_file_.close(); |
| 58 | +} |
| 59 | + |
| 60 | +void mu2e::CFODump::beginJob() |
| 61 | +{ |
| 62 | + std::string fileName = binary_file_name_; |
| 63 | + if (fileName.find(".bin") != std::string::npos) |
| 64 | + { |
| 65 | + std::string timestr = "_" + std::to_string(time(0)); |
| 66 | + fileName.insert(fileName.find(".bin"), timestr); |
| 67 | + } |
| 68 | + output_file_.open(fileName, std::ios::out | std::ios::app | std::ios::binary); |
| 69 | +} |
| 70 | + |
| 71 | +void mu2e::CFODump::analyze(art::Event const& evt) |
| 72 | +{ |
| 73 | + art::EventNumber_t eventNumber = evt.event(); |
| 74 | + TRACE(11, "mu2e::CFODump::analyze enter eventNumber=%d", eventNumber); |
| 75 | + |
| 76 | + artdaq::Fragments fragments; |
| 77 | + artdaq::FragmentPtrs containerFragments; |
| 78 | + |
| 79 | + std::vector<art::Handle<artdaq::Fragments>> fragmentHandles; |
| 80 | + fragmentHandles = evt.getMany<std::vector<artdaq::Fragment>>(); |
| 81 | + |
| 82 | + for (const auto& handle : fragmentHandles) |
| 83 | + { |
| 84 | + if (!handle.isValid() || handle->empty()) |
| 85 | + { |
| 86 | + continue; |
| 87 | + } |
| 88 | + |
| 89 | + if (handle->front().type() == artdaq::Fragment::ContainerFragmentType) |
| 90 | + { |
| 91 | + for (const auto& cont : *handle) |
| 92 | + { |
| 93 | + artdaq::ContainerFragment contf(cont); |
| 94 | + if (contf.fragment_type() != mu2e::FragmentType::CFO) |
| 95 | + { |
| 96 | + break; |
| 97 | + } |
| 98 | + |
| 99 | + for (size_t ii = 0; ii < contf.block_count(); ++ii) |
| 100 | + { |
| 101 | + containerFragments.push_back(contf[ii]); |
| 102 | + fragments.push_back(*containerFragments.back()); |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + else |
| 107 | + { |
| 108 | + if (handle->front().type() == mu2e::FragmentType::CFO) |
| 109 | + { |
| 110 | + for (auto frag : *handle) |
| 111 | + { |
| 112 | + fragments.emplace_back(frag); |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + // look for raw Toy data |
| 118 | + TLOG(TLVL_INFO) << "Run " << evt.run() << ", subrun " << evt.subRun() << ", event " << eventNumber << " has " |
| 119 | + << fragments.size() << " fragment(s) of type CFO"; |
| 120 | + |
| 121 | + for (const auto& frag : fragments) |
| 122 | + { |
| 123 | + CFOEventFragment bb(frag); |
| 124 | + auto evt = bb.getData(); |
| 125 | + TLOG(TLVL_DEBUG) << "Event " << evt.GetEventWindowTag().GetEventWindowTag(true) << " has fragment size " << frag.sizeBytes() << ")"; |
| 126 | + TLOG(TLVL_TRACE) << "Dumping CFO event: " << evt.GetEventRecord().toJson(); |
| 127 | + //if (output_file_) |
| 128 | + //{ |
| 129 | + // evt.WriteEvent(output_file_, detemu_format_); |
| 130 | + //} |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +DEFINE_ART_MODULE(mu2e::CFODump) |
0 commit comments