|
| 1 | +//////////////////////////////////////////////////////////////////////// |
| 2 | +// Class: SBNDPTBDecoder |
| 3 | +// Plugin Type: producer |
| 4 | +// File: SBNDPTBDecoder_module.cc |
| 5 | +// |
| 6 | +//////////////////////////////////////////////////////////////////////// |
| 7 | + |
| 8 | +#include "art/Framework/Core/EDProducer.h" |
| 9 | +#include "art/Framework/Core/ModuleMacros.h" |
| 10 | +#include "art/Framework/Principal/Event.h" |
| 11 | +#include "art/Framework/Principal/Handle.h" |
| 12 | +#include "art/Framework/Principal/Run.h" |
| 13 | +#include "art/Framework/Principal/SubRun.h" |
| 14 | +#include "canvas/Utilities/InputTag.h" |
| 15 | +#include "fhiclcpp/ParameterSet.h" |
| 16 | +#include "messagefacility/MessageLogger/MessageLogger.h" |
| 17 | + |
| 18 | +#include <memory> |
| 19 | + |
| 20 | +#include "sbndaq-artdaq-core/Overlays/SBND/PTBFragment.hh" |
| 21 | +#include "artdaq-core/Data/ContainerFragment.hh" |
| 22 | +#include "sbndcode/Decoders/PTB/sbndptb.h" |
| 23 | + |
| 24 | +class SBNDPTBDecoder; |
| 25 | + |
| 26 | + |
| 27 | +class SBNDPTBDecoder : public art::EDProducer { |
| 28 | +public: |
| 29 | + explicit SBNDPTBDecoder(fhicl::ParameterSet const & p); |
| 30 | + // The compiler-generated destructor is fine for non-base |
| 31 | + // classes without bare pointers or other resource use. |
| 32 | + |
| 33 | + // Plugins should not be copied or assigned. |
| 34 | + SBNDPTBDecoder(SBNDPTBDecoder const &) = delete; |
| 35 | + SBNDPTBDecoder(SBNDPTBDecoder &&) = delete; |
| 36 | + SBNDPTBDecoder & operator = (SBNDPTBDecoder const &) = delete; |
| 37 | + SBNDPTBDecoder & operator = (SBNDPTBDecoder &&) = delete; |
| 38 | + |
| 39 | + // Required functions. |
| 40 | + void produce(art::Event & e) override; |
| 41 | + |
| 42 | +private: |
| 43 | + |
| 44 | + // Declare member data here. |
| 45 | + |
| 46 | + std::string fInputLabel; |
| 47 | + std::string fInputContainerInstance; |
| 48 | + std::string fInputNonContainerInstance; |
| 49 | + std::string fOutputInstance; |
| 50 | + int fDebugLevel; |
| 51 | + |
| 52 | + typedef struct ptbsv |
| 53 | + { |
| 54 | + std::vector<raw::ptb::Trigger> HLTrigs; |
| 55 | + std::vector<raw::ptb::Trigger> LLTrigs; |
| 56 | + std::vector<raw::ptb::ChStatus> ChStats; |
| 57 | + std::vector<raw::ptb::Feedback> Feedbacks; |
| 58 | + std::vector<raw::ptb::Misc> Miscs; |
| 59 | + std::vector<raw::ptb::WordIndex> WordIndexes; |
| 60 | + } ptbsv_t; |
| 61 | + |
| 62 | + void _process_PTB_AUX(const artdaq::Fragment& frag, ptbsv_t &sout); |
| 63 | +}; |
| 64 | + |
| 65 | + |
| 66 | +SBNDPTBDecoder::SBNDPTBDecoder(fhicl::ParameterSet const & p) |
| 67 | + : EDProducer{p} |
| 68 | + // Initialize member data here. |
| 69 | +{ |
| 70 | + fInputLabel = p.get<std::string>("InputLabel"); |
| 71 | + fInputContainerInstance = p.get<std::string>("InputContainerInstance"); |
| 72 | + fInputNonContainerInstance = p.get<std::string>("InputNonContainerInstance"); |
| 73 | + fOutputInstance = p.get<std::string>("OutputInstance"); |
| 74 | + fDebugLevel = p.get<int>("DebugLevel",0); |
| 75 | + |
| 76 | + produces<std::vector<raw::ptb::sbndptb> >(fOutputInstance); |
| 77 | +} |
| 78 | + |
| 79 | +void SBNDPTBDecoder::produce(art::Event & evt) |
| 80 | +{ |
| 81 | + |
| 82 | + |
| 83 | + // look first for container fragments and then non-container fragments |
| 84 | + |
| 85 | + std::vector<raw::ptb::sbndptb> sbndptbs; |
| 86 | + |
| 87 | + art::InputTag itag1(fInputLabel, fInputContainerInstance); |
| 88 | + auto cont_frags = evt.getHandle<artdaq::Fragments>(itag1); |
| 89 | + if (cont_frags) |
| 90 | + { |
| 91 | + for (auto const& cont : *cont_frags) |
| 92 | + { |
| 93 | + artdaq::ContainerFragment cont_frag(cont); |
| 94 | + for (size_t ii = 0; ii < cont_frag.block_count(); ++ii) |
| 95 | + { |
| 96 | + ptbsv_t sout; // output structures |
| 97 | + _process_PTB_AUX(*cont_frag[ii], sout); |
| 98 | + raw::ptb::sbndptb ptbdp(sout.HLTrigs,sout.LLTrigs,sout.ChStats,sout.Feedbacks,sout.Miscs,sout.WordIndexes); |
| 99 | + sbndptbs.push_back(ptbdp); |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + art::InputTag itag2(fInputLabel, fInputNonContainerInstance); |
| 105 | + auto frags = evt.getHandle<artdaq::Fragments>(itag2); |
| 106 | + if (frags) |
| 107 | + { |
| 108 | + for(auto const& frag: *frags) |
| 109 | + { |
| 110 | + ptbsv_t sout; // output structures |
| 111 | + _process_PTB_AUX(frag, sout); |
| 112 | + raw::ptb::sbndptb ptbdp(sout.HLTrigs,sout.LLTrigs,sout.ChStats,sout.Feedbacks,sout.Miscs,sout.WordIndexes); |
| 113 | + sbndptbs.push_back(ptbdp); |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + evt.put(std::make_unique<std::vector<raw::ptb::sbndptb>>(std::move(sbndptbs)),fOutputInstance); |
| 118 | +} |
| 119 | + |
| 120 | +void SBNDPTBDecoder::_process_PTB_AUX(const artdaq::Fragment& frag, ptbsv_t &sout) |
| 121 | +{ |
| 122 | + sbndaq::CTBFragment ctbfrag(frag); // somehow the name CTBFragment stuck |
| 123 | + |
| 124 | + // use the same logic in sbndaq-artdaq-core/Overlays/SBND/PTBFragment.cc: operator<< |
| 125 | + // but separate out the HLTs and LLTs |
| 126 | + if (fDebugLevel > 0) |
| 127 | + { |
| 128 | + std::cout << "SBNDPTBDecoder_module: got into aux" << std::endl; |
| 129 | + } |
| 130 | + |
| 131 | + for (size_t iword = 0; iword < ctbfrag.NWords(); ++iword) |
| 132 | + { |
| 133 | + if (fDebugLevel > 0) |
| 134 | + { |
| 135 | + std::cout << "SBNDPTBDecoder_module: start processing word: " << iword << std::endl; |
| 136 | + } |
| 137 | + size_t ix=0; |
| 138 | + uint32_t wt = 0; |
| 139 | + if (ctbfrag.Trigger(iword)) |
| 140 | + { |
| 141 | + raw::ptb::Trigger tstruct; |
| 142 | + tstruct.word_type = ctbfrag.Trigger(iword)->word_type; |
| 143 | + wt = tstruct.word_type; |
| 144 | + tstruct.trigger_word = ctbfrag.Trigger(iword)->trigger_word; |
| 145 | + tstruct.timestamp = ctbfrag.Trigger(iword)->timestamp; |
| 146 | + if (ctbfrag.Trigger(iword)->IsHLT()) |
| 147 | + { |
| 148 | + ix = sout.HLTrigs.size(); |
| 149 | + sout.HLTrigs.push_back(tstruct); |
| 150 | + if (fDebugLevel > 0) |
| 151 | + { |
| 152 | + std::cout << "SBNDPTBDecoder_module: found HLT: " << wt << " " << ix << std::endl; |
| 153 | + } |
| 154 | + } |
| 155 | + else if (ctbfrag.Trigger(iword)->IsLLT()) |
| 156 | + { |
| 157 | + ix = sout.LLTrigs.size(); |
| 158 | + sout.LLTrigs.push_back(tstruct); |
| 159 | + if (fDebugLevel > 0) |
| 160 | + { |
| 161 | + std::cout << "SBNDPTBDecoder_module: found LLT: " << wt << " " << ix << std::endl; |
| 162 | + } |
| 163 | + } |
| 164 | + } |
| 165 | + else if (ctbfrag.ChStatus(iword)) |
| 166 | + { |
| 167 | + raw::ptb::ChStatus cstruct; |
| 168 | + cstruct.timestamp = ctbfrag.ChStatus(iword)->timestamp; |
| 169 | + cstruct.beam = ctbfrag.ChStatus(iword)->beam; |
| 170 | + cstruct.crt = ctbfrag.ChStatus(iword)->crt; |
| 171 | + cstruct.pds = ctbfrag.ChStatus(iword)->pds; |
| 172 | + cstruct.mtca = ctbfrag.ChStatus(iword)->mtca; |
| 173 | + cstruct.nim = ctbfrag.ChStatus(iword)->nim; |
| 174 | + cstruct.auxpds = ctbfrag.ChStatus(iword)->auxpds; |
| 175 | + cstruct.word_type = ctbfrag.ChStatus(iword)->word_type; |
| 176 | + wt = cstruct.word_type; |
| 177 | + ix = sout.ChStats.size(); |
| 178 | + sout.ChStats.push_back(cstruct); |
| 179 | + if (fDebugLevel > 0) |
| 180 | + { |
| 181 | + std::cout << "SBNDPTBDecoder_module: found CHStat: " << wt << " " << ix << std::endl; |
| 182 | + } |
| 183 | + } |
| 184 | + else if (ctbfrag.Feedback(iword)) |
| 185 | + { |
| 186 | + raw::ptb::Feedback fstruct; |
| 187 | + fstruct.timestamp = ctbfrag.Feedback(iword)->timestamp; |
| 188 | + fstruct.code = ctbfrag.Feedback(iword)->code; |
| 189 | + fstruct.source = ctbfrag.Feedback(iword)->source; |
| 190 | + fstruct.payload = ctbfrag.Feedback(iword)->payload; // broken in two in Tereza's version |
| 191 | + fstruct.word_type = ctbfrag.Feedback(iword)->word_type; |
| 192 | + wt = fstruct.word_type; |
| 193 | + ix = sout.Feedbacks.size(); |
| 194 | + sout.Feedbacks.push_back(fstruct); |
| 195 | + if (fDebugLevel > 0) |
| 196 | + { |
| 197 | + std::cout << "SBNDPTBDecoder_module: found Feedback: " << wt << " " << ix << std::endl; |
| 198 | + } |
| 199 | + } |
| 200 | + else |
| 201 | + { |
| 202 | + raw::ptb::Misc mstruct; |
| 203 | + mstruct.timestamp = ctbfrag.Word(iword)->timestamp; |
| 204 | + mstruct.payload = ctbfrag.Word(iword)->payload; |
| 205 | + mstruct.word_type = ctbfrag.Word(iword)->word_type; |
| 206 | + wt = mstruct.word_type; |
| 207 | + ix = sout.Miscs.size(); |
| 208 | + sout.Miscs.push_back(mstruct); |
| 209 | + if (fDebugLevel > 0) |
| 210 | + { |
| 211 | + std::cout << "SBNDPTBDecoder_module: found Misc: " << wt << " " << ix << std::endl; |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + raw::ptb::WordIndex wstruct; |
| 216 | + wstruct.word_type = wt; |
| 217 | + wstruct.index = ix; |
| 218 | + sout.WordIndexes.push_back(wstruct); |
| 219 | + if (fDebugLevel > 0) |
| 220 | + { |
| 221 | + std::cout << "SBNDPTBDecoder_module: index calc: " << wt << " " << ix << std::endl; |
| 222 | + } |
| 223 | + } |
| 224 | +} |
| 225 | + |
| 226 | + |
| 227 | +DEFINE_ART_MODULE(SBNDPTBDecoder) |
0 commit comments