Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-09 04:49:36

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 // make a sorted copy of a vector, optionally of a different type
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 /// constructors and destructor
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 /// Checks for Laser Signals in specific modules
0040 /// For Accessing FED Data see also EventFilter/SiStripRawToDigi/src/SiStripRawToDigiUnpacker.cc and related files
0041 bool LaserAlignmentEventFilter::filter(edm::StreamID sid, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0042   //unsigned int  det_ctr = 0;      // count how many modules are tested for signal
0043   unsigned int sig_ctr = 0;  // count how many modules have signal
0044   //unsigned long buffer_sum = 0;   // sum of buffer sizes
0045 
0046   // retrieve FED raw data (by label, which is "source" by default)
0047   edm::Handle<FEDRawDataCollection> buffers;
0048   iEvent.getByToken(FED_collection_token, buffers);
0049 
0050   // read the cabling map from the EventSetup
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     // Retrieve FED raw data for given FED
0056     const FEDRawData& input = buffers->FEDData(static_cast<int>(*ifed));
0057     LogDebug("LaserAlignmentEventFilter") << "Examining FED " << *ifed;
0058 
0059     // check on FEDRawData pointer
0060     if (not input.data())
0061       continue;
0062 
0063     // check on FEDRawData size
0064     if (not input.size())
0065       continue;
0066 
0067     // construct FEDBuffer
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     // get the cabling connections for this FED
0083     auto const& conns = cabling->fedConnections(*ifed);
0084 
0085     // Iterate through FED channels, extract payload and create Digis
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         //++det_ctr;
0093         if (buffer.channel(iconn->fedCh()).length() > single_channel_thresh)
0094           ++sig_ctr;
0095         //buffer_sum += buffer.channel(iconn->fedCh()).length();
0096         if (sig_ctr > channel_count_thresh) {
0097           LogDebug("LaserAlignmentEventFilter") << "Event identified as LAS";
0098           return true;
0099         }
0100       }
0101     }  // channel loop
0102   }    // FED loop
0103 
0104   //   LogDebug("LaserAlignmentEventFilter") << det_ctr << " channels were tested for signal\n"
0105   //                <<sig_ctr << " channels have signal\n"
0106   //                << "Sum of buffer sizes: " << buffer_sum;
0107 
0108   return false;
0109 }
0110 
0111 //define this as a plug-in
0112 DEFINE_FWK_MODULE(LaserAlignmentEventFilter);