File indexing completed on 2024-09-07 04:34:31
0001 #include "LaserAlignmentEventFilter.h"
0002
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0011 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
0012
0013 #include <algorithm>
0014
0015
0016 template <typename T, typename U>
0017 std::vector<T> copy_and_sort_vector(std::vector<U> const& input) {
0018 std::vector<T> copy(input.begin(), input.end());
0019 std::sort(copy.begin(), copy.end());
0020 return copy;
0021 }
0022
0023
0024
0025
0026 LaserAlignmentEventFilter::LaserAlignmentEventFilter(const edm::ParameterSet& iConfig)
0027 : cablingToken_(esConsumes()),
0028 FED_collection_token(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("FedInputTag"))),
0029 las_fed_ids(copy_and_sort_vector<uint16_t>(iConfig.getParameter<std::vector<int>>("FED_IDs"))),
0030 las_signal_ids(copy_and_sort_vector<uint32_t>(iConfig.getParameter<std::vector<int>>("SIGNAL_IDs"))),
0031 single_channel_thresh(iConfig.getParameter<unsigned>("SINGLE_CHANNEL_THRESH")),
0032 channel_count_thresh(iConfig.getParameter<unsigned>("CHANNEL_COUNT_THRESH")) {}
0033
0034
0035
0036
0037 LaserAlignmentEventFilter::~LaserAlignmentEventFilter() {}
0038
0039
0040
0041 bool LaserAlignmentEventFilter::filter(edm::StreamID sid, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0042
0043 unsigned int sig_ctr = 0;
0044
0045
0046
0047 edm::Handle<FEDRawDataCollection> buffers;
0048 iEvent.getByToken(FED_collection_token, buffers);
0049
0050
0051 const auto& cabling = &iSetup.getData(cablingToken_);
0052
0053 std::vector<uint16_t>::const_iterator ifed = las_fed_ids.begin();
0054 for (; ifed != las_fed_ids.end(); ifed++) {
0055
0056 const FEDRawData& input = buffers->FEDData(static_cast<int>(*ifed));
0057 LogDebug("LaserAlignmentEventFilter") << "Examining FED " << *ifed;
0058
0059
0060 if (not input.data())
0061 continue;
0062
0063
0064 if (not input.size())
0065 continue;
0066
0067
0068 const auto st_buffer = sistrip::preconstructCheckFEDBuffer(input);
0069 if (sistrip::FEDBufferStatusCode::SUCCESS != st_buffer) {
0070 throw cms::Exception("FEDBuffer") << st_buffer << " (check debug output for more details)";
0071 }
0072 sistrip::FEDBuffer buffer{input};
0073 const auto st_chan = buffer.findChannels();
0074 if (sistrip::FEDBufferStatusCode::SUCCESS != st_chan) {
0075 throw cms::Exception("FEDBuffer") << st_chan << " (check debug output for more details)";
0076 }
0077 if (not buffer.doChecks(true)) {
0078 edm::LogWarning("LaserAlignmentEventFilter") << "FED Buffer check fails for FED ID " << *ifed << ".";
0079 continue;
0080 }
0081
0082
0083 auto const& conns = cabling->fedConnections(*ifed);
0084
0085
0086 std::vector<FedChannelConnection>::const_iterator iconn = conns.begin();
0087 for (; iconn != conns.end(); iconn++) {
0088 if (std::binary_search(las_signal_ids.begin(), las_signal_ids.end(), iconn->detId())) {
0089 LogDebug("LaserAlignmentEventFilter")
0090 << " Found LAS signal module in FED " << *ifed << " DetId: " << iconn->detId() << "\n"
0091 << "buffer.channel(iconn->fedCh()).size(): " << buffer.channel(iconn->fedCh()).length();
0092
0093 if (buffer.channel(iconn->fedCh()).length() > single_channel_thresh)
0094 ++sig_ctr;
0095
0096 if (sig_ctr > channel_count_thresh) {
0097 LogDebug("LaserAlignmentEventFilter") << "Event identified as LAS";
0098 return true;
0099 }
0100 }
0101 }
0102 }
0103
0104
0105
0106
0107
0108 return false;
0109 }
0110
0111
0112 DEFINE_FWK_MODULE(LaserAlignmentEventFilter);