Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  *\ Class EcalRawToDigi
0003  *
0004  * This class takes unpacks ECAL raw data 
0005  * produces digis and raw data format prolblems reports
0006  *
0007  * \file EcalRawToDigi.h
0008  *
0009  * \author N. Almeida
0010  * \author G. Franzoni
0011  *
0012 */
0013 
0014 #include <iostream>
0015 
0016 #include "EventFilter/EcalRawToDigi/interface/DCCRawDataDefinitions.h"
0017 
0018 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
0019 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
0020 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>
0021 #include <DataFormats/EcalDigi/interface/EcalDigiCollections.h>
0022 #include <DataFormats/EcalRawData/interface/EcalRawDataCollections.h>
0023 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
0024 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0025 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
0026 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0027 
0028 #include <DataFormats/Common/interface/Handle.h>
0029 #include <FWCore/Framework/interface/Event.h>
0030 #include "FWCore/Framework/interface/stream/EDProducer.h"
0031 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0032 #include <FWCore/ParameterSet/interface/ParameterSet.h>
0033 #include <FWCore/Framework/interface/ESWatcher.h>
0034 #include "FWCore/Utilities/interface/ESGetToken.h"
0035 #include "DataFormats/EcalRawData/interface/EcalListOfFEDS.h"
0036 #include <sys/time.h>
0037 
0038 class EcalElectronicsMapper;
0039 class EcalElectronicsMapping;
0040 class DCCDataUnpacker;
0041 
0042 class EcalRawToDigi : public edm::stream::EDProducer<> {
0043 public:
0044   /**
0045    * Class constructor
0046    */
0047   explicit EcalRawToDigi(const edm::ParameterSet& ps);
0048 
0049   /**
0050    * Functions that are called by framework at each event
0051    */
0052   void produce(edm::Event& e, const edm::EventSetup& c) override;
0053   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0054 
0055   // function called at start of each run
0056   void beginRun(const edm::Run& run, const edm::EventSetup& es) override;
0057 
0058   /**
0059    * Class destructor
0060    */
0061   ~EcalRawToDigi() override;
0062 
0063   edm::ESWatcher<EcalMappingRcd> watcher_;
0064 
0065 private:
0066   //list of FEDs to unpack
0067   std::vector<int> fedUnpackList_;
0068 
0069   std::vector<int> orderedFedUnpackList_;
0070   std::vector<int> orderedDCCIdList_;
0071 
0072   unsigned int numbXtalTSamples_;
0073   unsigned int numbTriggerTSamples_;
0074 
0075   bool headerUnpacking_;
0076   bool srpUnpacking_;
0077   bool tccUnpacking_;
0078   bool feUnpacking_;
0079   bool memUnpacking_;
0080   bool syncCheck_;
0081   bool feIdCheck_;
0082   bool forceToKeepFRdata_;
0083   bool first_;
0084   bool put_;
0085 
0086   edm::EDGetTokenT<FEDRawDataCollection> dataToken_;
0087   edm::EDGetTokenT<EcalListOfFEDS> fedsToken_;
0088   edm::ESGetToken<EcalChannelStatusMap, EcalChannelStatusRcd> chStatusToken_;
0089   edm::ESGetToken<EcalElectronicsMapping, EcalMappingRcd> ecalMappingToken_;
0090 
0091   // -- For regional unacking :
0092   bool REGIONAL_;
0093 
0094   //an electronics mapper class
0095   EcalElectronicsMapper* myMap_;
0096 
0097   //Ecal unpacker
0098   DCCDataUnpacker* theUnpacker_;
0099 
0100   unsigned int nevts_;  // NA: for testing
0101   double RUNNING_TIME_, SETUP_TIME_;
0102 };
0103 
0104 #include "EventFilter/EcalRawToDigi/interface/EcalElectronicsMapper.h"
0105 #include "EventFilter/EcalRawToDigi/interface/DCCDataUnpacker.h"
0106 
0107 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0108 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0109 
0110 #include "FWCore/Framework/interface/EventSetup.h"
0111 #include "FWCore/Framework/interface/ESHandle.h"
0112 
0113 EcalRawToDigi::EcalRawToDigi(edm::ParameterSet const& conf)
0114     :
0115 
0116       //define the list of FED to be unpacked
0117       fedUnpackList_(conf.getParameter<std::vector<int> >("FEDs")),
0118 
0119       //define the ordered FED list
0120       orderedFedUnpackList_(conf.getParameter<std::vector<int> >("orderedFedList")),
0121 
0122       //define the ordered DCCId list
0123       orderedDCCIdList_(conf.getParameter<std::vector<int> >("orderedDCCIdList")),
0124 
0125       //get number of Xtal Time Samples
0126       numbXtalTSamples_(conf.getParameter<int>("numbXtalTSamples")),
0127 
0128       //Get number of Trigger Time Samples
0129       numbTriggerTSamples_(conf.getParameter<int>("numbTriggerTSamples")),
0130 
0131       //See if header unpacking is enabled
0132       headerUnpacking_(conf.getParameter<bool>("headerUnpacking")),
0133 
0134       //See if srp unpacking is enabled
0135       srpUnpacking_(conf.getParameter<bool>("srpUnpacking")),
0136 
0137       //See if tcc unpacking is enabled
0138       tccUnpacking_(conf.getParameter<bool>("tccUnpacking")),
0139 
0140       //See if fe unpacking is enabled
0141       feUnpacking_(conf.getParameter<bool>("feUnpacking")),
0142 
0143       //See if fe unpacking is enabled for mem box
0144       memUnpacking_(conf.getParameter<bool>("memUnpacking")),
0145 
0146       //See if syncCheck is enabled
0147       syncCheck_(conf.getParameter<bool>("syncCheck")),
0148 
0149       //See if feIdCheck is enabled
0150       feIdCheck_(conf.getParameter<bool>("feIdCheck")),
0151 
0152       // See if we want to keep data even if we have a mismatch between SR decision and block length
0153       forceToKeepFRdata_(conf.getParameter<bool>("forceToKeepFRData")),
0154 
0155       put_(conf.getParameter<bool>("eventPut")),
0156 
0157       REGIONAL_(conf.getParameter<bool>("DoRegional")),
0158 
0159       myMap_(nullptr),
0160 
0161       theUnpacker_(nullptr)
0162 
0163 {
0164   first_ = true;
0165   DCCDataUnpacker::silentMode_ = conf.getUntrackedParameter<bool>("silentMode", false);
0166 
0167   if (numbXtalTSamples_ < 6 || numbXtalTSamples_ > 64 || (numbXtalTSamples_ - 2) % 4) {
0168     std::ostringstream output;
0169     output << "\n Unsuported number of xtal time samples : " << numbXtalTSamples_
0170            << "\n Valid Number of xtal time samples are : 6,10,14,18,...,62";
0171     edm::LogError("IncorrectConfiguration") << output.str();
0172     // todo : throw an execption
0173   }
0174 
0175   if (numbTriggerTSamples_ != 1 && numbTriggerTSamples_ != 4 && numbTriggerTSamples_ != 8) {
0176     std::ostringstream output;
0177     output << "\n Unsuported number of trigger time samples : " << numbTriggerTSamples_
0178            << "\n Valid number of trigger time samples are :  1, 4 or 8";
0179     edm::LogError("IncorrectConfiguration") << output.str();
0180     // todo : throw an execption
0181   }
0182 
0183   //NA : testing
0184   //nevts_=0;
0185   //RUNNING_TIME_=0;
0186 
0187   // if there are FEDs specified to unpack fill the vector of the fedUnpackList_
0188   // else fill with the entire ECAL fed range (600-670)
0189   if (fedUnpackList_.empty())
0190     for (int i = FEDNumbering::MINECALFEDID; i <= FEDNumbering::MAXECALFEDID; i++)
0191       fedUnpackList_.push_back(i);
0192 
0193   //print the FEDs to unpack to the logger
0194   std::ostringstream loggerOutput_;
0195   if (!fedUnpackList_.empty()) {
0196     for (unsigned int i = 0; i < fedUnpackList_.size(); i++)
0197       loggerOutput_ << fedUnpackList_[i] << " ";
0198     edm::LogInfo("EcalRawToDigi") << "EcalRawToDigi will unpack FEDs ( " << loggerOutput_.str() << ")";
0199     LogDebug("EcalRawToDigi") << "EcalRawToDigi will unpack FEDs ( " << loggerOutput_.str() << ")";
0200   }
0201 
0202   edm::LogInfo("EcalRawToDigi") << "\n ECAL RawToDigi configuration:"
0203                                 << "\n Header  unpacking is " << headerUnpacking_ << "\n SRP Bl. unpacking is "
0204                                 << srpUnpacking_ << "\n TCC Bl. unpacking is " << tccUnpacking_
0205                                 << "\n FE  Bl. unpacking is " << feUnpacking_ << "\n MEM Bl. unpacking is "
0206                                 << memUnpacking_ << "\n sync check is " << syncCheck_ << "\n feID check is "
0207                                 << feIdCheck_ << "\n force keep FR data is " << forceToKeepFRdata_ << "\n";
0208 
0209   edm::InputTag dataLabel = conf.getParameter<edm::InputTag>("InputLabel");
0210   edm::InputTag fedsLabel = conf.getParameter<edm::InputTag>("FedLabel");
0211 
0212   // Producer products
0213   if (headerUnpacking_) {
0214     produces<EcalRawDataCollection>();
0215   }
0216 
0217   if (feUnpacking_) {
0218     produces<EBDigiCollection>("ebDigis");
0219     produces<EEDigiCollection>("eeDigis");
0220 
0221     // Integrity for xtal data
0222     produces<EBDetIdCollection>("EcalIntegrityGainErrors");
0223     produces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors");
0224     produces<EBDetIdCollection>("EcalIntegrityChIdErrors");
0225 
0226     // Integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
0227     produces<EEDetIdCollection>("EcalIntegrityGainErrors");
0228     produces<EEDetIdCollection>("EcalIntegrityGainSwitchErrors");
0229     produces<EEDetIdCollection>("EcalIntegrityChIdErrors");
0230 
0231     // Integrity Errors
0232     produces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors");
0233     produces<EcalElectronicsIdCollection>("EcalIntegrityZSXtalIdErrors");
0234     produces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors");
0235 
0236     //
0237     produces<EcalPnDiodeDigiCollection>();
0238   }
0239 
0240   if (srpUnpacking_) {
0241     produces<EBSrFlagCollection>();
0242     produces<EESrFlagCollection>();
0243   }
0244 
0245   if (tccUnpacking_) {
0246     produces<EcalTrigPrimDigiCollection>("EcalTriggerPrimitives");
0247     produces<EcalPSInputDigiCollection>("EcalPseudoStripInputs");
0248   }
0249 
0250   // Mem channels' integrity
0251   if (memUnpacking_) {
0252     produces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors");
0253     produces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSizeErrors");
0254     produces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors");
0255     produces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors");
0256   }
0257 
0258   dataToken_ = consumes<FEDRawDataCollection>(dataLabel);
0259   if (REGIONAL_) {
0260     fedsToken_ = consumes<EcalListOfFEDS>(fedsLabel);
0261   }
0262   chStatusToken_ = esConsumes<EcalChannelStatusMap, EcalChannelStatusRcd, edm::Transition::BeginRun>();
0263   ecalMappingToken_ = esConsumes<EcalElectronicsMapping, EcalMappingRcd>();
0264 
0265   // Build a new Electronics mapper and parse default map file
0266   myMap_ = new EcalElectronicsMapper(numbXtalTSamples_, numbTriggerTSamples_);
0267 
0268   // in case of external  tsext file (deprecated by HLT environment)
0269   //  bool readResult = myMap_->readDCCMapFile(conf.getParameter<std::string>("DCCMapFile",""));
0270 
0271   // use two arrays from cfg to establish DCCId:FedId. If they are empy, than use hard coded correspondence
0272   bool readResult = myMap_->makeMapFromVectors(orderedFedUnpackList_, orderedDCCIdList_);
0273   // myMap::makeMapFromVectors() returns "true" always
0274   // need to be fixed?
0275 
0276   if (!readResult) {
0277     edm::LogWarning("IncorrectConfiguration") << "Arrays orderedFedList and orderedDCCIdList are emply. "
0278                                                  "Hard coded correspondence for DCCId:FedId will be used.";
0279     // edm::LogError("EcalRawToDigi")<<"\n unable to read file : "
0280     //   <<conf.getParameter<std::string>("DCCMapFile");
0281   }
0282 
0283   // Build a new ECAL DCC data unpacker
0284   theUnpacker_ = new DCCDataUnpacker(myMap_,
0285                                      headerUnpacking_,
0286                                      srpUnpacking_,
0287                                      tccUnpacking_,
0288                                      feUnpacking_,
0289                                      memUnpacking_,
0290                                      syncCheck_,
0291                                      feIdCheck_,
0292                                      forceToKeepFRdata_);
0293 }
0294 
0295 // print list of crystals with non-zero statuses
0296 // this functions is only for debug purposes
0297 void printStatusRecords(const DCCDataUnpacker* unpacker, const EcalElectronicsMapping* mapping) {
0298   // Endcap
0299   std::cout << "===> ENDCAP" << std::endl;
0300   for (int i = 0; i < EEDetId::kSizeForDenseIndexing; ++i) {
0301     const EEDetId id = EEDetId::unhashIndex(i);
0302     if (!id.null()) {
0303       // channel status
0304       const uint16_t code = unpacker->getChannelValue(id);
0305 
0306       if (code) {
0307         const EcalElectronicsId ei = mapping->getElectronicsId(id);
0308 
0309         // convert DCC ID (1 - 54) to FED ID (601 - 654)
0310         const int fed_id = unpacker->electronicsMapper()->getDCCId(ei.dccId());
0311 
0312         std::cout << " id " << id.rawId() << " -> (" << id.ix() << ", " << id.iy() << ", " << id.zside() << ") "
0313                   << "(" << ei.dccId() << " : " << fed_id << ", " << ei.towerId() << ", " << ei.stripId() << ", "
0314                   << ei.xtalId() << ") "
0315                   << "status = " << code << std::endl;
0316       }
0317     }
0318   }
0319   std::cout << "<=== ENDCAP" << std::endl;
0320 
0321   std::cout << "===> BARREL" << std::endl;
0322   for (int i = 0; i < EBDetId::kSizeForDenseIndexing; ++i) {
0323     const EBDetId id = EBDetId::unhashIndex(i);
0324     if (!id.null()) {
0325       // channel status
0326       const uint16_t code = unpacker->getChannelValue(id);
0327 
0328       if (code) {
0329         const EcalElectronicsId ei = mapping->getElectronicsId(id);
0330 
0331         // convert DCC ID (1 - 54) to FED ID (601 - 654)
0332         const int fed_id = unpacker->electronicsMapper()->getDCCId(ei.dccId());
0333 
0334         std::cout << " id " << id.rawId() << " -> (" << id.ieta() << ", " << id.iphi() << ", " << id.zside() << ") "
0335                   << "(" << ei.dccId() << " : " << fed_id << ", " << ei.towerId() << ", " << ei.stripId() << ", "
0336                   << ei.xtalId() << ") "
0337                   << "status = " << code << std::endl;
0338       }
0339     }
0340   }
0341   std::cout << "<=== BARREL" << std::endl;
0342 }
0343 
0344 void EcalRawToDigi::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0345   edm::ParameterSetDescription desc;
0346   desc.add<bool>("tccUnpacking", true);
0347   desc.add<edm::InputTag>("FedLabel", edm::InputTag("listfeds"));
0348   desc.add<bool>("srpUnpacking", true);
0349   desc.add<bool>("syncCheck", true);
0350   desc.add<bool>("feIdCheck", true);
0351   desc.addUntracked<bool>("silentMode", true);
0352   desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
0353   {
0354     std::vector<int> temp1;
0355     unsigned int nvec = 54;
0356     temp1.reserve(nvec);
0357     for (unsigned int i = 0; i < nvec; i++)
0358       temp1.push_back(601 + i);
0359     desc.add<std::vector<int> >("orderedFedList", temp1);
0360   }
0361   desc.add<bool>("eventPut", true);
0362   desc.add<int>("numbTriggerTSamples", 1);
0363   desc.add<int>("numbXtalTSamples", 10);
0364   {
0365     std::vector<int> temp1;
0366     unsigned int nvec = 54;
0367     temp1.reserve(nvec);
0368     for (unsigned int i = 0; i < nvec; i++)
0369       temp1.push_back(1 + i);
0370     desc.add<std::vector<int> >("orderedDCCIdList", temp1);
0371   }
0372   {
0373     std::vector<int> temp1;
0374     unsigned int nvec = 54;
0375     temp1.reserve(nvec);
0376     for (unsigned int i = 0; i < nvec; i++)
0377       temp1.push_back(601 + i);
0378     desc.add<std::vector<int> >("FEDs", temp1);
0379   }
0380   desc.add<bool>("DoRegional", false);
0381   desc.add<bool>("feUnpacking", true);
0382   desc.add<bool>("forceToKeepFRData", false);
0383   desc.add<bool>("headerUnpacking", true);
0384   desc.add<bool>("memUnpacking", true);
0385   descriptions.add("ecalRawToDigi", desc);
0386 }
0387 
0388 void EcalRawToDigi::beginRun(const edm::Run&, const edm::EventSetup& es) {
0389   // channel status database
0390   edm::ESHandle<EcalChannelStatusMap> pChStatus = es.getHandle(chStatusToken_);
0391   theUnpacker_->setChannelStatusDB(pChStatus.product());
0392 
0393   // uncomment following line to print list of crystals with bad status
0394   //edm::ESHandle<EcalElectronicsMapping> pEcalMapping;
0395   //es.get<EcalMappingRcd>().get(pEcalMapping);
0396   //const EcalElectronicsMapping* mapping = pEcalMapping.product();
0397   //printStatusRecords(theUnpacker_, mapping);
0398 }
0399 
0400 void EcalRawToDigi::produce(edm::Event& e, const edm::EventSetup& es) {
0401   //double TIME_START = clock();
0402   //nevts_++; //NUNO
0403 
0404   if (first_) {
0405     watcher_.check(es);
0406     edm::ESHandle<EcalElectronicsMapping> ecalmapping = es.getHandle(ecalMappingToken_);
0407     myMap_->setEcalElectronicsMapping(ecalmapping.product());
0408 
0409     first_ = false;
0410 
0411   } else {
0412     if (watcher_.check(es)) {
0413       edm::ESHandle<EcalElectronicsMapping> ecalmapping = es.getHandle(ecalMappingToken_);
0414       myMap_->deletePointers();
0415       myMap_->resetPointers();
0416       myMap_->setEcalElectronicsMapping(ecalmapping.product());
0417     }
0418   }
0419 
0420   // Get list of FEDS :
0421   std::vector<int> FEDS_to_unpack;
0422   if (REGIONAL_) {
0423     edm::Handle<EcalListOfFEDS> listoffeds;
0424     e.getByToken(fedsToken_, listoffeds);
0425     FEDS_to_unpack = listoffeds->GetList();
0426   }
0427 
0428   // Step A: Get Inputs
0429 
0430   edm::Handle<FEDRawDataCollection> rawdata;
0431   e.getByToken(dataToken_, rawdata);
0432 
0433   // Step B: encapsulate vectors in actual collections and set unpacker pointers
0434 
0435   // create the collection of Ecal Digis
0436   auto productDigisEB = std::make_unique<EBDigiCollection>();
0437   productDigisEB->reserve(1700);
0438   theUnpacker_->setEBDigisCollection(&productDigisEB);
0439 
0440   // create the collection of Ecal Digis
0441   auto productDigisEE = std::make_unique<EEDigiCollection>();
0442   theUnpacker_->setEEDigisCollection(&productDigisEE);
0443 
0444   // create the collection for headers
0445   auto productDccHeaders = std::make_unique<EcalRawDataCollection>();
0446   theUnpacker_->setDccHeadersCollection(&productDccHeaders);
0447 
0448   // create the collection for invalid gains
0449   auto productInvalidGains = std::make_unique<EBDetIdCollection>();
0450   theUnpacker_->setInvalidGainsCollection(&productInvalidGains);
0451 
0452   // create the collection for invalid gain Switch
0453   auto productInvalidGainsSwitch = std::make_unique<EBDetIdCollection>();
0454   theUnpacker_->setInvalidGainsSwitchCollection(&productInvalidGainsSwitch);
0455 
0456   // create the collection for invalid chids
0457   auto productInvalidChIds = std::make_unique<EBDetIdCollection>();
0458   theUnpacker_->setInvalidChIdsCollection(&productInvalidChIds);
0459 
0460   ///////////////// make EEDetIdCollections for these ones
0461 
0462   // create the collection for invalid gains
0463   auto productInvalidEEGains = std::make_unique<EEDetIdCollection>();
0464   theUnpacker_->setInvalidEEGainsCollection(&productInvalidEEGains);
0465 
0466   // create the collection for invalid gain Switch
0467   auto productInvalidEEGainsSwitch = std::make_unique<EEDetIdCollection>();
0468   theUnpacker_->setInvalidEEGainsSwitchCollection(&productInvalidEEGainsSwitch);
0469 
0470   // create the collection for invalid chids
0471   auto productInvalidEEChIds = std::make_unique<EEDetIdCollection>();
0472   theUnpacker_->setInvalidEEChIdsCollection(&productInvalidEEChIds);
0473 
0474   ///////////////// make EEDetIdCollections for these ones
0475 
0476   // create the collection for EB srflags
0477   auto productEBSrFlags = std::make_unique<EBSrFlagCollection>();
0478   theUnpacker_->setEBSrFlagsCollection(&productEBSrFlags);
0479 
0480   // create the collection for EB srflags
0481   auto productEESrFlags = std::make_unique<EESrFlagCollection>();
0482   theUnpacker_->setEESrFlagsCollection(&productEESrFlags);
0483 
0484   // create the collection for ecal trigger primitives
0485   auto productEcalTps = std::make_unique<EcalTrigPrimDigiCollection>();
0486   theUnpacker_->setEcalTpsCollection(&productEcalTps);
0487   /////////////////////// collections for problems pertaining towers are already EE+EB communal
0488 
0489   // create the collection for ecal trigger primitives
0490   auto productEcalPSs = std::make_unique<EcalPSInputDigiCollection>();
0491   theUnpacker_->setEcalPSsCollection(&productEcalPSs);
0492   /////////////////////// collections for problems pertaining towers are already EE+EB communal
0493 
0494   // create the collection for invalid TTIds
0495   auto productInvalidTTIds = std::make_unique<EcalElectronicsIdCollection>();
0496   theUnpacker_->setInvalidTTIdsCollection(&productInvalidTTIds);
0497 
0498   // create the collection for invalid TTIds
0499   auto productInvalidZSXtalIds = std::make_unique<EcalElectronicsIdCollection>();
0500   theUnpacker_->setInvalidZSXtalIdsCollection(&productInvalidZSXtalIds);
0501 
0502   // create the collection for invalid BlockLengths
0503   auto productInvalidBlockLengths = std::make_unique<EcalElectronicsIdCollection>();
0504   theUnpacker_->setInvalidBlockLengthsCollection(&productInvalidBlockLengths);
0505 
0506   // MEMs Collections
0507   // create the collection for the Pn Diode Digis
0508   auto productPnDiodeDigis = std::make_unique<EcalPnDiodeDigiCollection>();
0509   theUnpacker_->setPnDiodeDigisCollection(&productPnDiodeDigis);
0510 
0511   // create the collection for invalid Mem Tt id
0512   auto productInvalidMemTtIds = std::make_unique<EcalElectronicsIdCollection>();
0513   theUnpacker_->setInvalidMemTtIdsCollection(&productInvalidMemTtIds);
0514 
0515   // create the collection for invalid Mem Block Size
0516   auto productInvalidMemBlockSizes = std::make_unique<EcalElectronicsIdCollection>();
0517   theUnpacker_->setInvalidMemBlockSizesCollection(&productInvalidMemBlockSizes);
0518 
0519   // create the collection for invalid Mem Block Size
0520   auto productInvalidMemChIds = std::make_unique<EcalElectronicsIdCollection>();
0521   theUnpacker_->setInvalidMemChIdsCollection(&productInvalidMemChIds);
0522 
0523   // create the collection for invalid Mem Gain Errors
0524   auto productInvalidMemGains = std::make_unique<EcalElectronicsIdCollection>();
0525   theUnpacker_->setInvalidMemGainsCollection(&productInvalidMemGains);
0526   //  double TIME_START = clock();
0527 
0528   // Step C: unpack all requested FEDs
0529   for (std::vector<int>::const_iterator i = fedUnpackList_.begin(); i != fedUnpackList_.end(); i++) {
0530     if (REGIONAL_) {
0531       std::vector<int>::const_iterator fed_it = find(FEDS_to_unpack.begin(), FEDS_to_unpack.end(), *i);
0532       if (fed_it == FEDS_to_unpack.end())
0533         continue;
0534     }
0535 
0536     // get fed raw data and SM id
0537     const FEDRawData& fedData = rawdata->FEDData(*i);
0538     const size_t length = fedData.size();
0539 
0540     LogDebug("EcalRawToDigi") << "raw data length: " << length;
0541     //if data size is not null interpret data
0542     if (length >= EMPTYEVENTSIZE) {
0543       if (myMap_->setActiveDCC(*i)) {
0544         const int smId = myMap_->getActiveSM();
0545         LogDebug("EcalRawToDigi") << "Getting FED = " << *i << "(SM = " << smId << ")"
0546                                   << " data size is: " << length;
0547 
0548         const uint64_t* data = (uint64_t*)fedData.data();
0549         theUnpacker_->unpack(data, length, smId, *i);
0550 
0551         LogDebug("EcalRawToDigi") << " in EE :" << productDigisEE->size() << " in EB :" << productDigisEB->size();
0552       }
0553     }
0554 
0555   }  // loop on FEDs
0556 
0557   //if(nevts_>1){   //NUNO
0558   //  double TIME_END = clock(); //NUNO
0559   //  RUNNING_TIME_ += TIME_END-TIME_START; //NUNO
0560   // }
0561 
0562   // Add collections to the event
0563 
0564   if (put_) {
0565     if (headerUnpacking_) {
0566       e.put(std::move(productDccHeaders));
0567     }
0568 
0569     if (feUnpacking_) {
0570       productDigisEB->sort();
0571       e.put(std::move(productDigisEB), "ebDigis");
0572       productDigisEE->sort();
0573       e.put(std::move(productDigisEE), "eeDigis");
0574       e.put(std::move(productInvalidGains), "EcalIntegrityGainErrors");
0575       e.put(std::move(productInvalidGainsSwitch), "EcalIntegrityGainSwitchErrors");
0576       e.put(std::move(productInvalidChIds), "EcalIntegrityChIdErrors");
0577       // EE (leaving for now the same names as in EB)
0578       e.put(std::move(productInvalidEEGains), "EcalIntegrityGainErrors");
0579       e.put(std::move(productInvalidEEGainsSwitch), "EcalIntegrityGainSwitchErrors");
0580       e.put(std::move(productInvalidEEChIds), "EcalIntegrityChIdErrors");
0581       // EE
0582       e.put(std::move(productInvalidTTIds), "EcalIntegrityTTIdErrors");
0583       e.put(std::move(productInvalidZSXtalIds), "EcalIntegrityZSXtalIdErrors");
0584       e.put(std::move(productInvalidBlockLengths), "EcalIntegrityBlockSizeErrors");
0585       e.put(std::move(productPnDiodeDigis));
0586     }
0587     if (memUnpacking_) {
0588       e.put(std::move(productInvalidMemTtIds), "EcalIntegrityMemTtIdErrors");
0589       e.put(std::move(productInvalidMemBlockSizes), "EcalIntegrityMemBlockSizeErrors");
0590       e.put(std::move(productInvalidMemChIds), "EcalIntegrityMemChIdErrors");
0591       e.put(std::move(productInvalidMemGains), "EcalIntegrityMemGainErrors");
0592     }
0593     if (srpUnpacking_) {
0594       e.put(std::move(productEBSrFlags));
0595       e.put(std::move(productEESrFlags));
0596     }
0597     if (tccUnpacking_) {
0598       e.put(std::move(productEcalTps), "EcalTriggerPrimitives");
0599       e.put(std::move(productEcalPSs), "EcalPseudoStripInputs");
0600     }
0601   }
0602 
0603   //if(nevts_>1){   //NUNO
0604   //  double TIME_END = clock(); //NUNO
0605   //  RUNNING_TIME_ += TIME_END-TIME_START; //NUNO
0606   //}
0607 }
0608 
0609 EcalRawToDigi::~EcalRawToDigi() {
0610   //cout << "EcalDCCUnpackingModule  " << "N events        " << (nevts_-1)<<endl;
0611   //cout << "EcalDCCUnpackingModule  " << " --- SETUP time " << endl;
0612   //cout << "EcalDCCUnpackingModule  " << "Time (sys)      " << SETUP_TIME_ << endl;
0613   //cout << "EcalDCCUnpackingModule  " << "Time in sec.    " << SETUP_TIME_/ CLOCKS_PER_SEC  << endl;
0614   //cout << "EcalDCCUnpackingModule  " << " --- Per event  " << endl;
0615 
0616   //RUNNING_TIME_ = RUNNING_TIME_ / (nevts_-1);
0617 
0618   //cout << "EcalDCCUnpackingModule  "<< "Time (sys)      " << RUNNING_TIME_  << endl;
0619   //cout << "EcalDCCUnpackingModule  "<< "Time in sec.    " << RUNNING_TIME_ / CLOCKS_PER_SEC  << endl;
0620 
0621   if (myMap_)
0622     delete myMap_;
0623   if (theUnpacker_)
0624     delete theUnpacker_;
0625 }
0626 
0627 #include "FWCore/Framework/interface/MakerMacros.h"
0628 DEFINE_FWK_MODULE(EcalRawToDigi);