Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /** \class CSCDCCUnpacker
0002  *
0003  *
0004  * \author Alex Tumanov
0005  */
0006 
0007 //Framework stuff
0008 #include "DataFormats/Common/interface/Handle.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/ConsumesCollector.h"
0011 #include "FWCore/Framework/interface/stream/EDProducer.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/Utilities/interface/InputTag.h"
0019 #include "FWCore/Utilities/interface/ESGetToken.h"
0020 #include "FWCore/ServiceRegistry/interface/Service.h"
0021 
0022 #include "CondFormats/CSCObjects/interface/CSCCrateMap.h"
0023 #include "CondFormats/DataRecord/interface/CSCCrateMapRcd.h"
0024 #include "CondFormats/CSCObjects/interface/CSCChamberMap.h"
0025 #include "CondFormats/DataRecord/interface/CSCChamberMapRcd.h"
0026 
0027 //FEDRawData
0028 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0029 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0030 
0031 //Digi stuff
0032 
0033 #include "DataFormats/CSCDigi/interface/CSCConstants.h"
0034 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
0035 #include "DataFormats/CSCDigi/interface/CSCCFEBStatusDigiCollection.h"
0036 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
0037 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
0038 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
0039 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
0040 #include "DataFormats/CSCDigi/interface/CSCRPCDigiCollection.h"
0041 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
0042 #include "DataFormats/CSCDigi/interface/CSCShowerDigiCollection.h"
0043 #include "DataFormats/GEMDigi/interface/GEMPadDigiClusterCollection.h"
0044 #include "DataFormats/CSCDigi/interface/CSCDMBStatusDigiCollection.h"
0045 #include "DataFormats/CSCDigi/interface/CSCTMBStatusDigiCollection.h"
0046 #include "DataFormats/CSCDigi/interface/CSCDDUStatusDigiCollection.h"
0047 #include "DataFormats/CSCDigi/interface/CSCDCCStatusDigiCollection.h"
0048 #include "DataFormats/CSCDigi/interface/CSCALCTStatusDigiCollection.h"
0049 #include "DataFormats/CSCDigi/interface/CSCALCTStatusDigiCollection.h"
0050 #include "DataFormats/CSCDigi/interface/CSCDCCFormatStatusDigiCollection.h"
0051 
0052 #include "EventFilter/CSCRawToDigi/interface/CSCEventData.h"
0053 #include "EventFilter/CSCRawToDigi/interface/CSCTMBData.h"
0054 #include "EventFilter/CSCRawToDigi/interface/CSCDCCEventData.h"
0055 #include "EventFilter/CSCRawToDigi/interface/CSCCFEBData.h"
0056 #include "EventFilter/CSCRawToDigi/interface/CSCGEMData.h"
0057 #include "EventFilter/CSCRawToDigi/interface/CSCMonitorInterface.h"
0058 
0059 #include <iostream>
0060 #include <sstream>
0061 #include <string>
0062 #include <iomanip>
0063 #include <cstdio>
0064 
0065 class CSCMonitorInterface;
0066 
0067 class CSCDCCUnpacker : public edm::stream::EDProducer<> {
0068 public:
0069   /// Constructor
0070   CSCDCCUnpacker(const edm::ParameterSet& pset);
0071 
0072   /// Destructor
0073   ~CSCDCCUnpacker() override;
0074 
0075   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0076 
0077   /// Produce digis out of raw data
0078   void produce(edm::Event& e, const edm::EventSetup& c) override;
0079 
0080   /// Visualization of raw data in FED-less events (Robert Harr and Alexander Sakharov)
0081   void visual_raw(int hl, int id, int run, int event, bool fedshort, bool fDump, short unsigned int* buf) const;
0082 
0083 private:
0084   bool debug, printEventNumber, goodEvent, useExaminer, unpackStatusDigis;
0085   bool useSelectiveUnpacking, useFormatStatus;
0086 
0087   /// option to unpack RPC data
0088   bool useRPCs_;
0089 
0090   /// option to unpack GEM cluster data
0091   bool useGEMs_;
0092 
0093   /// option to unpack CSC shower data
0094   bool useCSCShowers_;
0095 
0096   /// Visualization of raw data
0097   bool visualFEDInspect, visualFEDShort, formatedEventDump;
0098   /// Suppress zeros LCTs
0099   bool SuppressZeroLCT;
0100 
0101   int numOfEvents;
0102   unsigned int errorMask, examinerMask;
0103   bool instantiateDQM;
0104 
0105   bool disableMappingCheck, b904Setup;
0106   int b904vmecrate, b904dmb;
0107 
0108   CSCMonitorInterface* monitor;
0109 
0110   /// Token for consumes interface & access to data
0111   edm::EDGetTokenT<FEDRawDataCollection> i_token;
0112   edm::ESGetToken<CSCCrateMap, CSCCrateMapRcd> crateToken;
0113   edm::ESGetToken<CSCChamberMap, CSCChamberMapRcd> cscmapToken;
0114 };
0115 
0116 CSCDCCUnpacker::CSCDCCUnpacker(const edm::ParameterSet& pset) : numOfEvents(0) {
0117   // Tracked
0118   i_token = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("InputObjects"));
0119   crateToken = esConsumes<CSCCrateMap, CSCCrateMapRcd>();
0120   cscmapToken = esConsumes<CSCChamberMap, CSCChamberMapRcd>();
0121 
0122   useExaminer = pset.getParameter<bool>("UseExaminer");
0123   examinerMask = pset.getParameter<unsigned int>("ExaminerMask");
0124   /// Selective unpacking mode will skip only troublesome CSC blocks and not whole DCC/DDU block
0125   useSelectiveUnpacking = pset.getParameter<bool>("UseSelectiveUnpacking");
0126   errorMask = pset.getParameter<unsigned int>("ErrorMask");
0127   unpackStatusDigis = pset.getParameter<bool>("UnpackStatusDigis");
0128   /// Enable Format Status Digis
0129   useFormatStatus = pset.getParameter<bool>("UseFormatStatus");
0130 
0131   useRPCs_ = pset.getParameter<bool>("useRPCs");
0132   useGEMs_ = pset.getParameter<bool>("useGEMs");
0133   useCSCShowers_ = pset.getParameter<bool>("useCSCShowers");
0134 
0135   // Untracked
0136   printEventNumber = pset.getUntrackedParameter<bool>("PrintEventNumber", true);
0137   debug = pset.getUntrackedParameter<bool>("Debug", false);
0138   instantiateDQM = pset.getUntrackedParameter<bool>("runDQM", false);
0139 
0140   // Disable FED/DDU to chamber mapping inconsistency check
0141   disableMappingCheck = pset.getUntrackedParameter<bool>("DisableMappingCheck", false);
0142   // Make aware the unpacker that B904 test setup is used (disable mapping inconsistency check)
0143   b904Setup = pset.getUntrackedParameter<bool>("B904Setup", false);
0144   b904vmecrate = pset.getUntrackedParameter<int>("B904vmecrate", 1);
0145   b904dmb = pset.getUntrackedParameter<int>("B904dmb", 3);
0146 
0147   /// Visualization of raw data
0148   visualFEDInspect = pset.getUntrackedParameter<bool>("VisualFEDInspect", false);
0149   visualFEDShort = pset.getUntrackedParameter<bool>("VisualFEDShort", false);
0150   formatedEventDump = pset.getUntrackedParameter<bool>("FormatedEventDump", false);
0151 
0152   /// Suppress zeros LCTs
0153   SuppressZeroLCT = pset.getUntrackedParameter<bool>("SuppressZeroLCT", true);
0154 
0155   if (instantiateDQM) {
0156     monitor = edm::Service<CSCMonitorInterface>().operator->();
0157   }
0158 
0159   produces<CSCWireDigiCollection>("MuonCSCWireDigi");
0160   produces<CSCStripDigiCollection>("MuonCSCStripDigi");
0161   produces<CSCComparatorDigiCollection>("MuonCSCComparatorDigi");
0162   produces<CSCALCTDigiCollection>("MuonCSCALCTDigi");
0163   produces<CSCCLCTDigiCollection>("MuonCSCCLCTDigi");
0164   produces<CSCCorrelatedLCTDigiCollection>("MuonCSCCorrelatedLCTDigi");
0165 
0166   if (unpackStatusDigis) {
0167     produces<CSCCFEBStatusDigiCollection>("MuonCSCCFEBStatusDigi");
0168     produces<CSCTMBStatusDigiCollection>("MuonCSCTMBStatusDigi");
0169     produces<CSCDMBStatusDigiCollection>("MuonCSCDMBStatusDigi");
0170     produces<CSCALCTStatusDigiCollection>("MuonCSCALCTStatusDigi");
0171     produces<CSCDDUStatusDigiCollection>("MuonCSCDDUStatusDigi");
0172     produces<CSCDCCStatusDigiCollection>("MuonCSCDCCStatusDigi");
0173   }
0174 
0175   if (useFormatStatus) {
0176     produces<CSCDCCFormatStatusDigiCollection>("MuonCSCDCCFormatStatusDigi");
0177   }
0178 
0179   if (useRPCs_) {
0180     produces<CSCRPCDigiCollection>("MuonCSCRPCDigi");
0181   }
0182 
0183   if (useGEMs_) {
0184     produces<GEMPadDigiClusterCollection>("MuonGEMPadDigiCluster");
0185   }
0186 
0187   if (useCSCShowers_) {
0188     produces<CSCShowerDigiCollection>("MuonCSCShowerDigi");
0189     produces<CSCShowerDigiCollection>("MuonCSCShowerDigiAnode");
0190     produces<CSCShowerDigiCollection>("MuonCSCShowerDigiCathode");
0191     produces<CSCShowerDigiCollection>("MuonCSCShowerDigiAnodeALCT");
0192   }
0193 
0194   //CSCAnodeData::setDebug(debug);
0195   CSCALCTHeader::setDebug(debug);
0196   CSCComparatorData::setDebug(debug);
0197   CSCEventData::setDebug(debug);
0198   CSCTMBData::setDebug(debug);
0199   CSCDCCEventData::setDebug(debug);
0200   CSCDDUEventData::setDebug(debug);
0201   CSCTMBHeader::setDebug(debug);
0202   CSCRPCData::setDebug(debug);
0203   CSCDDUEventData::setErrorMask(errorMask);
0204 }
0205 
0206 CSCDCCUnpacker::~CSCDCCUnpacker() {
0207   //fill destructor here
0208 }
0209 
0210 void CSCDCCUnpacker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0211   edm::ParameterSetDescription desc;
0212   desc.add<edm::InputTag>("InputObjects", edm::InputTag("rawDataCollector"))
0213       ->setComment("# Define input to the unpacker");
0214   desc.add<bool>("UseExaminer", true)
0215       ->setComment("# Use CSC examiner to check for corrupt or semi-corrupt data & avoid unpacker crashes");
0216   desc.add<unsigned int>("ExaminerMask", 535557110)->setComment("# This mask is needed by the examiner");
0217   desc.add<bool>("UseSelectiveUnpacking", true)
0218       ->setComment("# Use Examiner to unpack good chambers and skip only bad ones");
0219   desc.add<unsigned int>("ErrorMask", 0)->setComment("# This mask simply reduces error reporting");
0220   desc.add<bool>("UnpackStatusDigis", false)->setComment("# Unpack general status digis?");
0221   desc.add<bool>("UseFormatStatus", true)->setComment("# Unpack FormatStatus digi?");
0222   desc.add<bool>("useRPCs", false)->setComment("Unpack RPC data");
0223   desc.add<bool>("useGEMs", true)->setComment("Unpack GEM trigger data");
0224   desc.add<bool>("useCSCShowers", true)->setComment("Unpack CSCShower trigger data");
0225   desc.addUntracked<bool>("Debug", false)->setComment("# Turn on lots of output");
0226   desc.addUntracked<bool>("PrintEventNumber", false);
0227   desc.addUntracked<bool>("runDQM", false);
0228   desc.addUntracked<bool>("VisualFEDInspect", false)->setComment("# Visualization of raw data in corrupted events");
0229   desc.addUntracked<bool>("VisualFEDShort", false)->setComment("# Visualization of raw data in corrupted events");
0230   desc.addUntracked<bool>("FormatedEventDump", false);
0231   desc.addUntracked<bool>("SuppressZeroLCT", true);
0232   desc.addUntracked<bool>("DisableMappingCheck", false)
0233       ->setComment("# Disable FED/DDU to chamber mapping inconsistency check");
0234   desc.addUntracked<bool>("B904Setup", false)->setComment("# Make the unpacker aware of B904 test setup configuration");
0235   desc.addUntracked<int>("B904vmecrate", 1)->setComment("# Set vmecrate number for chamber used in B904 test setup");
0236   desc.addUntracked<int>("B904dmb", 3)->setComment("# Set dmb slot for chamber used in B904 test setup");
0237   descriptions.add("muonCSCDCCUnpacker", desc);
0238   descriptions.setComment(" This is the generic cfi file for CSC unpacking");
0239 }
0240 
0241 void CSCDCCUnpacker::produce(edm::Event& e, const edm::EventSetup& c) {
0242   ///access database for mapping
0243   // Do we really have to do this every event???
0244   // ... Yes, because framework is more efficient than you are at caching :)
0245   // (But if you want to actually DO something specific WHEN the mapping changes, check out ESWatcher)
0246   edm::ESHandle<CSCCrateMap> hcrate = c.getHandle(crateToken);
0247   const CSCCrateMap* pcrate = hcrate.product();
0248 
0249   // Need access to CSCChamberMap for chamber<->FED/DDU mapping consistency checks
0250   edm::ESHandle<CSCChamberMap> cscmap = c.getHandle(cscmapToken);
0251   const CSCChamberMap* cscmapping = cscmap.product();
0252 
0253   if (printEventNumber)
0254     ++numOfEvents;
0255 
0256   /// Get a handle to the FED data collection
0257   edm::Handle<FEDRawDataCollection> rawdata;
0258   e.getByToken(i_token, rawdata);
0259 
0260   /// create the collections of CSC digis
0261   auto wireProduct = std::make_unique<CSCWireDigiCollection>();
0262   auto stripProduct = std::make_unique<CSCStripDigiCollection>();
0263   auto alctProduct = std::make_unique<CSCALCTDigiCollection>();
0264   auto clctProduct = std::make_unique<CSCCLCTDigiCollection>();
0265   auto comparatorProduct = std::make_unique<CSCComparatorDigiCollection>();
0266   auto rpcProduct = std::make_unique<CSCRPCDigiCollection>();
0267   auto corrlctProduct = std::make_unique<CSCCorrelatedLCTDigiCollection>();
0268   auto cfebStatusProduct = std::make_unique<CSCCFEBStatusDigiCollection>();
0269   auto dmbStatusProduct = std::make_unique<CSCDMBStatusDigiCollection>();
0270   auto tmbStatusProduct = std::make_unique<CSCTMBStatusDigiCollection>();
0271   auto dduStatusProduct = std::make_unique<CSCDDUStatusDigiCollection>();
0272   auto dccStatusProduct = std::make_unique<CSCDCCStatusDigiCollection>();
0273   auto alctStatusProduct = std::make_unique<CSCALCTStatusDigiCollection>();
0274 
0275   auto formatStatusProduct = std::make_unique<CSCDCCFormatStatusDigiCollection>();
0276 
0277   auto gemProduct = std::make_unique<GEMPadDigiClusterCollection>();
0278 
0279   auto lctShowerProduct =
0280       std::make_unique<CSCShowerDigiCollection>();  // HMT shower objects from OTMB/MPC LCT trigger data frames
0281   auto anodeShowerProductOTMB =
0282       std::make_unique<CSCShowerDigiCollection>();  // anode HMT shower objects from (O)TMB header data (matched at OTMB)
0283   auto cathodeShowerProductOTMB =
0284       std::make_unique<CSCShowerDigiCollection>();  // cathode HMT shower objects from (O)TMB header data
0285   auto anodeShowerProductALCT = std::make_unique<
0286       CSCShowerDigiCollection>();  // anode HMT shower objects from ALCT data (vector of HMT shower objects per ALCT BX)
0287 
0288   // If set selective unpacking mode
0289   // hardcoded examiner mask below to check for DCC and DDU level errors will be used first
0290   // then examinerMask for CSC level errors will be used during unpacking of each CSC block
0291   unsigned long dccBinCheckMask = 0x06080016;
0292 
0293   // Post-LS1 FED/DDU ID mapping fix
0294   const unsigned postLS1_map[] = {841, 842, 843, 844, 845, 846, 847, 848, 849, 831, 832, 833,
0295                                   834, 835, 836, 837, 838, 839, 861, 862, 863, 864, 865, 866,
0296                                   867, 868, 869, 851, 852, 853, 854, 855, 856, 857, 858, 859};
0297 
0298   // For new CSC readout layout, which wont include DCCs need to loop over DDU FED IDs. DCC IDs are included for backward compatibility with old data
0299   std::vector<unsigned int> cscFEDids;
0300 
0301   for (unsigned int id = FEDNumbering::MINCSCFEDID; id <= FEDNumbering::MAXCSCFEDID; ++id)  // loop over DCCs
0302   {
0303     cscFEDids.push_back(id);
0304   }
0305 
0306   for (unsigned int id = FEDNumbering::MINCSCDDUFEDID; id <= FEDNumbering::MAXCSCDDUFEDID; ++id)  // loop over DDUs
0307   {
0308     cscFEDids.push_back(id);
0309   }
0310 
0311   for (unsigned int i = 0; i < cscFEDids.size(); i++)  // loop over all CSC FEDs (DCCs and DDUs)
0312   {
0313     unsigned int id = cscFEDids[i];
0314     bool isDDU_FED = ((id >= FEDNumbering::MINCSCDDUFEDID) && (id <= FEDNumbering::MAXCSCDDUFEDID)) ? true : false;
0315 
0316     /// uncomment this for regional unpacking
0317     /// if (id!=SOME_ID) continue;
0318 
0319     /// Take a reference to this FED's data
0320     const FEDRawData& fedData = rawdata->FEDData(id);
0321     unsigned long length = fedData.size();
0322 
0323     if (length >= 32)  ///if fed has data then unpack it
0324     {
0325       CSCDCCExaminer* examiner = nullptr;
0326       goodEvent = true;
0327       if (useExaminer)  ///examine event for integrity
0328       {
0329         // CSCDCCExaminer examiner;
0330         examiner = new CSCDCCExaminer();
0331         if (examinerMask & 0x40000)
0332           examiner->crcCFEB(true);
0333         if (examinerMask & 0x8000)
0334           examiner->crcTMB(true);
0335         if (examinerMask & 0x0400)
0336           examiner->crcALCT(true);
0337         examiner->setMask(examinerMask);
0338 
0339         /// If we have DCC or only DDU FED by checking FED ID set examiner to uswe DCC or DDU mode
0340         if (isDDU_FED) {
0341           if (examiner != nullptr)
0342             examiner->modeDDU(true);
0343         }
0344 
0345         const short unsigned int* data = (short unsigned int*)fedData.data();
0346 
0347         LogTrace("badData") << "Length: " << length / 2;
0348         // Event data hex dump
0349         /*
0350               short unsigned * buf = (short unsigned int *)fedData.data();
0351                 std::cout <<std::endl<<length/2<<" words of data:"<<std::endl;
0352                 for (short unsigned int i=0;i<length/2;i++) {
0353                 printf("%04x %04x %04x %04x\n",buf[i+3],buf[i+2],buf[i+1],buf[i]);
0354                 i+=3;
0355                 }
0356                       */
0357 
0358         int res = examiner->check(data, long(fedData.size() / 2));
0359         if (res < 0) {
0360           goodEvent = false;
0361         } else {
0362           if (useSelectiveUnpacking)
0363             goodEvent = !(examiner->errors() & dccBinCheckMask);
0364           else
0365             goodEvent = !(examiner->errors() & examinerMask);
0366         }
0367 
0368         /*
0369         std::cout << "FED" << std::dec << id << " size:" << fedData.size() << " good:" << goodEvent << " errs 0x"
0370               << std::hex << examiner->errors() << std::dec << std::endl;
0371          */
0372 
0373         // Fill Format status digis per FED
0374         // Remove examiner->errors() != 0 check if we need to put status digis for every event
0375         if (useFormatStatus && (examiner->errors() != 0))
0376           // formatStatusProduct->insertDigi(CSCDetId(1,1,1,1,1), CSCDCCFormatStatusDigi(id,examiner,dccBinCheckMask));
0377           formatStatusProduct->insertDigi(CSCDetId(1, 1, 1, 1, 1),
0378                                           CSCDCCFormatStatusDigi(id,
0379                                                                  dccBinCheckMask,
0380                                                                  examiner->getMask(),
0381                                                                  examiner->errors(),
0382                                                                  examiner->errorsDetailedDDU(),
0383                                                                  examiner->errorsDetailed(),
0384                                                                  examiner->payloadDetailed(),
0385                                                                  examiner->statusDetailed()));
0386       }
0387 
0388       /// Visualization of raw data
0389       if (visualFEDInspect || formatedEventDump) {
0390         if (!goodEvent || formatedEventDump) {
0391           short unsigned* buf = (short unsigned int*)fedData.data();
0392           visual_raw(length / 2, id, (int)e.id().run(), (int)e.id().event(), visualFEDShort, formatedEventDump, buf);
0393         }
0394       }
0395 
0396       if (goodEvent) {
0397         ///get a pointer to data and pass it to constructor for unpacking
0398 
0399         CSCDCCExaminer* ptrExaminer = examiner;
0400         if (!useSelectiveUnpacking)
0401           ptrExaminer = nullptr;
0402 
0403         std::vector<CSCDDUEventData> fed_Data;
0404         std::vector<CSCDDUEventData>* ptr_fedData = &fed_Data;
0405 
0406         /// set default detid to that for E=+z, S=1, R=1, C=1, L=1
0407         CSCDetId layer(1, 1, 1, 1, 1);
0408 
0409         if (isDDU_FED)  // Use new DDU FED readout mode
0410         {
0411           CSCDDUEventData single_dduData((short unsigned int*)fedData.data(), ptrExaminer);
0412           fed_Data.push_back(single_dduData);
0413 
0414           // if(instantiateDQM) monitor->process(examiner, &single_dduData);
0415 
0416         } else  // Use old DCC FED readout mode
0417         {
0418           CSCDCCEventData dccData((short unsigned int*)fedData.data(), ptrExaminer);
0419 
0420           //std::cout << " DCC Size [UNPK] " << dccData.sizeInWords() << std::endl;
0421 
0422           if (instantiateDQM)
0423             monitor->process(examiner, &dccData);
0424 
0425           ///get a reference to dduData
0426           // const std::vector<CSCDDUEventData> & dduData = dccData.dduData();
0427           // ptr_fedData = &(dccData.dduData());
0428           fed_Data = dccData.dduData();
0429 
0430           if (unpackStatusDigis) {
0431             /// DCC Trailer 2 added to dcc status product (to access TTS from DCC)
0432             short unsigned* bufForDcc = (short unsigned int*)fedData.data();
0433 
0434             //std::cout << "FED Length: " << std::dec << length/2 <<
0435             //" Trailer 2: " << std::hex << bufForDcc[length/2-4] << std::endl;
0436 
0437             dccStatusProduct->insertDigi(layer,
0438                                          CSCDCCStatusDigi(dccData.dccHeader().data(),
0439                                                           dccData.dccTrailer().data(),
0440                                                           examiner->errors(),
0441                                                           bufForDcc[length / 2 - 4]));
0442           }
0443         }
0444 
0445         const std::vector<CSCDDUEventData>& dduData = *ptr_fedData;
0446 
0447         for (unsigned int iDDU = 0; iDDU < dduData.size(); ++iDDU)  // loop over DDUs
0448         {
0449           /// skip the DDU if its data has serious errors
0450           /// define a mask for serious errors
0451           if (dduData[iDDU].trailer().errorstat() & errorMask) {
0452             LogTrace("CSCDCCUnpacker|CSCRawToDigi")
0453                 << "FED ID" << id << " DDU# " << iDDU << " has serious error - no digis unpacked! " << std::hex
0454                 << dduData[iDDU].trailer().errorstat();
0455             continue;  // to next iteration of DDU loop
0456           }
0457 
0458           if (unpackStatusDigis)
0459             dduStatusProduct->insertDigi(
0460                 layer,
0461                 CSCDDUStatusDigi(dduData[iDDU].header().data(),
0462                                  dduData[iDDU].trailer().data(),
0463                                  /// DDU Trailer 0 added to ddu status product (to access TTS from DDU)
0464                                  dduData[iDDU].trailer0()));
0465 
0466           ///get a reference to chamber data
0467           const std::vector<CSCEventData>& cscData = dduData[iDDU].cscData();
0468 
0469           // if (cscData.size() != 0) std::cout << "FED" << id << " DDU Source ID: " << dduData[iDDU].header().source_id() << " firmware version: " << dduData[iDDU].header().format_version() << std::endl;
0470 
0471           for (unsigned int iCSC = 0; iCSC < cscData.size(); ++iCSC)  // loop over CSCs
0472           {
0473             ///first process chamber-wide digis such as LCT
0474 
0475             int vmecrate = b904Setup ? b904vmecrate : cscData[iCSC].dmbHeader()->crateID();
0476             int dmb = b904Setup ? b904dmb : cscData[iCSC].dmbHeader()->dmbID();
0477 
0478             int icfeb = 0;   /// default value for all digis not related to cfebs
0479             int ilayer = 0;  /// layer=0 flags entire chamber
0480 
0481             if (debug)
0482               LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "crate = " << vmecrate << "; dmb = " << dmb;
0483 
0484             if ((vmecrate >= 1) && (vmecrate <= 60) && (dmb >= 1) && (dmb <= 10) && (dmb != 6)) {
0485               layer = pcrate->detId(vmecrate, dmb, icfeb, ilayer);
0486             } else {
0487               LogTrace("CSCDCCUnpacker|CSCRawToDigi") << " detID input out of range!!! ";
0488               LogTrace("CSCDCCUnpacker|CSCRawToDigi") << " skipping chamber vme= " << vmecrate << " dmb= " << dmb;
0489               continue;  // to next iteration of iCSC loop
0490             }
0491 
0492             /// For Post-LS1 readout only. Check Chamber->FED/DDU mapping consistency.
0493             /// Skip chambers (special case of data corruption), which report wrong ID and pose as different chamber
0494             if (isDDU_FED) {
0495               unsigned int dduid = cscmapping->ddu(layer);
0496               if ((dduid >= 1) && (dduid <= 36)) {
0497                 dduid = postLS1_map[dduid - 1];  // Fix for Post-LS1 FED/DDU IDs mappings
0498                 // std::cout << "CSC " << layer << " -> " << id << ":" << dduid << ":" << vmecrate << ":" << dmb << std::endl;
0499               }
0500 
0501               /// Do not skip chamber data if mapping check is disabled or b904 setup data file is used
0502               if ((!disableMappingCheck) && (!b904Setup) && (id != dduid)) {
0503                 LogTrace("CSCDDUUnpacker|CSCRawToDigi") << " CSC->FED/DDU mapping inconsistency!!! ";
0504                 LogTrace("CSCDCCUnpacker|CSCRawToDigi")
0505                     << "readout FED/DDU ID=" << id << " expected ID=" << dduid << ", skipping chamber " << layer
0506                     << " vme= " << vmecrate << " dmb= " << dmb;
0507                 continue;
0508               }
0509             }
0510 
0511             /// check alct data integrity
0512             int nalct = cscData[iCSC].dmbHeader()->nalct();
0513             bool goodALCT = false;
0514             //if (nalct&&(cscData[iCSC].dataPresent>>6&0x1)==1) {
0515             if (nalct && cscData[iCSC].alctHeader()) {
0516               if (cscData[iCSC].alctHeader()->check()) {
0517                 goodALCT = true;
0518               } else {
0519                 LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "not storing ALCT digis; alct is bad or not present";
0520               }
0521             } else {
0522               if (debug)
0523                 LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "nALCT==0 !!!";
0524             }
0525 
0526             /// fill alct digi
0527             if (goodALCT) {
0528               std::vector<CSCALCTDigi> alctDigis = cscData[iCSC].alctHeader()->ALCTDigis();
0529               if (SuppressZeroLCT) {
0530                 std::vector<CSCALCTDigi> alctDigis_0;
0531                 for (int unsigned i = 0; i < alctDigis.size(); ++i) {
0532                   if (alctDigis[i].isValid()) {
0533                     if (debug)
0534                       LogTrace("CSCDCCUnpacker|CSCRawToDigi") << alctDigis[i] << std::endl;
0535                     alctDigis_0.push_back(alctDigis[i]);
0536                   }
0537                 }
0538                 alctProduct->move(std::make_pair(alctDigis_0.begin(), alctDigis_0.end()), layer);
0539               } else
0540                 alctProduct->move(std::make_pair(alctDigis.begin(), alctDigis.end()), layer);
0541 
0542               /// fill Run3 anode HMT Shower digis
0543               /// anode shower digis vector per ALCT BX from ALCT data
0544               if (useCSCShowers_) {
0545                 std::vector<CSCShowerDigi> anodeShowerDigisALCT = cscData[iCSC].alctHeader()->alctShowerDigis();
0546                 anodeShowerProductALCT->move(std::make_pair(anodeShowerDigisALCT.begin(), anodeShowerDigisALCT.end()),
0547                                              layer);
0548               }
0549             }
0550 
0551             ///check tmb data integrity
0552             int nclct = cscData[iCSC].dmbHeader()->nclct();
0553             bool goodTMB = false;
0554             //      if (nclct&&(cscData[iCSC].dataPresent>>5&0x1)==1) {
0555             if (nclct && cscData[iCSC].tmbData()) {
0556               if (cscData[iCSC].tmbHeader()->check()) {
0557                 if (cscData[iCSC].comparatorData()->check())
0558                   goodTMB = true;
0559               } else {
0560                 LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "one of TMB checks failed! not storing TMB digis ";
0561               }
0562             } else {
0563               if (debug)
0564                 LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "nCLCT==0 !!!";
0565             }
0566 
0567             /// fill correlatedlct and clct digis
0568             if (goodTMB) {
0569               std::vector<CSCCorrelatedLCTDigi> correlatedlctDigis =
0570                   cscData[iCSC].tmbHeader()->CorrelatedLCTDigis(layer.rawId());
0571               if (SuppressZeroLCT) {
0572                 std::vector<CSCCorrelatedLCTDigi> correlatedlctDigis_0;
0573                 for (int unsigned i = 0; i < correlatedlctDigis.size(); ++i) {
0574                   if (correlatedlctDigis[i].isValid()) {
0575                     if (debug)
0576                       LogTrace("CSCDCCUnpacker|CSCRawToDigi") << correlatedlctDigis[i] << std::endl;
0577                     correlatedlctDigis_0.push_back(correlatedlctDigis[i]);
0578                   }
0579                 }
0580                 corrlctProduct->move(std::make_pair(correlatedlctDigis_0.begin(), correlatedlctDigis_0.end()), layer);
0581               } else
0582                 corrlctProduct->move(std::make_pair(correlatedlctDigis.begin(), correlatedlctDigis.end()), layer);
0583 
0584               std::vector<CSCCLCTDigi> clctDigis = cscData[iCSC].tmbHeader()->CLCTDigis(layer.rawId());
0585               if (SuppressZeroLCT) {
0586                 std::vector<CSCCLCTDigi> clctDigis_0;
0587                 for (int unsigned i = 0; i < clctDigis.size(); ++i) {
0588                   if (clctDigis[i].isValid()) {
0589                     if (debug)
0590                       LogTrace("CSCDCCUnpacker|CSCRawToDigi") << clctDigis[i] << std::endl;
0591                     clctDigis_0.push_back(clctDigis[i]);
0592                   }
0593                 }
0594                 clctProduct->move(std::make_pair(clctDigis_0.begin(), clctDigis_0.end()), layer);
0595               } else
0596                 clctProduct->move(std::make_pair(clctDigis.begin(), clctDigis.end()), layer);
0597 
0598               /// fill Run3 HMT Shower digis
0599               if (useCSCShowers_) {
0600                 /// (O)TMB Shower digi sent to MPC LCT trigger data
0601                 CSCShowerDigi lctShowerDigi = cscData[iCSC].tmbHeader()->showerDigi(layer.rawId());
0602                 if (lctShowerDigi.isValid()) {
0603                   std::vector<CSCShowerDigi> lctShowerDigis;
0604                   lctShowerDigis.push_back(lctShowerDigi);
0605                   lctShowerProduct->move(std::make_pair(lctShowerDigis.begin(), lctShowerDigis.end()), layer);
0606                 }
0607 
0608                 /// anode shower digis from OTMB header data
0609                 CSCShowerDigi anodeShowerDigiOTMB = cscData[iCSC].tmbHeader()->anodeShowerDigi(layer.rawId());
0610                 if (anodeShowerDigiOTMB.isValid()) {
0611                   std::vector<CSCShowerDigi> anodeShowerDigis;
0612                   anodeShowerDigis.push_back(anodeShowerDigiOTMB);
0613                   anodeShowerProductOTMB->move(std::make_pair(anodeShowerDigis.begin(), anodeShowerDigis.end()), layer);
0614                 }
0615 
0616                 /// cathode shower digis from OTMB header data
0617                 CSCShowerDigi cathodeShowerDigiOTMB = cscData[iCSC].tmbHeader()->cathodeShowerDigi(layer.rawId());
0618                 if (cathodeShowerDigiOTMB.isValid()) {
0619                   std::vector<CSCShowerDigi> cathodeShowerDigis;
0620                   cathodeShowerDigis.push_back(cathodeShowerDigiOTMB);
0621                   cathodeShowerProductOTMB->move(std::make_pair(cathodeShowerDigis.begin(), cathodeShowerDigis.end()),
0622                                                  layer);
0623                 }
0624               }
0625 
0626               /// fill CSC-RPC or CSC-GEMs digis
0627               if (cscData[iCSC].tmbData()->checkSize()) {
0628                 if (useRPCs_ && cscData[iCSC].tmbData()->hasRPC()) {
0629                   std::vector<CSCRPCDigi> rpcDigis = cscData[iCSC].tmbData()->rpcData()->digis();
0630                   rpcProduct->move(std::make_pair(rpcDigis.begin(), rpcDigis.end()), layer);
0631                 }
0632 
0633                 /// fill CSC-GEM GEMPadCluster digis
0634                 if (useGEMs_ && cscData[iCSC].tmbData()->hasGEM()) {
0635                   for (int unsigned igem = 0; igem < (int unsigned)(cscData[iCSC].tmbData()->gemData()->numGEMs());
0636                        ++igem) {
0637                     int gem_chamber = layer.chamber();
0638                     int gem_region = (layer.endcap() == 1) ? 1 : -1;
0639                     // Loop over GEM layer eta/rolls
0640                     for (unsigned ieta = 0; ieta < 8; ieta++) {
0641                       // GE11 eta/roll collection addressing according to GEMDetID definition is 1-8 (eta 8 being closest to beampipe)
0642                       GEMDetId gemid(gem_region, layer.ring(), layer.station(), igem + 1, gem_chamber, ieta + 1);
0643                       // GE11 trigger data format reports eta/rolls in 0-7 range (eta 0 being closest to beampipe)
0644                       // mapping agreement is that real data eta needs to be reversed from 0-7 to 8-1 for GEMDetId collection convention
0645                       std::vector<GEMPadDigiCluster> gemDigis = cscData[iCSC].tmbData()->gemData()->etaDigis(
0646                           igem, 7 - ieta, cscData[iCSC].tmbHeader()->ALCTMatchTime());
0647                       if (!gemDigis.empty()) {
0648                         gemProduct->move(std::make_pair(gemDigis.begin(), gemDigis.end()), gemid);
0649                       }
0650                     }
0651                   }
0652                 }
0653               } else
0654                 LogTrace("CSCDCCUnpacker|CSCRawToDigi") << " TMBData check size failed!";
0655             }
0656 
0657             /// fill cfeb status digi
0658             if (unpackStatusDigis) {
0659               for (icfeb = 0; icfeb < CSCConstants::MAX_CFEBS_RUN2; ++icfeb)  ///loop over status digis
0660               {
0661                 if (cscData[iCSC].cfebData(icfeb) != nullptr)
0662                   cfebStatusProduct->insertDigi(layer, cscData[iCSC].cfebData(icfeb)->statusDigi());
0663               }
0664               /// fill dmb status digi
0665               dmbStatusProduct->insertDigi(
0666                   layer, CSCDMBStatusDigi(cscData[iCSC].dmbHeader()->data(), cscData[iCSC].dmbTrailer()->data()));
0667               if (goodTMB)
0668                 tmbStatusProduct->insertDigi(
0669                     layer,
0670                     CSCTMBStatusDigi(cscData[iCSC].tmbHeader()->data(), cscData[iCSC].tmbData()->tmbTrailer()->data()));
0671               if (goodALCT)
0672                 alctStatusProduct->insertDigi(
0673                     layer, CSCALCTStatusDigi(cscData[iCSC].alctHeader()->data(), cscData[iCSC].alctTrailer()->data()));
0674             }
0675 
0676             /// fill wire, strip and comparator digis...
0677             for (int ilayer = CSCDetId::minLayerId(); ilayer <= CSCDetId::maxLayerId(); ++ilayer) {
0678               /// set layer, dmb and vme are valid because already checked in line 240
0679               // (You have to be kidding. Line 240 in whose universe?)
0680 
0681               // Allocate all ME1/1 wire digis to ring 1
0682               layer = pcrate->detId(vmecrate, dmb, 0, ilayer);
0683               {
0684                 std::vector<CSCWireDigi> wireDigis = cscData[iCSC].wireDigis(ilayer);
0685                 wireProduct->move(std::make_pair(wireDigis.begin(), wireDigis.end()), layer);
0686               }
0687 
0688               for (icfeb = 0; icfeb < CSCConstants::MAX_CFEBS_RUN2; ++icfeb) {
0689                 layer = pcrate->detId(vmecrate, dmb, icfeb, ilayer);
0690                 if (cscData[iCSC].cfebData(icfeb) && cscData[iCSC].cfebData(icfeb)->check()) {
0691                   std::vector<CSCStripDigi> stripDigis;
0692                   cscData[iCSC].cfebData(icfeb)->digis(layer.rawId(), stripDigis);
0693                   stripProduct->move(std::make_pair(stripDigis.begin(), stripDigis.end()), layer);
0694                 }
0695               }
0696 
0697               if (goodTMB && (cscData[iCSC].tmbHeader() != nullptr)) {
0698                 int nCFEBs = cscData[iCSC].tmbHeader()->NCFEBs();
0699                 for (icfeb = 0; icfeb < nCFEBs; ++icfeb) {
0700                   layer = pcrate->detId(vmecrate, dmb, icfeb, ilayer);
0701                   std::vector<CSCComparatorDigi> comparatorDigis =
0702                       cscData[iCSC].comparatorData()->comparatorDigis(layer.rawId(), icfeb);
0703                   // Set cfeb=0, so that ME1/a and ME1/b comparators go to
0704                   // ring 1.
0705                   layer = pcrate->detId(vmecrate, dmb, 0, ilayer);
0706                   comparatorProduct->move(std::make_pair(comparatorDigis.begin(), comparatorDigis.end()), layer);
0707                 }
0708               }  // end of loop over cfebs
0709             }    // end of loop over layers
0710           }      // end of loop over chambers
0711         }        // endof loop over DDUs
0712       }          // end of good event
0713       else {
0714         LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "ERROR! Examiner rejected FED #" << id;
0715         if (examiner) {
0716           for (int i = 0; i < examiner->nERRORS; ++i) {
0717             if (((examinerMask & examiner->errors()) >> i) & 0x1)
0718               LogTrace("CSCDCCUnpacker|CSCRawToDigi") << examiner->errName(i);
0719           }
0720           if (debug) {
0721             LogTrace("CSCDCCUnpacker|CSCRawToDigi")
0722                 << " Examiner errors:0x" << std::hex << examiner->errors() << " & 0x" << examinerMask << " = "
0723                 << (examiner->errors() & examinerMask);
0724           }
0725         }
0726 
0727         // dccStatusProduct->insertDigi(CSCDetId(1,1,1,1,1), CSCDCCStatusDigi(examiner->errors()));
0728         // if(instantiateDQM)  monitor->process(examiner, NULL);
0729       }
0730       if (examiner != nullptr)
0731         delete examiner;
0732     }  // end of if fed has data
0733   }    // end of loop over DCCs
0734   // put into the event
0735   e.put(std::move(wireProduct), "MuonCSCWireDigi");
0736   e.put(std::move(stripProduct), "MuonCSCStripDigi");
0737   e.put(std::move(alctProduct), "MuonCSCALCTDigi");
0738   e.put(std::move(clctProduct), "MuonCSCCLCTDigi");
0739   e.put(std::move(comparatorProduct), "MuonCSCComparatorDigi");
0740   e.put(std::move(corrlctProduct), "MuonCSCCorrelatedLCTDigi");
0741 
0742   if (useFormatStatus)
0743     e.put(std::move(formatStatusProduct), "MuonCSCDCCFormatStatusDigi");
0744 
0745   if (unpackStatusDigis) {
0746     e.put(std::move(cfebStatusProduct), "MuonCSCCFEBStatusDigi");
0747     e.put(std::move(dmbStatusProduct), "MuonCSCDMBStatusDigi");
0748     e.put(std::move(tmbStatusProduct), "MuonCSCTMBStatusDigi");
0749     e.put(std::move(dduStatusProduct), "MuonCSCDDUStatusDigi");
0750     e.put(std::move(dccStatusProduct), "MuonCSCDCCStatusDigi");
0751     e.put(std::move(alctStatusProduct), "MuonCSCALCTStatusDigi");
0752   }
0753 
0754   if (useRPCs_) {
0755     e.put(std::move(rpcProduct), "MuonCSCRPCDigi");
0756   }
0757   if (useGEMs_) {
0758     e.put(std::move(gemProduct), "MuonGEMPadDigiCluster");
0759   }
0760   if (useCSCShowers_) {
0761     e.put(std::move(lctShowerProduct), "MuonCSCShowerDigi");
0762     e.put(std::move(anodeShowerProductOTMB), "MuonCSCShowerDigiAnode");
0763     e.put(std::move(cathodeShowerProductOTMB), "MuonCSCShowerDigiCathode");
0764     e.put(std::move(anodeShowerProductALCT), "MuonCSCShowerDigiAnodeALCT");
0765   }
0766   if (printEventNumber)
0767     LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "[CSCDCCUnpacker]: " << numOfEvents << " events processed ";
0768 }
0769 
0770 /// Visualization of raw data
0771 
0772 void CSCDCCUnpacker::visual_raw(
0773     int hl, int id, int run, int event, bool fedshort, bool fDump, short unsigned int* buf) const {
0774   std::cout << std::endl << std::endl << std::endl;
0775   std::cout << "Run: " << run << " Event: " << event << std::endl;
0776   std::cout << std::endl << std::endl;
0777   if (formatedEventDump)
0778     std::cout << "FED-" << id << "  "
0779               << "(scroll down to see summary)" << std::endl;
0780   else
0781     std::cout << "Problem seems in FED-" << id << "  "
0782               << "(scroll down to see summary)" << std::endl;
0783   std::cout << "********************************************************************************" << std::endl;
0784   std::cout << hl << " words of data:" << std::endl;
0785 
0786   //================================================
0787   // FED codes in DCC
0788   std::vector<int> dcc_id;
0789   int dcc_h1_id = 0;
0790   // Current codes
0791   for (int i = 750; i < 758; i++)
0792     dcc_id.push_back(i);
0793   // Codes for upgrade
0794   for (int i = 830; i < 838; i++)
0795     dcc_id.push_back(i);
0796 
0797   char dcc_common[] = "DCC-";
0798 
0799   //================================================
0800   // DDU codes per FED
0801   std::vector<int> ddu_id;
0802   int ddu_h1_12_13 = 0;
0803   for (int i = 1; i < 37; i++)
0804     ddu_id.push_back(i);
0805   // For DDU Headers and tarailers
0806   char ddu_common[] = "DDU-";
0807   char ddu_header1[] = "Header 1";
0808   char ddu_header2[] = "Header 2";
0809   char ddu_header3[] = "Header 3";
0810   char ddu_trail1[] = "Trailer 1", ddu_trail2[] = "Trailer 2", ddu_trail3[] = "Trailer 3";
0811   // For Header 2
0812   char ddu_trailer1_bit[] = {'8', '0', '0', '0', 'f', 'f', 'f', 'f', '8', '0', '0', '0', '8', '0', '0', '0'};
0813   char ddu_trailer3_bit[] = {'a'};
0814   // Corrupted Trailers
0815   char ddu_tr1_err_common[] = "Incomplet";
0816   //====================================================
0817 
0818   //DMB
0819   char dmb_common[] = "DMB", dmb_header1[] = "Header 1", dmb_header2[] = "Header 2";
0820   char dmb_common_crate[] = "crate:", dmb_common_slot[] = "slot:";
0821   char dmb_common_l1a[] = "L1A:";
0822   char dmb_header1_bit[] = {'9', '9', '9', '9'};
0823   char dmb_header2_bit[] = {'a', 'a', 'a', 'a'};
0824   char dmb_tr1[] = "Trailer 1", dmb_tr2[] = "Trailer 2";
0825   char dmb_tr1_bit[] = {'f', 'f', 'f', 'f'}, dmb_tr2_bit[] = {'e', 'e', 'e', 'e'};
0826 
0827   //=====================================================
0828 
0829   // ALCT
0830   char alct_common[] = "ALCT", alct_header1[] = "Header 1", alct_header2[] = "Header 2";
0831   char alct_common_bxn[] = "BXN:";
0832   char alct_common_wcnt2[] = "| Actual word count:";
0833   char alct_common_wcnt1[] = "Expected word count:";
0834   char alct_header1_bit[] = {'d', 'd', 'd', 'd', 'b', '0', 'a'};
0835   char alct_header2_bit[] = {'0', '0', '0', '0'};
0836   char alct_tr1[] = "Trailer 1";
0837 
0838   //======================================================
0839 
0840   //TMB
0841   char tmb_common[] = "TMB", tmb_header1[] = "Header", tmb_tr1[] = "Trailer";
0842   char tmb_header1_bit[] = {'d', 'd', 'd', 'd', 'b', '0', 'c'};
0843   char tmb_tr1_bit[] = {'d', 'd', 'd', 'd', 'e', '0', 'f'};
0844 
0845   //======================================================
0846 
0847   //CFEB
0848   char cfeb_common[] = "CFEB", cfeb_tr1[] = "Trailer", cfeb_b[] = "B-word";
0849   char cfeb_common_sample[] = "sample:";
0850 
0851   //======================================================
0852 
0853   //Auxiliary variables
0854 
0855   // Bufers
0856   int word_lines = hl / 4;
0857   char tempbuf[80];
0858   char tempbuf1[130];
0859   char tempbuf_short[17];
0860   char sign1[] = "  --->| ";
0861 
0862   // Counters
0863   int word_numbering = 0;
0864   int ddu_inst_i = 0, ddu_inst_n = 0, ddu_inst_l1a = 0;
0865   int ddu_inst_bxn = 0;
0866   int dmb_inst_crate = 0, dmb_inst_slot = 0, dmb_inst_l1a = 0;
0867   int cfeb_sample = 0;
0868   int alct_inst_l1a = 0;
0869   int alct_inst_bxn = 0;
0870   int alct_inst_wcnt1 = 0;
0871   int alct_inst_wcnt2 = 0;
0872   int alct_start = 0;
0873   int alct_stop = 0;
0874   int tmb_inst_l1a = 0;
0875   int tmb_inst_wcnt1 = 0;
0876   int tmb_inst_wcnt2 = 0;
0877   int tmb_start = 0;
0878   int tmb_stop = 0;
0879   int dcc_h1_check = 0;
0880 
0881   //Flags
0882   int w = 0;
0883 
0884   //Logic variables
0885   const int sz1 = 5;
0886   bool dcc_check = false;
0887   bool ddu_h2_check[sz1] = {false};
0888   bool ddu_h1_check = false;
0889   bool dmb_h1_check[sz1] = {false};
0890   bool dmb_h2_check[sz1] = {false};
0891   bool ddu_h2_h1 = false;
0892   bool ddu_tr1_check[sz1] = {false};
0893   bool alct_h1_check[sz1] = {false};
0894   bool alct_h2_check[sz1] = {false};
0895   bool alct_tr1_check[sz1] = {false};
0896   bool dmb_tr1_check[sz1] = {false};
0897   bool dmb_tr2_check[sz1] = {false};
0898   bool tmb_h1_check[sz1] = {false};
0899   bool tmb_tr1_check[sz1] = {false};
0900   bool cfeb_tr1_check[sz1] = {false};
0901   bool cfeb_b_check[sz1] = {false};
0902   bool ddu_tr1_bad_check[sz1] = {false};
0903   bool extraction = fedshort;
0904 
0905   //Summary vectors
0906   //DDU
0907   std::vector<int> ddu_h1_coll;
0908   std::vector<int> ddu_h1_n_coll;
0909   std::vector<int> ddu_h2_coll;
0910   std::vector<int> ddu_h3_coll;
0911   std::vector<int> ddu_t1_coll;
0912   std::vector<int> ddu_t2_coll;
0913   std::vector<int> ddu_t3_coll;
0914   std::vector<int> ddu_l1a_coll;
0915   std::vector<int> ddu_bxn_coll;
0916   //DMB
0917   std::vector<int> dmb_h1_coll;
0918   std::vector<int> dmb_h2_coll;
0919   std::vector<int> dmb_t1_coll;
0920   std::vector<int> dmb_t2_coll;
0921   std::vector<int> dmb_crate_coll;
0922   std::vector<int> dmb_slot_coll;
0923   std::vector<int> dmb_l1a_coll;
0924   //ALCT
0925   std::vector<int> alct_h1_coll;
0926   std::vector<int> alct_h2_coll;
0927   std::vector<int> alct_t1_coll;
0928   std::vector<int> alct_l1a_coll;
0929   std::vector<int> alct_bxn_coll;
0930   std::vector<int> alct_wcnt1_coll;
0931   std::vector<int> alct_wcnt2_coll;
0932   std::vector<int> alct_wcnt2_id_coll;
0933   //TMB
0934   std::vector<int> tmb_h1_coll;
0935   std::vector<int> tmb_t1_coll;
0936   std::vector<int> tmb_l1a_coll;
0937   std::vector<int> tmb_wcnt1_coll;
0938   std::vector<int> tmb_wcnt2_coll;
0939   //CFEB
0940   std::vector<int> cfeb_t1_coll;
0941 
0942   //========================================================
0943 
0944   // DCC Header and Ttrailer information
0945   char dcc_header1[] = "DCC Header 1";
0946   char dcc_header2[] = "DCC Header 2";
0947   char dcc_trail1[] = "DCC Trailer 1", dcc_trail1_bit[] = {'e'};
0948   char dcc_trail2[] = "DCC Trailer 2", dcc_trail2_bit[] = {'a'};
0949   //=========================================================
0950 
0951   for (int i = 0; i < hl; i++) {
0952     ++word_numbering;
0953     for (int j = -1; j < 4; j++) {
0954       sprintf(tempbuf_short,
0955               "%04x%04x%04x%04x",
0956               buf[i + 4 * (j - 1) + 3],
0957               buf[i + 4 * (j - 1) + 2],
0958               buf[i + 4 * (j - 1) + 1],
0959               buf[i + 4 * (j - 1)]);
0960 
0961       // WARNING in 5_0_X for time being
0962       ddu_h2_check[j] = ((buf[i + 4 * (j - 1) + 1] == 0x8000) && (buf[i + 4 * (j - 1) + 2] == 0x0001) &&
0963                          (buf[i + 4 * (j - 1) + 3] == 0x8000));
0964 
0965       ddu_tr1_check[j] = ((tempbuf_short[0] == ddu_trailer1_bit[0]) && (tempbuf_short[1] == ddu_trailer1_bit[1]) &&
0966                           (tempbuf_short[2] == ddu_trailer1_bit[2]) && (tempbuf_short[3] == ddu_trailer1_bit[3]) &&
0967                           (tempbuf_short[4] == ddu_trailer1_bit[4]) && (tempbuf_short[5] == ddu_trailer1_bit[5]) &&
0968                           (tempbuf_short[6] == ddu_trailer1_bit[6]) && (tempbuf_short[7] == ddu_trailer1_bit[7]) &&
0969                           (tempbuf_short[8] == ddu_trailer1_bit[8]) && (tempbuf_short[9] == ddu_trailer1_bit[9]) &&
0970                           (tempbuf_short[10] == ddu_trailer1_bit[10]) && (tempbuf_short[11] == ddu_trailer1_bit[11]) &&
0971                           (tempbuf_short[12] == ddu_trailer1_bit[12]) && (tempbuf_short[13] == ddu_trailer1_bit[13]) &&
0972                           (tempbuf_short[14] == ddu_trailer1_bit[14]) && (tempbuf_short[15] == ddu_trailer1_bit[15]));
0973 
0974       dmb_h1_check[j] = ((tempbuf_short[0] == dmb_header1_bit[0]) && (tempbuf_short[4] == dmb_header1_bit[1]) &&
0975                          (tempbuf_short[8] == dmb_header1_bit[2]) && (tempbuf_short[12] == dmb_header1_bit[3]));
0976 
0977       dmb_h2_check[j] = ((tempbuf_short[0] == dmb_header2_bit[0]) && (tempbuf_short[4] == dmb_header2_bit[1]) &&
0978                          (tempbuf_short[8] == dmb_header2_bit[2]) && (tempbuf_short[12] == dmb_header2_bit[3]));
0979       alct_h1_check[j] = ((tempbuf_short[0] == alct_header1_bit[0]) && (tempbuf_short[4] == alct_header1_bit[1]) &&
0980                           (tempbuf_short[8] == alct_header1_bit[2]) && (tempbuf_short[12] == alct_header1_bit[3]) &&
0981                           (tempbuf_short[13] == alct_header1_bit[4]) && (tempbuf_short[14] == alct_header1_bit[5]) &&
0982                           (tempbuf_short[15] == alct_header1_bit[6]));
0983       alct_h2_check[j] = (((tempbuf_short[0] == alct_header2_bit[0]) && (tempbuf_short[1] == alct_header2_bit[1]) &&
0984                            (tempbuf_short[2] == alct_header2_bit[2]) && (tempbuf_short[3] == alct_header2_bit[3])) ||
0985                           ((tempbuf_short[4] == alct_header2_bit[0]) && (tempbuf_short[5] == alct_header2_bit[1]) &&
0986                            (tempbuf_short[6] == alct_header2_bit[2]) && (tempbuf_short[7] == alct_header2_bit[3])) ||
0987                           ((tempbuf_short[8] == alct_header2_bit[0]) && (tempbuf_short[9] == alct_header2_bit[1]) &&
0988                            (tempbuf_short[10] == alct_header2_bit[2]) && (tempbuf_short[11] == alct_header2_bit[3])) ||
0989                           ((tempbuf_short[12] == alct_header2_bit[0]) && (tempbuf_short[13] == alct_header2_bit[1]) &&
0990                            (tempbuf_short[14] == alct_header2_bit[2]) && (tempbuf_short[15] == alct_header2_bit[3]))
0991                           //(tempbuf_short[4]==alct_header2_bit[4])&&(tempbuf_short[5]==alct_header2_bit[5])
0992       );
0993       // ALCT Trailers
0994       alct_tr1_check[j] =
0995           (((buf[i + 4 * (j - 1)] & 0xFFFF) == 0xDE0D) && ((buf[i + 4 * (j - 1) + 1] & 0xF800) == 0xD000) &&
0996            ((buf[i + 4 * (j - 1) + 2] & 0xF800) == 0xD000) && ((buf[i + 4 * (j - 1) + 3] & 0xF000) == 0xD000));
0997       // DMB Trailers
0998       dmb_tr1_check[j] = ((tempbuf_short[0] == dmb_tr1_bit[0]) && (tempbuf_short[4] == dmb_tr1_bit[1]) &&
0999                           (tempbuf_short[8] == dmb_tr1_bit[2]) && (tempbuf_short[12] == dmb_tr1_bit[3]));
1000       dmb_tr2_check[j] = ((tempbuf_short[0] == dmb_tr2_bit[0]) && (tempbuf_short[4] == dmb_tr2_bit[1]) &&
1001                           (tempbuf_short[8] == dmb_tr2_bit[2]) && (tempbuf_short[12] == dmb_tr2_bit[3]));
1002       // TMB
1003       tmb_h1_check[j] = ((tempbuf_short[0] == tmb_header1_bit[0]) && (tempbuf_short[4] == tmb_header1_bit[1]) &&
1004                          (tempbuf_short[8] == tmb_header1_bit[2]) && (tempbuf_short[12] == tmb_header1_bit[3]) &&
1005                          (tempbuf_short[13] == tmb_header1_bit[4]) && (tempbuf_short[14] == tmb_header1_bit[5]) &&
1006                          (tempbuf_short[15] == tmb_header1_bit[6]));
1007       tmb_tr1_check[j] = ((tempbuf_short[0] == tmb_tr1_bit[0]) && (tempbuf_short[4] == tmb_tr1_bit[1]) &&
1008                           (tempbuf_short[8] == tmb_tr1_bit[2]) && (tempbuf_short[12] == tmb_tr1_bit[3]) &&
1009                           (tempbuf_short[13] == tmb_tr1_bit[4]) && (tempbuf_short[14] == tmb_tr1_bit[5]) &&
1010                           (tempbuf_short[15] == tmb_tr1_bit[6]));
1011       // CFEB
1012       cfeb_tr1_check[j] =
1013           (((buf[i + 4 * (j - 1) + 1] & 0xF000) == 0x7000) && ((buf[i + 4 * (j - 1) + 2] & 0xF000) == 0x7000) &&
1014            ((buf[i + 4 * (j - 1) + 1] != 0x7FFF) || (buf[i + 4 * (j - 1) + 2] != 0x7FFF)) &&
1015            ((buf[i + 4 * (j - 1) + 3] == 0x7FFF) || ((buf[i + 4 * (j - 1) + 3] & buf[i + 4 * (j - 1)]) == 0x0 &&
1016                                                      (buf[i + 4 * (j - 1) + 3] + buf[i + 4 * (j - 1)] == 0x7FFF))));
1017       cfeb_b_check[j] =
1018           (((buf[i + 4 * (j - 1) + 3] & 0xF000) == 0xB000) && ((buf[i + 4 * (j - 1) + 2] & 0xF000) == 0xB000) &&
1019            ((buf[i + 4 * (j - 1) + 1] & 0xF000) == 0xB000) && ((buf[i + 4 * (j - 1)] = 3 & 0xF000) == 0xB000));
1020       // DDU Trailers with errors
1021       ddu_tr1_bad_check[j] =
1022           ((tempbuf_short[0] != ddu_trailer1_bit[0]) &&
1023            //(tempbuf_short[1]!=ddu_trailer1_bit[1])&&(tempbuf_short[2]!=ddu_trailer1_bit[2])&&
1024            //(tempbuf_short[3]==ddu_trailer1_bit[3])&&
1025            (tempbuf_short[4] != ddu_trailer1_bit[4]) &&
1026            //(tempbuf_short[5]==ddu_trailer1_bit[5])&&
1027            //(tempbuf_short[6]==ddu_trailer1_bit[6])&&(tempbuf_short[7]==ddu_trailer1_bit[7])&&
1028            (tempbuf_short[8] == ddu_trailer1_bit[8]) && (tempbuf_short[9] == ddu_trailer1_bit[9]) &&
1029            (tempbuf_short[10] == ddu_trailer1_bit[10]) && (tempbuf_short[11] == ddu_trailer1_bit[11]) &&
1030            (tempbuf_short[12] == ddu_trailer1_bit[12]) && (tempbuf_short[13] == ddu_trailer1_bit[13]) &&
1031            (tempbuf_short[14] == ddu_trailer1_bit[14]) && (tempbuf_short[15] == ddu_trailer1_bit[15]));
1032     }
1033 
1034     // DDU Header 2 next to Header 1
1035     ddu_h2_h1 = ddu_h2_check[2];
1036 
1037     sprintf(tempbuf_short, "%04x%04x%04x%04x", buf[i + 3], buf[i + 2], buf[i + 1], buf[i]);
1038 
1039     // Looking for DDU Header 1
1040     ddu_h1_12_13 = (buf[i] >> 8);
1041     for (int kk = 0; kk < 36; kk++) {
1042       if (((buf[i + 3] & 0xF000) == 0x5000) && (ddu_h1_12_13 == ddu_id[kk]) && ddu_h2_h1) {
1043         ddu_h1_coll.push_back(word_numbering);
1044         ddu_h1_n_coll.push_back(ddu_id[kk]);
1045         ddu_inst_l1a = ((buf[i + 2] & 0xFFFF) + ((buf[i + 3] & 0x00FF) << 16));
1046         ddu_l1a_coll.push_back(ddu_inst_l1a);
1047         ddu_inst_bxn = (buf[i + 1] & 0xFFF0) >> 4;
1048         ddu_bxn_coll.push_back(ddu_inst_bxn);
1049         sprintf(tempbuf1,
1050                 "%6i    %04x %04x %04x %04x%s%s%i %s%s %s %i %s %i",
1051                 word_numbering,
1052                 buf[i + 3],
1053                 buf[i + 2],
1054                 buf[i + 1],
1055                 buf[i],
1056                 sign1,
1057                 ddu_common,
1058                 ddu_id[kk],
1059                 ddu_header1,
1060                 sign1,
1061                 dmb_common_l1a,
1062                 ddu_inst_l1a,
1063                 alct_common_bxn,
1064                 ddu_inst_bxn);
1065         std::cout << tempbuf1 << std::endl;
1066         w = 0;
1067         ddu_h1_check = true;
1068         cfeb_sample = 0;
1069       }
1070     }
1071 
1072     // Looking for DCC Header 1
1073     dcc_h1_id = (((buf[i + 1] << 12) & 0xF000) >> 4) + (buf[i] >> 8);
1074     for (int dcci = 0; dcci < 16; dcci++) {
1075       if ((dcc_id[dcci] == dcc_h1_id) && (((buf[i + 3] & 0xF000) == 0x5000) && (!ddu_h1_check))) {
1076         sprintf(tempbuf1,
1077                 "%6i    %04x %04x %04x %04x%s%s%i %s",
1078                 word_numbering,
1079                 buf[i + 3],
1080                 buf[i + 2],
1081                 buf[i + 1],
1082                 buf[i],
1083                 sign1,
1084                 dcc_common,
1085                 dcc_h1_id,
1086                 dcc_header1);
1087         dcc_h1_check = word_numbering;
1088         w = 0;
1089         dcc_check = true;
1090         std::cout << tempbuf1 << std::endl;
1091       }
1092     }
1093 
1094     // Looking for DCC Header 2 and trailers
1095     if (((word_numbering - 1) == dcc_h1_check) && ((buf[i + 3] & 0xFF00) == 0xD900)) {
1096       sprintf(tempbuf1,
1097               "%6i    %04x %04x %04x %04x%s%s",
1098               word_numbering,
1099               buf[i + 3],
1100               buf[i + 2],
1101               buf[i + 1],
1102               buf[i],
1103               sign1,
1104               dcc_header2);
1105       std::cout << tempbuf1 << std::endl;
1106       w = 0;
1107     } else if ((word_numbering == word_lines - 1) && (tempbuf_short[0] == dcc_trail1_bit[0])) {
1108       sprintf(tempbuf1,
1109               "%6i    %04x %04x %04x %04x%s%s",
1110               word_numbering,
1111               buf[i + 3],
1112               buf[i + 2],
1113               buf[i + 1],
1114               buf[i],
1115               sign1,
1116               dcc_trail1);
1117       std::cout << tempbuf1 << std::endl;
1118       w = 0;
1119     } else if ((word_numbering == word_lines) && (tempbuf_short[0] == dcc_trail2_bit[0])) {
1120       sprintf(tempbuf1,
1121               "%6i    %04x %04x %04x %04x%s%s",
1122               word_numbering,
1123               buf[i + 3],
1124               buf[i + 2],
1125               buf[i + 1],
1126               buf[i],
1127               sign1,
1128               dcc_trail2);
1129       std::cout << tempbuf1 << std::endl;
1130       w = 0;
1131     }
1132 
1133     // DDU Header 2
1134     else if (ddu_h2_check[1]) {
1135       ddu_inst_i = ddu_h1_n_coll.size();  //ddu_inst_n=ddu_h1_n_coll[0];
1136       if (ddu_inst_i > 0) {
1137         ddu_inst_n = ddu_h1_n_coll[ddu_inst_i - 1];
1138       }
1139       sprintf(tempbuf1,
1140               "%6i    %04x %04x %04x %04x%s%s%i %s",
1141               word_numbering,
1142               buf[i + 3],
1143               buf[i + 2],
1144               buf[i + 1],
1145               buf[i],
1146               sign1,
1147               ddu_common,
1148               ddu_inst_n,
1149               ddu_header2);
1150       ddu_h2_coll.push_back(word_numbering);
1151       std::cout << tempbuf1 << std::endl;
1152       w = 0;
1153     }
1154 
1155     // DDU Header 3 (either between DDU Header 2 DMB Header or DDU Header 2 DDU Trailer1)
1156     else if ((ddu_h2_check[0] && dmb_h1_check[2]) || (ddu_h2_check[0] && ddu_tr1_check[2])) {
1157       ddu_inst_i = ddu_h1_n_coll.size();
1158       if (ddu_inst_i > 0) {
1159         ddu_inst_n = ddu_h1_n_coll[ddu_inst_i - 1];
1160       }
1161       sprintf(tempbuf1,
1162               "%6i    %04x %04x %04x %04x%s%s%i %s",
1163               word_numbering,
1164               buf[i + 3],
1165               buf[i + 2],
1166               buf[i + 1],
1167               buf[i],
1168               sign1,
1169               ddu_common,
1170               ddu_inst_n,
1171               ddu_header3);
1172       ddu_h3_coll.push_back(word_numbering);
1173       std::cout << tempbuf1 << std::endl;
1174       w = 0;
1175     }
1176 
1177     // DMB Header 1,2
1178 
1179     else if (dmb_h1_check[1]) {
1180       dmb_inst_crate = 0;
1181       dmb_inst_slot = 0;
1182       dmb_inst_l1a = ((buf[i] & 0x0FFF) + ((buf[i + 1] & 0xFFF) << 12));
1183       dmb_l1a_coll.push_back(dmb_inst_l1a);
1184       if (dmb_h2_check[2]) {
1185         dmb_inst_crate = ((buf[i + 4 + 1] >> 4) & 0xFF);
1186         dmb_inst_slot = (buf[i + 4 + 1] & 0xF);
1187         dmb_crate_coll.push_back(dmb_inst_crate);
1188         dmb_slot_coll.push_back(dmb_inst_slot);
1189       }
1190       sprintf(tempbuf1,
1191               "%6i    %04x %04x %04x %04x%s%s %s%s%s %i %s %i %s %i",
1192               word_numbering,
1193               buf[i + 3],
1194               buf[i + 2],
1195               buf[i + 1],
1196               buf[i],
1197               sign1,
1198               dmb_common,
1199               dmb_header1,
1200               sign1,
1201               dmb_common_crate,
1202               dmb_inst_crate,
1203               dmb_common_slot,
1204               dmb_inst_slot,
1205               dmb_common_l1a,
1206               dmb_inst_l1a);
1207       dmb_h1_coll.push_back(word_numbering);
1208       std::cout << tempbuf1 << std::endl;
1209       w = 0;
1210     }
1211 
1212     else if (dmb_h2_check[1]) {
1213       dmb_inst_crate = ((buf[i + 1] >> 4) & 0xFF);
1214       dmb_inst_slot = (buf[i + 1] & 0xF);
1215       dmb_h2_coll.push_back(word_numbering);
1216       if (dmb_h1_check[0])
1217         dmb_inst_l1a = ((buf[i - 4] & 0x0FFF) + ((buf[i - 4 + 1] & 0xFFF) << 12));
1218       sprintf(tempbuf1,
1219               "%6i    %04x %04x %04x %04x%s%s %s%s%s %i %s %i %s %i",
1220               word_numbering,
1221               buf[i + 3],
1222               buf[i + 2],
1223               buf[i + 1],
1224               buf[i],
1225               sign1,
1226               dmb_common,
1227               dmb_header2,
1228               sign1,
1229               dmb_common_crate,
1230               dmb_inst_crate,
1231               dmb_common_slot,
1232               dmb_inst_slot,
1233               dmb_common_l1a,
1234               dmb_inst_l1a);
1235       std::cout << tempbuf1 << std::endl;
1236       w = 0;
1237     }
1238 
1239     //DDU Trailer 1
1240 
1241     else if (ddu_tr1_check[1]) {
1242       ddu_inst_i = ddu_h1_n_coll.size();
1243       if (ddu_inst_i > 0) {
1244         ddu_inst_n = ddu_h1_n_coll[ddu_inst_i - 1];
1245       }
1246       //ddu_inst_n=ddu_h1_n_coll[ddu_inst_i-1];
1247       sprintf(tempbuf1,
1248               "%6i    %04x %04x %04x %04x%s%s%i %s",
1249               word_numbering,
1250               buf[i + 3],
1251               buf[i + 2],
1252               buf[i + 1],
1253               buf[i],
1254               sign1,
1255               ddu_common,
1256               ddu_inst_n,
1257               ddu_trail1);
1258       ddu_t1_coll.push_back(word_numbering);
1259       std::cout << tempbuf1 << std::endl;
1260       w = 0;
1261     }
1262 
1263     ///ALCT Header 1,2
1264     else if (alct_h1_check[1]) {
1265       alct_start = word_numbering;
1266       alct_inst_l1a = (buf[i + 2] & 0x0FFF);
1267       alct_l1a_coll.push_back(alct_inst_l1a);
1268       sprintf(tempbuf1,
1269               "%6i    %04x %04x %04x %04x%s%s %s%s %s %i",
1270               word_numbering,
1271               buf[i + 3],
1272               buf[i + 2],
1273               buf[i + 1],
1274               buf[i],
1275               sign1,
1276               alct_common,
1277               alct_header1,
1278               sign1,
1279               dmb_common_l1a,
1280               alct_inst_l1a);
1281       alct_h1_coll.push_back(word_numbering);
1282       std::cout << tempbuf1 << std::endl;
1283       w = 0;
1284     }
1285 
1286     else if ((alct_h1_check[0]) && (alct_h2_check[2])) {
1287       alct_inst_bxn = (buf[i] & 0x0FFF);
1288       alct_bxn_coll.push_back(alct_inst_bxn);
1289       sprintf(tempbuf1,
1290               "%6i    %04x %04x %04x %04x%s%s %s%s%s %i",
1291               word_numbering,
1292               buf[i + 3],
1293               buf[i + 2],
1294               buf[i + 1],
1295               buf[i],
1296               sign1,
1297               alct_common,
1298               alct_header2,
1299               sign1,
1300               alct_common_bxn,
1301               alct_inst_bxn);
1302       alct_h2_coll.push_back(word_numbering);
1303       std::cout << tempbuf1 << std::endl;
1304       w = 0;
1305     }
1306 
1307     //ALCT Trailer 1
1308     else if (alct_tr1_check[1]) {
1309       alct_stop = word_numbering;
1310       if ((alct_start != 0) && (alct_stop != 0) && (alct_stop > alct_start)) {
1311         alct_inst_wcnt2 = 4 * (alct_stop - alct_start + 1);
1312         alct_wcnt2_coll.push_back(alct_inst_wcnt2);
1313         alct_wcnt2_id_coll.push_back(alct_start);
1314       }
1315       alct_inst_wcnt1 = (buf[i + 3] & 0x7FF);
1316       alct_wcnt1_coll.push_back(alct_inst_wcnt1);
1317       sprintf(tempbuf1,
1318               "%6i    %04x %04x %04x %04x%s%s %s%s%s %i %s %i",
1319               word_numbering,
1320               buf[i + 3],
1321               buf[i + 2],
1322               buf[i + 1],
1323               buf[i],
1324               sign1,
1325               alct_common,
1326               alct_tr1,
1327               sign1,
1328               alct_common_wcnt1,
1329               alct_inst_wcnt1,
1330               alct_common_wcnt2,
1331               alct_inst_wcnt2);
1332       alct_t1_coll.push_back(word_numbering);
1333       std::cout << tempbuf1 << std::endl;
1334       w = 0;
1335       alct_inst_wcnt2 = 0;
1336     }
1337 
1338     //DDU Trailer 3
1339 
1340     //      else if ((ddu_tr1_check[-1])&&(tempbuf_short[0]==ddu_trailer3_bit[0])) { // !!! TO FIX: negative index
1341     else if ((ddu_h2_h1) && (tempbuf_short[0] == ddu_trailer3_bit[0])) {
1342       //&&(tempbuf_short[0]==ddu_trailer3_bit[0])){
1343       ddu_inst_i = ddu_h1_n_coll.size();
1344       if (ddu_inst_i > 0) {
1345         ddu_inst_n = ddu_h1_n_coll[ddu_inst_i - 1];
1346       }
1347       //ddu_inst_n=ddu_h1_n_coll[ddu_inst_i-1];
1348       sprintf(tempbuf1,
1349               "%6i    %04x %04x %04x %04x%s%s%i %s",
1350               word_numbering,
1351               buf[i + 3],
1352               buf[i + 2],
1353               buf[i + 1],
1354               buf[i],
1355               sign1,
1356               ddu_common,
1357               ddu_inst_n,
1358               ddu_trail3);
1359       ddu_t3_coll.push_back(word_numbering);
1360       std::cout << tempbuf1 << std::endl;
1361       w = 0;
1362     }
1363     //DDU Trailer 2
1364     else if ((ddu_tr1_check[0]) && (tempbuf_short[0] != ddu_trailer3_bit[0])) {
1365       //&&(tempbuf_short[0]==ddu_trailer3_bit[0])){
1366       ddu_inst_i = ddu_h1_n_coll.size();
1367       if (ddu_inst_i > 0) {
1368         ddu_inst_n = ddu_h1_n_coll[ddu_inst_i - 1];
1369       }
1370       //ddu_inst_n=ddu_h1_n_coll[ddu_inst_i-1];
1371       sprintf(tempbuf1,
1372               "%6i    %04x %04x %04x %04x%s%s%i %s",
1373               word_numbering,
1374               buf[i + 3],
1375               buf[i + 2],
1376               buf[i + 1],
1377               buf[i],
1378               sign1,
1379               ddu_common,
1380               ddu_inst_n,
1381               ddu_trail2);
1382       ddu_t2_coll.push_back(word_numbering);
1383       std::cout << tempbuf1 << std::endl;
1384       w = 0;
1385     }
1386 
1387     //DMB Trailer 1,2
1388     else if (dmb_tr1_check[1]) {
1389       sprintf(tempbuf1,
1390               "%6i    %04x %04x %04x %04x%s%s %s",
1391               word_numbering,
1392               buf[i + 3],
1393               buf[i + 2],
1394               buf[i + 1],
1395               buf[i],
1396               sign1,
1397               dmb_common,
1398               dmb_tr1);
1399       dmb_t1_coll.push_back(word_numbering);
1400       std::cout << tempbuf1 << std::endl;
1401       w = 0;
1402       cfeb_sample = 0;
1403     }
1404 
1405     else if (dmb_tr2_check[1]) {
1406       sprintf(tempbuf1,
1407               "%6i    %04x %04x %04x %04x%s%s %s",
1408               word_numbering,
1409               buf[i + 3],
1410               buf[i + 2],
1411               buf[i + 1],
1412               buf[i],
1413               sign1,
1414               dmb_common,
1415               dmb_tr2);
1416       dmb_t2_coll.push_back(word_numbering);
1417       std::cout << tempbuf1 << std::endl;
1418       w = 0;
1419     }
1420     // TMB
1421     else if (tmb_h1_check[1]) {
1422       tmb_start = word_numbering;
1423       tmb_inst_l1a = (buf[i + 2] & 0x000F);
1424       tmb_l1a_coll.push_back(tmb_inst_l1a);
1425       sprintf(tempbuf1,
1426               "%6i    %04x %04x %04x %04x%s%s %s%s%s %i",
1427               word_numbering,
1428               buf[i + 3],
1429               buf[i + 2],
1430               buf[i + 1],
1431               buf[i],
1432               sign1,
1433               tmb_common,
1434               tmb_header1,
1435               sign1,
1436               dmb_common_l1a,
1437               tmb_inst_l1a);
1438       tmb_h1_coll.push_back(word_numbering);
1439       std::cout << tempbuf1 << std::endl;
1440       w = 0;
1441     } else if (tmb_tr1_check[1]) {
1442       tmb_stop = word_numbering;
1443       if ((tmb_start != 0) && (tmb_stop != 0) && (tmb_stop > tmb_start)) {
1444         tmb_inst_wcnt2 = 4 * (tmb_stop - tmb_start + 1);
1445         tmb_wcnt2_coll.push_back(tmb_inst_wcnt2);
1446       }
1447       tmb_inst_wcnt1 = (buf[i + 3] & 0x7FF);
1448       tmb_wcnt1_coll.push_back(tmb_inst_wcnt1);
1449       sprintf(tempbuf1,
1450               "%6i    %04x %04x %04x %04x%s%s %s%s%s %i %s %i",
1451               word_numbering,
1452               buf[i + 3],
1453               buf[i + 2],
1454               buf[i + 1],
1455               buf[i],
1456               sign1,
1457               tmb_common,
1458               tmb_tr1,
1459               sign1,
1460               alct_common_wcnt1,
1461               tmb_inst_wcnt1,
1462               alct_common_wcnt2,
1463               tmb_inst_wcnt2);
1464       tmb_t1_coll.push_back(word_numbering);
1465       std::cout << tempbuf1 << std::endl;
1466       w = 0;
1467       tmb_inst_wcnt2 = 0;
1468     }
1469     // CFEB
1470     else if (cfeb_tr1_check[1]) {
1471       ++cfeb_sample;
1472       sprintf(tempbuf1,
1473               "%6i    %04x %04x %04x %04x%s%s %s%s %s %i",
1474               word_numbering,
1475               buf[i + 3],
1476               buf[i + 2],
1477               buf[i + 1],
1478               buf[i],
1479               sign1,
1480               cfeb_common,
1481               cfeb_tr1,
1482               sign1,
1483               cfeb_common_sample,
1484               cfeb_sample);
1485       cfeb_t1_coll.push_back(word_numbering);
1486       std::cout << tempbuf1 << std::endl;
1487       w = 0;
1488     } else if (cfeb_b_check[1]) {
1489       sprintf(tempbuf1,
1490               "%6i    %04x %04x %04x %04x%s%s %s",
1491               word_numbering,
1492               buf[i + 3],
1493               buf[i + 2],
1494               buf[i + 1],
1495               buf[i],
1496               sign1,
1497               cfeb_common,
1498               cfeb_b);
1499       std::cout << tempbuf1 << std::endl;
1500       w = 0;
1501     }
1502 
1503     //ERRORS ddu_tr1_bad_check
1504 
1505     else if (ddu_tr1_bad_check[1]) {
1506       ddu_inst_i = ddu_h1_n_coll.size();
1507       ddu_inst_n = ddu_h1_n_coll[ddu_inst_i - 1];
1508       sprintf(tempbuf1,
1509               "%6i    %04x %04x %04x %04x%s%s%i %s %s",
1510               word_numbering,
1511               buf[i + 3],
1512               buf[i + 2],
1513               buf[i + 1],
1514               buf[i],
1515               sign1,
1516               ddu_common,
1517               ddu_inst_n,
1518               ddu_trail1,
1519               ddu_tr1_err_common);
1520       std::cout << tempbuf1 << std::endl;
1521       w = 0;
1522     }
1523 
1524     else if (extraction && (!ddu_h1_check) && (!dcc_check)) {
1525       if (w < 3) {
1526         sprintf(tempbuf, "%6i    %04x %04x %04x %04x", word_numbering, buf[i + 3], buf[i + 2], buf[i + 1], buf[i]);
1527         std::cout << tempbuf << std::endl;
1528         w++;
1529       }
1530       if (w == 3) {
1531         std::cout << "..................................................." << std::endl;
1532         w++;
1533       }
1534     }
1535 
1536     else if ((!ddu_h1_check) && (!dcc_check)) {
1537       sprintf(tempbuf, "%6i    %04x %04x %04x %04x", word_numbering, buf[i + 3], buf[i + 2], buf[i + 1], buf[i]);
1538       std::cout << tempbuf << std::endl;
1539     }
1540 
1541     i += 3;
1542     ddu_h1_check = false;
1543     dcc_check = false;
1544   }
1545   //char sign[30]; //WARNING 5_0_X
1546   std::cout << "********************************************************************************" << std::endl
1547             << std::endl;
1548   if (fedshort)
1549     std::cout << "For complete output turn off VisualFEDShort in muonCSCDigis configuration file." << std::endl;
1550   std::cout << "********************************************************************************" << std::endl
1551             << std::endl;
1552   std::cout << std::endl << std::endl;
1553   std::cout << "            Summary                " << std::endl;
1554   std::cout << std::endl << std::endl;
1555   std::cout << ddu_h1_coll.size() << "  " << ddu_common << "  " << ddu_header1 << "  "
1556             << "found" << std::endl;
1557   /*
1558   std::cout << ddu_h1_coll.size() << " " << ddu_h1_n_coll.size() << " " << ddu_l1a_coll.size() <<
1559   " " << ddu_bxn_coll.size() << std::endl;
1560   */
1561   for (unsigned int k = 0; k < ddu_h1_coll.size(); ++k) {
1562     /*
1563       sprintf(sign,"%s%6i%5s %s%i %s %i %s %i","Line: ",
1564       ddu_h1_coll[k],sign1,ddu_common,ddu_h1_n_coll[k],dmb_common_l1a,ddu_l1a_coll[k],
1565       alct_common_bxn,ddu_bxn_coll[k]);
1566       */
1567     std::cout << "Line: "
1568               << "    " << ddu_h1_coll[k] << " " << sign1 << " " << ddu_common << " " << ddu_h1_n_coll[k] << " "
1569               << dmb_common_l1a << " " << ddu_l1a_coll[k] << " " << alct_common_bxn << " " << ddu_bxn_coll[k]
1570               << std::endl;
1571   }
1572 
1573   std::cout << std::endl << std::endl;
1574   std::cout << "||||||||||||||||||||" << std::endl;
1575   std::cout << std::endl << std::endl;
1576   std::cout << ddu_h2_coll.size() << "  " << ddu_common << "  " << ddu_header2 << "  "
1577             << "found" << std::endl;
1578   for (unsigned int k = 0; k < ddu_h2_coll.size(); ++k)
1579     std::cout << "Line:  " << ddu_h2_coll[k] << std::endl;
1580   std::cout << std::endl << std::endl;
1581   std::cout << "||||||||||||||||||||" << std::endl;
1582   std::cout << std::endl << std::endl;
1583   std::cout << ddu_h3_coll.size() << "  " << ddu_common << "  " << ddu_header3 << "  "
1584             << "found" << std::endl;
1585   for (unsigned int k = 0; k < ddu_h3_coll.size(); ++k)
1586     std::cout << "Line:  " << ddu_h3_coll[k] << std::endl;
1587   std::cout << std::endl << std::endl;
1588   std::cout << "||||||||||||||||||||" << std::endl;
1589   std::cout << std::endl << std::endl;
1590   std::cout << ddu_t1_coll.size() << "  " << ddu_common << "  " << ddu_trail1 << "  "
1591             << "found" << std::endl;
1592   for (unsigned int k = 0; k < ddu_t1_coll.size(); ++k)
1593     std::cout << "Line:  " << ddu_t1_coll[k] << std::endl;
1594   std::cout << std::endl << std::endl;
1595   std::cout << "||||||||||||||||||||" << std::endl;
1596   std::cout << std::endl << std::endl;
1597   std::cout << ddu_t2_coll.size() << "  " << ddu_common << "  " << ddu_trail2 << "  "
1598             << "found" << std::endl;
1599   for (unsigned int k = 0; k < ddu_t2_coll.size(); ++k)
1600     std::cout << "Line:  " << ddu_t2_coll[k] << std::endl;
1601   std::cout << std::endl << std::endl;
1602   std::cout << "||||||||||||||||||||" << std::endl;
1603   std::cout << std::endl << std::endl;
1604   std::cout << ddu_t3_coll.size() << "  " << ddu_common << "  " << ddu_trail3 << "  "
1605             << "found" << std::endl;
1606   for (unsigned int k = 0; k < ddu_t3_coll.size(); ++k)
1607     std::cout << "Line:  " << ddu_t3_coll[k] << std::endl;
1608   std::cout << std::endl << std::endl;
1609   std::cout << "||||||||||||||||||||" << std::endl;
1610   std::cout << std::endl << std::endl;
1611   std::cout << dmb_h1_coll.size() << "  " << dmb_common << "  " << dmb_header1 << "  "
1612             << "found" << std::endl;
1613 
1614   for (unsigned int k = 0; k < dmb_h1_coll.size(); ++k) {
1615     /*
1616       sprintf(sign,"%s%6i%5s %s %s %i %s %i %s %i","Line: ",
1617       dmb_h1_coll[k],sign1,dmb_common,dmb_common_crate,dmb_crate_coll[k],dmb_common_slot,
1618       dmb_slot_coll[k],dmb_common_l1a,dmb_l1a_coll[k]);
1619       */
1620     std::cout << "Line: "
1621               << "    " << dmb_h1_coll[k] << " " << sign1 << dmb_common << " " << dmb_common_crate << " "
1622               << dmb_crate_coll[k] << " " << dmb_common_slot << " " << dmb_slot_coll[k] << " " << dmb_common_l1a << " "
1623               << dmb_l1a_coll[k] << std::endl;
1624   }
1625   std::cout << std::endl << std::endl;
1626   std::cout << "||||||||||||||||||||" << std::endl;
1627   std::cout << std::endl << std::endl;
1628   std::cout << dmb_h2_coll.size() << "  " << dmb_common << "  " << dmb_header2 << "  "
1629             << "found" << std::endl;
1630   for (unsigned int k = 0; k < dmb_h2_coll.size(); ++k)
1631     std::cout << "Line:  " << dmb_h2_coll[k] << std::endl;
1632   std::cout << std::endl << std::endl;
1633   std::cout << "||||||||||||||||||||" << std::endl;
1634   std::cout << std::endl << std::endl;
1635   std::cout << dmb_t1_coll.size() << "  " << dmb_common << "  " << dmb_tr1 << "  "
1636             << "found" << std::endl;
1637   for (unsigned int k = 0; k < dmb_t1_coll.size(); ++k)
1638     std::cout << "Line:  " << dmb_t1_coll[k] << std::endl;
1639   std::cout << std::endl << std::endl;
1640   std::cout << "||||||||||||||||||||" << std::endl;
1641   std::cout << std::endl << std::endl;
1642   std::cout << dmb_t2_coll.size() << "  " << dmb_common << "  " << dmb_tr2 << "  "
1643             << "found" << std::endl;
1644   for (unsigned int k = 0; k < dmb_t2_coll.size(); ++k)
1645     std::cout << "Line:  " << dmb_t2_coll[k] << std::endl;
1646   std::cout << std::endl << std::endl;
1647   std::cout << "||||||||||||||||||||" << std::endl;
1648   std::cout << std::endl << std::endl;
1649   std::cout << alct_h1_coll.size() << "  " << alct_common << "  " << alct_header1 << "  "
1650             << "found" << std::endl;
1651   for (unsigned int k = 0; k < alct_h1_coll.size(); ++k) {
1652     /*
1653       sprintf(sign,"%s%6i%5s %s %s %i","Line: ",
1654       alct_h1_coll[k],sign1,alct_common,
1655       dmb_common_l1a,alct_l1a_coll[k]);
1656       std::cout << sign << std::endl;
1657       */
1658     std::cout << "Line: "
1659               << "    " << alct_h1_coll[k] << " " << sign1 << " " << alct_common << " " << dmb_common_l1a << " "
1660               << alct_l1a_coll[k] << std::endl;
1661   }
1662 
1663   std::cout << std::endl << std::endl;
1664   std::cout << "||||||||||||||||||||" << std::endl;
1665   std::cout << std::endl << std::endl;
1666   std::cout << alct_h2_coll.size() << "  " << alct_common << "  " << alct_header2 << "  "
1667             << "found" << std::endl;
1668   for (unsigned int k = 0; k < alct_h2_coll.size(); ++k) {
1669     /*
1670       sprintf(sign,"%s%6i%5s %s %s %i","Line: ",
1671       alct_h1_coll[k],sign1,alct_common,
1672       alct_common_bxn,alct_bxn_coll[k]);
1673       std::cout << sign << std::endl;
1674       */
1675     std::cout << "Line: "
1676               << "    " << alct_h1_coll[k] << " " << sign1 << " " << alct_common << " " << alct_common_bxn << " "
1677               << alct_bxn_coll[k] << std::endl;
1678   }
1679 
1680   std::cout << std::endl << std::endl;
1681   std::cout << "||||||||||||||||||||" << std::endl;
1682   std::cout << std::endl << std::endl;
1683   std::cout << alct_t1_coll.size() << "  " << alct_common << "  " << alct_tr1 << "  "
1684             << "found" << std::endl;
1685   for (unsigned int k = 0; k < alct_t1_coll.size(); ++k) {
1686     /*
1687          sprintf(sign,"%s%6i%5s %s %s %i %s %i","Line: ",
1688          alct_t1_coll[k],sign1,alct_common,
1689          alct_common_wcnt1,alct_wcnt1_coll[k],alct_common_wcnt2,alct_wcnt2_coll[k]);
1690          std::cout << sign << std::endl;
1691        */
1692     std::cout << "Line: "
1693               << "    " << alct_t1_coll[k] << " " << sign1 << " " << alct_common << " " << alct_common_wcnt1 << " "
1694               << alct_wcnt1_coll[k] << " " << alct_common_wcnt2 << " ";
1695     if (!alct_wcnt2_coll.empty()) {
1696       std::cout << alct_wcnt2_coll[k] << std::endl;
1697     } else {
1698       std::cout << "Undefined (ALCT Header is not found) " << std::endl;
1699     }
1700   }
1701 
1702   std::cout << std::endl << std::endl;
1703   std::cout << "||||||||||||||||||||" << std::endl;
1704   std::cout << std::endl << std::endl;
1705   std::cout << tmb_h1_coll.size() << "  " << tmb_common << "  " << tmb_header1 << "  "
1706             << "found" << std::endl;
1707   for (unsigned int k = 0; k < tmb_h1_coll.size(); ++k) {
1708     /*
1709       sprintf(sign,"%s%6i%5s %s %s %i","Line: ",
1710       tmb_h1_coll[k],sign1,tmb_common,
1711       dmb_common_l1a,tmb_l1a_coll[k]);
1712       std::cout << sign << std::endl;
1713       */
1714     std::cout << "Line: "
1715               << "    " << tmb_h1_coll[k] << " " << sign1 << " " << tmb_common << " " << dmb_common_l1a << " "
1716               << tmb_l1a_coll[k] << std::endl;
1717   }
1718 
1719   std::cout << std::endl << std::endl;
1720   std::cout << "||||||||||||||||||||" << std::endl;
1721   std::cout << std::endl << std::endl;
1722   std::cout << tmb_t1_coll.size() << "  " << tmb_common << "  " << tmb_tr1 << "  "
1723             << "found" << std::endl;
1724   for (unsigned int k = 0; k < tmb_t1_coll.size(); ++k) {
1725     /*
1726       sprintf(sign,"%s%6i%5s %s %s %i %s %i","Line: ",
1727       tmb_t1_coll[k],sign1,tmb_common,
1728       alct_common_wcnt1,tmb_wcnt1_coll[k],alct_common_wcnt2,tmb_wcnt2_coll[k]);
1729       std::cout << sign << std::endl;
1730       */
1731     std::cout << "Line: "
1732               << "    " << tmb_t1_coll[k] << " " << sign1 << " " << tmb_common << " " << alct_common_wcnt1 << " "
1733               << tmb_wcnt1_coll[k] << " " << alct_common_wcnt2 << " " << tmb_wcnt2_coll[k] << std::endl;
1734   }
1735 
1736   std::cout << std::endl << std::endl;
1737   std::cout << "||||||||||||||||||||" << std::endl;
1738   std::cout << std::endl << std::endl;
1739   std::cout << cfeb_t1_coll.size() << "  " << cfeb_common << "  " << cfeb_tr1 << "  "
1740             << "found" << std::endl;
1741   for (unsigned int k = 0; k < cfeb_t1_coll.size(); ++k)
1742     std::cout << "Line:  " << cfeb_t1_coll[k] << std::endl;
1743   std::cout << "********************************************************************************" << std::endl;
1744 }
1745 
1746 #include "FWCore/Framework/interface/MakerMacros.h"
1747 DEFINE_FWK_MODULE(CSCDCCUnpacker);