Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:30

0001 /*
0002  * adapting to CTPPS pixel detector March 2017 - F.Ferro
0003  */
0004 
0005 #include "EventFilter/CTPPSRawToDigi/interface/CTPPSPixelRawToDigi.h"
0006 
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 #include "DataFormats/CTPPSDigi/interface/CTPPSPixelDigi.h"
0012 
0013 #include "DataFormats/Common/interface/DetSetVector.h"
0014 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0015 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0016 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0017 
0018 #include "EventFilter/CTPPSRawToDigi/interface/CTPPSPixelDataFormatter.h"
0019 
0020 #include "FWCore/Framework/interface/ConsumesCollector.h"
0021 
0022 using namespace std;
0023 
0024 CTPPSPixelRawToDigi::CTPPSPixelRawToDigi(const edm::ParameterSet& conf)
0025     : config_(conf),
0026       eSummary_("CTPPSPixelDataFormatter", "[ctppsPixelRawToDigi]", edm::isDebugEnabled())
0027 
0028 {
0029   FEDRawDataCollection_ = consumes<FEDRawDataCollection>(config_.getParameter<edm::InputTag>("inputLabel"));
0030   CTPPSPixelDAQMapping_ = esConsumes<CTPPSPixelDAQMapping, CTPPSPixelDAQMappingRcd>();
0031 
0032   produces<edm::DetSetVector<CTPPSPixelDigi>>();
0033 
0034   isRun3_ = config_.getParameter<bool>("isRun3");
0035   includeErrors_ = config_.getParameter<bool>("includeErrors");
0036   mappingLabel_ = config_.getParameter<std::string>("mappingLabel");
0037 
0038   if (includeErrors_) {
0039     produces<edm::DetSetVector<CTPPSPixelDataError>>();
0040   }
0041 }
0042 
0043 CTPPSPixelRawToDigi::~CTPPSPixelRawToDigi() {
0044   edm::LogInfo("CTPPSPixelRawToDigi") << " CTPPSPixelRawToDigi destructor!";
0045 }
0046 
0047 void CTPPSPixelRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0048   edm::ParameterSetDescription desc;
0049   desc.add<bool>("isRun3", true);
0050   desc.add<bool>("includeErrors", true);
0051   desc.add<edm::InputTag>("inputLabel", edm::InputTag("rawDataCollector"));
0052   desc.add<std::string>("mappingLabel", "RPix");
0053   descriptions.add("ctppsPixelDigis", desc);
0054 }
0055 
0056 void CTPPSPixelRawToDigi::produce(edm::Event& ev, const edm::EventSetup& es) {
0057   edm::Handle<FEDRawDataCollection> buffers;
0058   ev.getByToken(FEDRawDataCollection_, buffers);
0059 
0060   edm::ESHandle<CTPPSPixelDAQMapping> mapping;
0061 
0062   bool data_exist = false;
0063   for (int fed = FEDNumbering::MINCTPPSPixelsFEDID; fed <= FEDNumbering::MAXCTPPSPixelsFEDID; fed++) {
0064     const FEDRawData& tempRawData = buffers->FEDData(fed);
0065     if (tempRawData.size() != 0) {
0066       data_exist = true;
0067       break;
0068     }
0069   }
0070   /// create product (digis & errors)
0071   auto collection = std::make_unique<edm::DetSetVector<CTPPSPixelDigi>>();
0072 
0073   auto errorcollection = std::make_unique<edm::DetSetVector<CTPPSPixelDataError>>();
0074 
0075   if (data_exist) {
0076     mapping = es.getHandle(CTPPSPixelDAQMapping_);
0077 
0078     fedIds_ = mapping->fedIds();
0079 
0080     CTPPSPixelDataFormatter formatter(mapping->ROCMapping, eSummary_);
0081     formatter.setErrorStatus(includeErrors_);
0082 
0083     bool errorsInEvent = false;
0084     CTPPSPixelDataFormatter::DetErrors nodeterrors;
0085 
0086     for (auto aFed = fedIds_.begin(); aFed != fedIds_.end(); ++aFed) {
0087       int fedId = *aFed;
0088 
0089       edm::LogInfo("CTPPSPixelRawToDigi") << " PRODUCE DIGI FOR FED: " << dec << fedId << endl;
0090 
0091       CTPPSPixelDataFormatter::Errors errors;
0092       /// get event data for this fed
0093       const FEDRawData& fedRawData = buffers->FEDData(fedId);
0094 
0095       formatter.interpretRawData(isRun3_, errorsInEvent, fedId, fedRawData, *collection, errors);
0096 
0097       if (includeErrors_) {
0098         for (auto const& is : errors) {
0099           uint32_t errordetid = is.first;
0100           /// errors given dummy detId must be sorted by Fed
0101           if (errordetid == RPixErrorChecker::dummyDetId) {
0102             nodeterrors.insert(nodeterrors.end(), errors[errordetid].begin(), errors[errordetid].end());
0103           } else {
0104             edm::DetSet<CTPPSPixelDataError>& errorDetSet = errorcollection->find_or_insert(errordetid);
0105             errorDetSet.data.insert(errorDetSet.data.end(), is.second.begin(), is.second.end());
0106           }
0107         }
0108       }
0109     }
0110 
0111     if (includeErrors_) {
0112       errorcollection->find_or_insert(RPixErrorChecker::dummyDetId).data = nodeterrors;
0113     }
0114     if (errorsInEvent)
0115       LogDebug("CTPPSPixelRawToDigi") << "Error words were stored in this event";
0116   }
0117   ///send digis and errors back to framework
0118   ev.put(std::move(collection));
0119 
0120   if (includeErrors_) {
0121     ev.put(std::move(errorcollection));
0122   }
0123 }
0124 
0125 void CTPPSPixelRawToDigi::endStream() { eSummary_.printSummary(); }
0126 
0127 DEFINE_FWK_MODULE(CTPPSPixelRawToDigi);