Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-07 05:50:19

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