Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:00

0001 /** \class SiPixelRawDumper_H
0002  *  Plug-in module that dump raw data file 
0003  *  for pixel subdetector
0004  *  Added class to interpret the data d.k. 30/10/08
0005  *  Add histograms. Add pix 0 detection.
0006  * Adopt for SLC6, CMSSW620, 11.10.13, dk
0007  * Works for CMSSW7X (bytoken)d.k.
0008  */
0009 
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 
0014 #include "DataFormats/Common/interface/Handle.h"
0015 
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0018 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0019 
0020 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0021 
0022 #include "EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h"
0023 
0024 // for detids
0025 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0026 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
0027 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
0028 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0029 #include "DataFormats/DetId/interface/DetId.h"
0030 
0031 // For L1  NOT IN RAW
0032 //#include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtils.h"
0033 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
0034 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
0035 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0036 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h"
0037 
0038 // To use root histos
0039 #include "FWCore/ServiceRegistry/interface/Service.h"
0040 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0041 
0042 // For ROOT
0043 #include <TROOT.h>
0044 //#include <TChain.h>
0045 #include <TFile.h>
0046 #include <TF1.h>
0047 #include <TH2F.h>
0048 #include <TH1F.h>
0049 
0050 #include <iostream>
0051 using namespace std;
0052 
0053 // Include the helper decoding class
0054 /////////////////////////////////////////////////////////////////////////////
0055 class MyDecode {
0056 public:
0057   MyDecode() {}
0058   ~MyDecode() {}
0059   static int error(int error, int &fedChannel, int fed, bool print = false);
0060   static int data(int error, int &fedChannel, int fed, bool print = false);
0061   static int header(unsigned long long word64, int fed, bool print);
0062   static int trailer(unsigned long long word64, int fed, bool print);
0063 
0064 private:
0065 };
0066 /////////////////////////////////////////////////////////////////////////////
0067 int MyDecode::header(unsigned long long word64, int fed, bool print) {
0068   int fed_id = (word64 >> 8) & 0xfff;
0069   int event_id = (word64 >> 32) & 0xffffff;
0070   unsigned int bx_id = (word64 >> 20) & 0xfff;
0071   //   if(bx_id!=101) {
0072   //     cout<<" Header "<<" for FED "
0073   //    <<fed_id<<" event "<<event_id<<" bx "<<bx_id<<endl;
0074   //     int dummy=0;
0075   //     cout<<" : ";
0076   //     cin>>dummy;
0077   //   }
0078   if (print)
0079     cout << " Header "
0080          << " for FED " << fed_id << " event " << event_id << " bx " << bx_id << endl;
0081 
0082   return event_id;
0083 }
0084 //
0085 int MyDecode::trailer(unsigned long long word64, int fed, bool print) {
0086   int slinkLength = int((word64 >> 32) & 0xffffff);
0087   int crc = int((word64 & 0xffff0000) >> 16);
0088   int tts = int((word64 & 0xf0) >> 4);
0089   int slinkError = int((word64 & 0xf00) >> 8);
0090   if (print)
0091     cout << " Trailer "
0092          << " len " << slinkLength << " tts " << tts << " error " << slinkError << " crc " << hex << crc << dec << endl;
0093   return slinkLength;
0094 }
0095 //
0096 // Decode error FIFO
0097 // Works for both, the error FIFO and the SLink error words. d.k. 25/04/07
0098 int MyDecode::error(int word, int &fedChannel, int fed, bool print) {
0099   int status = -1;
0100 
0101   const unsigned int errorMask = 0x3e00000;
0102   const unsigned int dummyMask = 0x03600000;
0103   const unsigned int gapMask = 0x03400000;
0104   const unsigned int timeOut = 0x3a00000;
0105   const unsigned int eventNumError = 0x3e00000;
0106   const unsigned int trailError = 0x3c00000;
0107   const unsigned int fifoError = 0x3800000;
0108 
0109   //  const unsigned int  timeOutChannelMask = 0x1f;  // channel mask for timeouts
0110   //const unsigned int  eventNumMask = 0x1fe000; // event number mask
0111   const unsigned int channelMask = 0xfc000000;  // channel num mask
0112   const unsigned int tbmEventMask = 0xff;       // tbm event num mask
0113   const unsigned int overflowMask = 0x100;      // data overflow
0114   const unsigned int tbmStatusMask = 0xff;      //TBM trailer info
0115   const unsigned int BlkNumMask = 0x700;        //pointer to error fifo #
0116   const unsigned int FsmErrMask = 0x600;        //pointer to FSM errors
0117   const unsigned int RocErrMask = 0x800;        //pointer to #Roc errors
0118   const unsigned int ChnFifMask = 0x1f;         //channel mask for fifo error
0119   const unsigned int Fif2NFMask = 0x40;         //mask for fifo2 NF
0120   const unsigned int TrigNFMask = 0x80;         //mask for trigger fifo NF
0121 
0122   const int offsets[8] = {0, 4, 9, 13, 18, 22, 27, 31};
0123   unsigned int channel = 0;
0124 
0125   //cout<<"error word "<<hex<<word<<dec<<endl;
0126 
0127   if ((word & errorMask) == dummyMask) {  // DUMMY WORD
0128     //cout<<" Dummy word";
0129     return 0;
0130   } else if ((word & errorMask) == gapMask) {  // GAP WORD
0131     //cout<<" Gap word";
0132     return 0;
0133 
0134   } else if ((word & errorMask) == timeOut) {  // TIMEOUT
0135                                                // More than 1 channel within a group can have a timeout error
0136     unsigned int index = (word & 0x1F);        // index within a group of 4/5
0137     unsigned int chip = (word & BlkNumMask) >> 8;
0138     int offset = offsets[chip];
0139     if (print)
0140       cout << "Timeout Error- channel: ";
0141     for (int i = 0; i < 5; i++) {
0142       if ((index & 0x1) != 0) {
0143         channel = offset + i + 1;
0144         if (print)
0145           cout << channel << " ";
0146       }
0147       index = index >> 1;
0148     }
0149     //if(print) cout<<" for Fed "<<fed<<endl;
0150     status = -10;
0151     fedChannel = channel;
0152     //end of timeout  chip and channel decoding
0153 
0154   } else if ((word & errorMask) == eventNumError) {  // EVENT NUMBER ERROR
0155     channel = (word & channelMask) >> 26;
0156     unsigned int tbm_event = (word & tbmEventMask);
0157 
0158     if (print)
0159       cout << "Event Number Error- channel: " << channel << " tbm event nr. " << tbm_event << " ";
0160     status = -11;
0161     fedChannel = channel;
0162 
0163   } else if (((word & errorMask) == trailError)) {  // TRAILER
0164     channel = (word & channelMask) >> 26;
0165     unsigned int tbm_status = (word & tbmStatusMask);
0166 
0167     if (tbm_status != 0) {
0168       if (print)
0169         cout << "Trailer Error- "
0170              << "channel: " << channel << " TBM status:0x" << hex << tbm_status << dec << " ";  // <<endl;
0171       status = -15;
0172       // implement the resync/reset 17
0173     }
0174 
0175     if (word & RocErrMask) {
0176       if (print)
0177         cout << "Number of Rocs Error- "
0178              << "channel: " << channel << " ";  // <<endl;
0179       status = -12;
0180     }
0181 
0182     if (word & overflowMask) {
0183       if (print)
0184         cout << "Overflow Error- "
0185              << "channel: " << channel << " ";  // <<endl;
0186       status = -14;
0187     }
0188 
0189     if (word & FsmErrMask) {
0190       if (print)
0191         cout << "Finite State Machine Error- "
0192              << "channel: " << channel << " Error status:0x" << hex << ((word & FsmErrMask) >> 9) << dec
0193              << " ";  // <<endl;
0194       status = -13;
0195     }
0196 
0197     fedChannel = channel;
0198 
0199   } else if ((word & errorMask) == fifoError) {  // FIFO
0200     if (print) {
0201       if (word & Fif2NFMask)
0202         cout << "A fifo 2 is Nearly full- ";
0203       if (word & TrigNFMask)
0204         cout << "The trigger fifo is nearly Full - ";
0205       if (word & ChnFifMask)
0206         cout << "fifo-1 is nearly full for channel" << (word & ChnFifMask);
0207       //cout<<endl;
0208       status = -16;
0209     }
0210 
0211   } else {
0212     cout << " Unknown error?, error word " << hex << word << dec << endl;
0213     status = -19;
0214   }
0215 
0216   if (print && status < -1)
0217     cout << " For FED " << fed << endl;
0218   return status;
0219 }
0220 ///////////////////////////////////////////////////////////////////////////
0221 int MyDecode::data(int word, int &fedChannel, int fed, bool print) {
0222   const bool CHECK_PIXELS = true;
0223   //const int ROCMAX = 24;
0224   const unsigned int plsmsk = 0xff;    // pulse height
0225   const unsigned int pxlmsk = 0xff00;  // pixel index
0226   const unsigned int dclmsk = 0x1f0000;
0227   const unsigned int rocmsk = 0x3e00000;
0228   const unsigned int chnlmsk = 0xfc000000;
0229   int status = 0;
0230 
0231   int roc = ((word & rocmsk) >> 21);
0232   // Check for embeded special words
0233   if (roc > 0 && roc < 25) {  // valid ROCs go from 1-24
0234     //if(print) cout<<"data "<<hex<<word<<dec;
0235     unsigned int channel = ((word & chnlmsk) >> 26);
0236     if (channel > 0 && channel < 37) {  // valid channels 1-36
0237       //cout<<hex<<word<<dec;
0238       int dcol = (word & dclmsk) >> 16;
0239       int pix = (word & pxlmsk) >> 8;
0240       int adc = (word & plsmsk);
0241       fedChannel = channel;
0242       // print the roc number according to the online 0-15 scheme
0243       if (print) {
0244         int dcol1 = dcol / 6;
0245         int dcol2 = dcol % 6;
0246         int pix1 = pix / 36;
0247         int pix2 = (pix % 36) / 6;
0248         int pix3 = pix % 6;
0249         cout << " Fed " << fed << " Channel- " << channel << " ROC- " << (roc - 1) << " DCOL- " << dcol << " Pixel- "
0250              << pix << " ADC- " << adc << " : " << dcol1 << dcol2 << "-" << pix1 << pix2 << pix3 << endl;
0251       }
0252       status++;
0253       if (CHECK_PIXELS) {
0254         if (dcol < 0 || dcol > 25) {
0255           if (print)
0256             cout << " Fed " << fed << " wrong dcol number chan/roc/dcol/pix/adc = " << channel << "/" << roc << "/"
0257                  << dcol << "/" << pix << "/" << adc << endl;
0258           status = -3;
0259         }
0260 
0261         if (pix < 2 || pix > 181) {
0262           if (print)
0263             cout << " Fed " << fed << " wrong pix number chan/roc/dcol/pix/adc = " << channel << "/" << roc << "/"
0264                  << dcol << "/" << pix << "/" << adc << endl;
0265           status = -3;
0266         }
0267 
0268         if ((fed > 31 && roc > 24) || (fed <= 31 && roc > 16)) {
0269           if (print)
0270             cout << " Fed " << fed << " wrong roc number chan/roc/dcol/pix/adc = " << channel << "/" << roc << "/"
0271                  << dcol << "/" << pix << "/" << adc << endl;
0272           status = -4;
0273         } else if (fed <= 31 && channel <= 24 && roc > 8) {
0274           // ptorotect for rerouted signals
0275           if (!((fed == 13 && channel == 17) || (fed == 15 && channel == 5) || (fed == 31 && channel == 10) ||
0276                 (fed == 27 && channel == 15))) {
0277             if (print)
0278               cout << " Fed " << fed << " wrong roc number, chan/roc/dcol/pix/adc = " << channel << "/" << roc << "/"
0279                    << dcol << "/" << pix << "/" << adc << endl;
0280             status = -4;
0281           }
0282         }
0283 
0284         if (pix == 0) {
0285           if (print)
0286             cout << " Fed " << fed << " pix=0 chan/roc/dcol/pix/adc = " << channel << "/" << roc << "/" << dcol << "/"
0287                  << pix << "/" << adc << endl;
0288           status = -5;
0289         }
0290       }
0291 
0292     } else {
0293       cout << "Wrong channel " << channel << endl;
0294       return -2;
0295     }
0296 
0297   } else if (roc == 25) {  //
0298 
0299     unsigned int channel = ((word & chnlmsk) >> 26);
0300     cout << "Wrong roc 25-" << roc << " in fed/chan " << fed << "/" << channel << endl;
0301     status = -4;
0302 
0303   } else {  // error word
0304 
0305     //cout<<"error word "<<hex<<word<<dec;
0306     status = error(word, fedChannel, fed, print);
0307 
0308   }  // end if
0309 
0310   return status;
0311 }
0312 
0313 ////////////////////////////////////////////////////////////////////////////
0314 
0315 class FedErrorDumper : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0316 public:
0317   /// ctor
0318   explicit FedErrorDumper(const edm::ParameterSet &cfg);
0319 
0320   /// dtor
0321   virtual ~FedErrorDumper() = default;
0322 
0323   void beginJob();
0324 
0325   // end of job
0326   void endJob();
0327 
0328   /// get data, convert to digis attach againe to Event
0329   virtual void analyze(const edm::Event &, const edm::EventSetup &);
0330 
0331 private:
0332   edm::ParameterSet theConfig;
0333   edm::EDGetTokenT<edm::DetSetVector<SiPixelRawDataError> > fedErrorContainer;
0334   bool PRINT;
0335   //int countEvents, countAllEvents;
0336   int fedErrors, moduleErrors, spareCounts;
0337   //float sumPixels, sumFedSize, sumFedPixels[40];
0338   //int fedErrors[40][36];
0339   //int decodeErrors[40][36];
0340   //int decodeErrors000[40][36];  // pix 0 problem
0341   int countErrors[40], countErrors2[40];
0342 
0343   TH1F *hfeds, *hfedsF, *hfedsSlink, *hfedsCRC, *hfedsUnknown;
0344   TH1F *herrors, *herrorsF, *htype;
0345   TH1F *hmode, *hmodeF;
0346   TH1F *htbm, *htbmF;
0347   TH2F *hfedErrors0, *hfedErrors1, *hfedErrors2, *hfedErrors3, *hfedErrors4, *hfedErrors5, *hfedErrors6, *hfedErrors7,
0348       *hfedErrors8, *hfedErrors9;
0349   TH2F *hfedErrors0F, *hfed2d, *hfed2d0;
0350 
0351   TH1F *hlumi, *hbx;
0352 };
0353 //----------------------------------
0354 FedErrorDumper::FedErrorDumper(const edm::ParameterSet &cfg) : theConfig(cfg) {
0355   //std::string src_ = theConfig.getUntrackedParameter<std::string>("InputLabel","source");
0356   std::string src = theConfig.getUntrackedParameter<std::string>("InputLabel", "siPixelDigis");
0357 
0358   // For the ByToken method
0359   fedErrorContainer = consumes<edm::DetSetVector<SiPixelRawDataError> >(src);
0360   usesResource(TFileService::kSharedResource);
0361 }
0362 
0363 //---------------------------------
0364 void FedErrorDumper::endJob() {
0365   cout << " fed-errors " << fedErrors << " module-Errors " << moduleErrors << " " << spareCounts << endl;
0366   for (int i = 0; i < 40; ++i) {
0367     if (countErrors[i] > 0 || countErrors2[i] > 0)
0368       cout << i << " " << countErrors[i] << " " << countErrors2[i] << endl;
0369   }
0370 
0371   //sumFedPixels[i] /= float(countEvents);
0372   //       hpixels4->Fill(float(i),sumFedPixels[i]); //pixels only
0373   //     }
0374   //   }
0375 
0376   //   if(countEvents>0) {
0377   //     sumPixels /= float(countEvents);
0378   //     sumFedSize /= float(countAllEvents);
0379 
0380   //   cout<<" Total/non-empty events " <<countAllEvents<<" / "<<countEvents<<" average number of pixels "<<sumPixels<<endl;
0381 
0382   //   cout<<" Average Fed size for all events "<<sumFedSize<<endl;
0383   //   for(int i=0;i<40;++i) cout<<sumFedPixels[i]<<" ";
0384   //   cout<<endl;
0385 
0386   //   cout<<" Total number of errors "<<countErrors<<endl;
0387   //   cout<<" FED erros "<<endl<<"  Fed Channel Errors"<<endl;
0388   //   for(int i=0;i<40;++i) {
0389   //     for(int j=0;j<36;++j) if(fedErrors[i][j]>0) {
0390   //       cout<<i<<" "<<j<<" "<<fedErrors[i][j]<<endl;
0391   //     }
0392   //   }
0393   //   cout<<" Decode errors "<<endl<<"  Fed Channel Errors Pix_000"<<endl;
0394   //   for(int i=0;i<40;++i) {
0395   //     for(int j=0;j<36;++j) if(decodeErrors[i][j]>0) {
0396   //       cout<<i<<" "<<j<<" "<<decodeErrors[i][j]<<" "<<decodeErrors000[i][j]<<endl;
0397   //     }
0398   //   }
0399 
0400   //   cout<<" Total errors for all feds "<<endl<<" Type Errors"<<endl;
0401   //   for(int i=0;i<20;++i) {
0402   //     if( errorType[i]>0 ) cout<<"   "<<i<<" "<<errorType[i]<<endl;
0403   //   }
0404 }
0405 
0406 void FedErrorDumper::beginJob() {
0407   //countEvents=0;
0408   //countAllEvents=0;
0409   //countErrors=0;
0410   fedErrors = 0;
0411   moduleErrors = 0;
0412   spareCounts = 0.;
0413   //sumFedSize=0;
0414 
0415   PRINT = theConfig.getUntrackedParameter<bool>("Verbosity", false);
0416   for (int i = 0; i < 40; ++i) {
0417     countErrors[i] = 0;
0418     countErrors2[i] = 0;
0419   }
0420 
0421   //   for(int i=0;i<40;++i) {
0422   //     sumFedPixels[i]=0;
0423   //     for(int j=0;j<36;++j) fedErrors[i][j]=0;
0424   //     for(int j=0;j<36;++j) decodeErrors[i][j]=0;
0425   //     for(int j=0;j<36;++j) decodeErrors000[i][j]=0;
0426   //   }
0427   //   for(int i=0;i<20;++i) errorType[i]=0;
0428 
0429   edm::Service<TFileService> fs;
0430 
0431   htbm = fs->make<TH1F>("htbm", "tbm errors ", 256, -0.5, 255.5);
0432   htbmF = fs->make<TH1F>("htbmF", "tbm errors ", 256, -0.5, 255.5);
0433 
0434   hmode = fs->make<TH1F>("hmode", "mode", 16, -0.5, 15.5);
0435   hmodeF = fs->make<TH1F>("hmodeF", "mode", 16, -0.5, 15.5);
0436 
0437   hfeds = fs->make<TH1F>("hfeds", "errors per FED", 40, -0.5, 39.5);
0438   hfedsF = fs->make<TH1F>("hfedsF", "errors per FED", 40, -0.5, 39.5);
0439   hfedsSlink = fs->make<TH1F>("hfedsSlink", "errors per FED", 40, -0.5, 39.5);
0440   hfedsCRC = fs->make<TH1F>("hfedsCRC", "errors per FED", 40, -0.5, 39.5);
0441   hfedsUnknown = fs->make<TH1F>("hfedsUnknown", "errors per FED", 40, -0.5, 39.5);
0442 
0443   htype = fs->make<TH1F>("htype", "error type ", 50, -0.5, 49.5);
0444   herrors = fs->make<TH1F>("herrors", "error type ", 50, -0.5, 49.5);
0445   herrorsF = fs->make<TH1F>("herrorsF", "error type", 50, -0.5, 49.5);
0446 
0447   hfedErrors0 = fs->make<TH2F>("hfedErrors0", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);    // ALL
0448   hfedErrors0F = fs->make<TH2F>("hfedErrors0F", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);  // ALL
0449   hfedErrors1 = fs->make<TH2F>("hfedErrors1", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);    // Timeout
0450   hfedErrors2 = fs->make<TH2F>("hfedErrors2", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);    // Overflow
0451   hfedErrors3 = fs->make<TH2F>("hfedErrors3", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);    // ENE
0452   hfedErrors4 = fs->make<TH2F>("hfedErrors4", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);    // FIFO
0453   hfedErrors5 = fs->make<TH2F>("hfedErrors5", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);    // NOR
0454   hfedErrors6 = fs->make<TH2F>("hfedErrors6", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);    // TRAILER
0455   hfedErrors7 = fs->make<TH2F>("hfedErrors7", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);    // FSM
0456   hfedErrors8 = fs->make<TH2F>("hfedErrors8", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);    // Invalid ROC
0457   hfedErrors9 = fs->make<TH2F>("hfedErrors9", "errors", 40, -0.5, 39.5, 37, -0.5, 36.5);    // Invalid DCOL-PIX
0458 
0459   hfed2d = fs->make<TH2F>("hfed2d", "errors", 40, -0.5, 39.5, 20, 19.5, 39.5);    // ALL
0460   hfed2d0 = fs->make<TH2F>("hfed2d0", "errors", 40, -0.5, 39.5, 20, 19.5, 39.5);  // ALL
0461 
0462   hlumi = fs->make<TH1F>("hlumi", "lumi", 4000, 0, 4000.);
0463   hbx = fs->make<TH1F>("hbx", "bx", 4000, 0, 4000.);
0464 }
0465 //--------------------------------------------------------------------------------
0466 void FedErrorDumper::analyze(const edm::Event &ev, const edm::EventSetup &es) {
0467   //const bool PRINT = false;
0468 
0469   // Access event information
0470   int run = ev.id().run();
0471   int event = ev.id().event();
0472   int lumiBlock = ev.luminosityBlock();
0473   int bx = ev.bunchCrossing();
0474   //int orbit     = ev.orbitNumber(); // unused
0475 
0476   hlumi->Fill(float(lumiBlock));
0477   hbx->Fill(float(bx));
0478 
0479   //   edm::Handle<FEDRawDataCollection> buffers;
0480   //   static std::string label = theConfig.getUntrackedParameter<std::string>("InputLabel","source");
0481   //   static std::string instance = theConfig.getUntrackedParameter<std::string>("InputInstance","");
0482   //   ev.getByLabel( label, instance, buffers);
0483 
0484   edm::Handle<edm::DetSetVector<SiPixelRawDataError> > input;
0485   //static std::string src_ = theConfig.getUntrackedParameter<std::string>("InputLabel","source");
0486   //static std::string src_ = theConfig.getUntrackedParameter<std::string>("InputLabel","siPixelDigis");
0487   //static std::string instance = theConfig.getUntrackedParameter<std::string>("InputInstance","");
0488   //ev.getByLabel( src_, instance, input );
0489   ev.getByToken(fedErrorContainer, input);  // the new bytoken
0490 
0491   if (!input.isValid()) {
0492     cout << " Container not found " << endl;
0493     return;
0494   }
0495 
0496   if (PRINT)
0497     cout << " Container found " << run << " " << event << " " << lumiBlock << " " << bx << endl;
0498 
0499   // Iterate on detector units
0500   edm::DetSetVector<SiPixelRawDataError>::const_iterator DSViter;
0501   for (DSViter = input->begin(); DSViter != input->end(); DSViter++) {
0502     //bool valid = false;
0503     unsigned int detid = DSViter->id;  // = rawid
0504     //cout<<hex<<detid<<dec<<endl;
0505 
0506     if (detid == 0xffffffff) {  // whole fed
0507 
0508       if (PRINT)
0509         cout << " FED errors " << DSViter->data.size() << endl;
0510       // Look at FED errors now
0511       edm::DetSet<SiPixelRawDataError>::const_iterator di;
0512 
0513       for (di = DSViter->data.begin(); di != DSViter->data.end(); di++) {
0514         int FedId = di->getFedId();     // FED the error came from
0515         int errorType = di->getType();  // type of error
0516         uint32_t word32 = di->getWord32();
0517         uint64_t word64 = di->getWord64();
0518 
0519         fedErrors++;
0520 
0521         herrors->Fill(float(errorType));
0522         herrorsF->Fill(float(errorType));
0523         hfedsF->Fill(float(FedId));
0524         hfeds->Fill(float(FedId));
0525         int errorTypeMod = errorType;
0526 
0527         if (PRINT)
0528           cout << " fed " << FedId << " type " << errorType << " " << hex << word32 << " " << word64 << dec << " "
0529                << di->getMessage() << endl;
0530 
0531         int status = 0;
0532         int fedChannel = -1;
0533         //const bool printData    = true;
0534         if (errorType >= 26 && errorType <= 31) {  // fed error
0535           status = MyDecode::error(word32, fedChannel, FedId, PRINT);
0536           if (PRINT)
0537             cout << " status " << status << endl;
0538 
0539           if (fedChannel < 1 || fedChannel > 36) {
0540             cout << " Cannot get a valid  fed channel number of a -fed- error " << fedChannel << endl;
0541             continue;  // skip this error
0542           }
0543 
0544           hfedErrors0->Fill(float(FedId), float(fedChannel));
0545           hfedErrors0F->Fill(float(FedId), float(fedChannel));
0546 
0547           switch (errorType) {
0548             case (28): {  // FIFO
0549               hfedErrors4->Fill(float(FedId), float(fedChannel));
0550               hfed2d0->Fill(float(FedId), float(errorTypeMod));
0551               htype->Fill(float(errorTypeMod));
0552               break;
0553             }
0554 
0555             case (29): {  // TIMEOUT
0556               hfedErrors1->Fill(float(FedId), float(fedChannel));
0557               hfed2d0->Fill(float(FedId), float(errorTypeMod));
0558               htype->Fill(float(errorTypeMod));
0559               break;
0560             }
0561 
0562             case (30): {  // TRAILER
0563 
0564               int tbm = (word32 & 0xff);
0565               int mode = (word32 >> 8) & 0xf;
0566               hmodeF->Fill(float(mode));
0567               hmode->Fill(float(mode));
0568               //cout<<" error 30 "<<hex<<mode<<dec<<endl;
0569               countErrors[30]++;
0570 
0571               if (tbm != 0) {  // trailer
0572                 hfedErrors6->Fill(float(FedId), float(fedChannel));
0573                 htbmF->Fill(float(tbm));
0574                 errorTypeMod = 20;
0575                 hfed2d0->Fill(float(FedId), float(errorTypeMod));
0576                 htype->Fill(float(errorTypeMod));
0577               }
0578 
0579               if ((mode & 0x8) != 0) {  // nor
0580                 //cout<<" NOR "<<endl;
0581                 hfedErrors5->Fill(float(FedId), float(fedChannel));
0582                 errorTypeMod = 21;
0583                 hfed2d0->Fill(float(FedId), float(errorTypeMod));
0584                 htype->Fill(float(errorTypeMod));
0585               }
0586 
0587               if ((mode & 0x1) != 0) {  // overflow
0588                 hfedErrors2->Fill(float(FedId), float(fedChannel));
0589                 errorTypeMod = 22;
0590                 hfed2d0->Fill(float(FedId), float(errorTypeMod));
0591                 htype->Fill(float(errorTypeMod));
0592               }
0593 
0594               if ((mode & 0x6) != 0) {  // fsm
0595                 hfedErrors7->Fill(float(FedId), float(fedChannel));
0596                 errorTypeMod = 23;
0597                 hfed2d0->Fill(float(FedId), float(errorTypeMod));
0598                 htype->Fill(float(errorTypeMod));
0599               }
0600 
0601               break;
0602             }
0603 
0604             case (31): {  // EVE
0605               hfedErrors3->Fill(float(FedId), float(fedChannel));
0606               hfed2d0->Fill(float(FedId), float(errorTypeMod));
0607               htype->Fill(float(errorTypeMod));
0608               break;
0609             }
0610           }  // end switch
0611 
0612         } else if (errorType >= 32 && errorType <= 34) {
0613           cout << " Slink error " << endl;
0614 
0615           hfedsSlink->Fill(float(FedId));
0616           hfed2d0->Fill(float(FedId), float(errorTypeMod));
0617           htype->Fill(float(errorTypeMod));
0618 
0619         } else if (errorType == 25 || (errorType >= 35 && errorType <= 38)) {  // conversion error
0620           cout << " Should never happen, a -fed- conversion error?  " << endl;
0621           status = MyDecode::data(word32, fedChannel, FedId, PRINT);
0622           if (PRINT)
0623             cout << " status " << status << endl;
0624 
0625           hfedErrors0->Fill(float(FedId), float(fedChannel));
0626           hfed2d0->Fill(float(FedId), float(errorTypeMod));
0627           htype->Fill(float(errorTypeMod));
0628 
0629           switch (errorType) {
0630             case (25): {  // inv ROC
0631               hfedErrors8->Fill(float(FedId), float(fedChannel));
0632               break;
0633             }
0634             case (36): {  // inv ROC
0635               hfedErrors8->Fill(float(FedId), float(fedChannel));
0636               break;
0637             }
0638             case (37): {  // inv DCOL&PIX
0639               hfedErrors9->Fill(float(FedId), float(fedChannel));
0640               //spareCounts++;
0641               cout << " does it ever happen " << endl;
0642               break;
0643             }
0644           }
0645 
0646         } else if (errorType == 39) {  // CRC
0647           cout << " CRC error " << endl;
0648           hfedsCRC->Fill(float(FedId));
0649           hfed2d0->Fill(float(FedId), float(errorTypeMod));
0650           htype->Fill(float(errorTypeMod));
0651 
0652         } else {
0653           cout << " unknown error " << errorType << endl;
0654           hfedsUnknown->Fill(float(FedId));
0655           errorTypeMod = 24;
0656           hfed2d0->Fill(float(FedId), float(errorTypeMod));
0657           htype->Fill(float(errorTypeMod));
0658         }
0659 
0660         hfed2d->Fill(float(FedId), float(errorTypeMod));
0661 
0662         if (errorTypeMod >= 0 && errorTypeMod < 40)
0663           countErrors[errorTypeMod]++;
0664 
0665       }  // for errors
0666 
0667     } else {  // module errors
0668 
0669       DetId detId(detid);
0670       //const GeomDetUnit      * geoUnit = geom->idToDetUnit( detId );
0671       //const PixelGeomDetUnit * pixDet  = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
0672       unsigned int detType = detId.det();     // det type, tracker=1
0673       unsigned int subid = detId.subdetId();  //subdetector type, barrel=1
0674 
0675       if (PRINT) {
0676         cout << " Module errors " << DSViter->data.size() << endl;
0677         cout << "Det: " << detId.rawId() << ":";
0678         //cout<<"Det: "<<detId.rawId()<<" "<<detId.null()<<" "<<detType<<" "<<subid<<endl;
0679       }
0680 
0681       int layer = 0, ladder = 0, module = 0, disk = 0, blade = 0, zindex = 0;
0682       if (subid == 1) {  // bpix
0683         PXBDetId pdetId = PXBDetId(detid);
0684         // Barell layer = 1,2,3
0685         int layerC = pdetId.layer();  // unused
0686         // Barrel ladder id 1-20,32,44.
0687         int ladderC = pdetId.ladder();  // unused
0688         // Barrel Z-index=1,8
0689         int zindex = pdetId.module();
0690         // Convert to online
0691         PixelBarrelName pbn(pdetId);
0692         int sector = pbn.sectorName();
0693         ladder = pbn.ladderName();
0694         layer = pbn.layerName();
0695         module = pbn.moduleName();
0696         int half = pbn.isHalfModule();
0697         PixelBarrelName::Shell shell = pbn.shell();
0698 
0699         if (PRINT)
0700           cout << " BPix: layer " << layer << " ladder " << ladder << " module " << module << " shell " << shell
0701                << " sector " << sector << " " << layerC << " " << ladderC << " " << zindex << " " << half << " "
0702                << detType << endl;
0703 
0704       } else if (subid == 2) {  // fpix
0705 
0706         PXFDetId pdetId = PXFDetId(detid);
0707         disk = pdetId.disk();        //1,2,3
0708         blade = pdetId.blade();      //1-24
0709         zindex = pdetId.module();    //
0710         int side = pdetId.side();    //size=1 for -z, 2 for +z
0711         int panel = pdetId.panel();  //panel=1
0712 
0713         if (PRINT)
0714           cout << " FPix: disk " << disk << " " << blade << " " << side << " " << panel << endl;
0715       }
0716 
0717       // Look at FED errors now
0718       edm::DetSet<SiPixelRawDataError>::const_iterator di;
0719       for (di = DSViter->data.begin(); di != DSViter->data.end(); di++) {
0720         int FedId = di->getFedId();     // FED the error came from
0721         int errorType = di->getType();  // type of error
0722         uint32_t word32 = di->getWord32();
0723         //uint64_t word64 = di->getWord64();  // unused
0724 
0725         herrors->Fill(float(errorType));
0726         moduleErrors++;
0727         int errorTypeMod = errorType;
0728 
0729         //cout<<" fed " <<FedId<<" type "<<errorType<<" "<<hex<<word32<<" "<<word64<<dec<<" "<<di->getMessage()<<endl;
0730         if (PRINT)
0731           cout << " fed " << FedId << " type " << errorType << endl;
0732 
0733         int status = 0;
0734         int fedChannel = 0;
0735         //const bool printData    = true;
0736 
0737         if (errorType >= 26 && errorType <= 31) {  // fed error
0738           status = MyDecode::error(word32, fedChannel, FedId, PRINT);
0739           if (PRINT)
0740             cout << " fed " << FedId << " "
0741                  << "Channel " << fedChannel << " " << status << endl;
0742 
0743           hfedErrors0->Fill(float(FedId), float(fedChannel));
0744 
0745           switch (errorType) {
0746             case (28): {  // FIFO
0747               hfedErrors4->Fill(float(FedId), float(fedChannel));
0748               hfed2d0->Fill(float(FedId), float(errorTypeMod));
0749               htype->Fill(float(errorTypeMod));
0750               break;
0751             }
0752 
0753             case (29): {  // TIMEOUT
0754               hfedErrors1->Fill(float(FedId), float(fedChannel));
0755               hfed2d0->Fill(float(FedId), float(errorTypeMod));
0756               htype->Fill(float(errorTypeMod));
0757               break;
0758             }
0759 
0760             case (30): {  // TRAILER
0761 
0762               int tbm = (word32 & 0xff);
0763               int mode = (word32 >> 8) & 0xf;
0764               hmode->Fill(float(mode));
0765               //cout<<" error 30 "<<hex<<mode<<dec<<endl;
0766 
0767               if (tbm != 0) {  // trailer
0768                 htbm->Fill(float(tbm));
0769                 hfedErrors6->Fill(float(FedId), float(fedChannel));
0770                 errorTypeMod = 20;
0771                 hfed2d0->Fill(float(FedId), float(errorTypeMod));
0772                 htype->Fill(float(errorTypeMod));
0773               }
0774 
0775               if ((mode & 0x8) != 0) {  // nor
0776                 //cout<<" NOR "<<endl;
0777                 hfedErrors5->Fill(float(FedId), float(fedChannel));
0778                 errorTypeMod = 21;
0779                 hfed2d0->Fill(float(FedId), float(errorTypeMod));
0780                 htype->Fill(float(errorTypeMod));
0781               }
0782 
0783               if ((mode & 0x1) != 0) {  // overflow
0784                 hfedErrors2->Fill(float(FedId), float(fedChannel));
0785                 errorTypeMod = 22;
0786                 hfed2d0->Fill(float(FedId), float(errorTypeMod));
0787                 htype->Fill(float(errorTypeMod));
0788               }
0789 
0790               if ((mode & 0x6) != 0) {  // fsm
0791                 hfedErrors7->Fill(float(FedId), float(fedChannel));
0792                 errorTypeMod = 23;
0793                 hfed2d0->Fill(float(FedId), float(errorTypeMod));
0794                 htype->Fill(float(errorTypeMod));
0795               }
0796 
0797               break;
0798             }
0799 
0800             case (31): {  // EVE
0801               hfedErrors3->Fill(float(FedId), float(fedChannel));
0802               hfed2d0->Fill(float(FedId), float(errorTypeMod));
0803               htype->Fill(float(errorTypeMod));
0804               break;
0805             }
0806           }  // end switch
0807 
0808         } else if (errorType >= 32 && errorType <= 34) {
0809           cout << " Slink error " << endl;
0810           hfedsSlink->Fill(float(FedId));
0811           hfed2d0->Fill(float(FedId), float(errorTypeMod));
0812           htype->Fill(float(errorTypeMod));
0813 
0814         } else if (errorType == 25 || (errorType >= 35 && errorType <= 38)) {  // conversion error
0815 
0816           status = MyDecode::data(word32, fedChannel, FedId, PRINT);
0817           if (PRINT)
0818             cout << " fed " << FedId << " "
0819                  << "Channel " << fedChannel << " " << status << endl;
0820 
0821           hfedErrors0->Fill(float(FedId), float(fedChannel));
0822           hfed2d0->Fill(float(FedId), float(errorTypeMod));
0823           htype->Fill(float(errorTypeMod));
0824 
0825           switch (errorType) {
0826             case (25): {  // inv ROC
0827               hfedErrors8->Fill(float(FedId), float(fedChannel));
0828               break;
0829             }
0830             case (36): {  // inv ROC
0831               hfedErrors8->Fill(float(FedId), float(fedChannel));
0832               break;
0833             }
0834             case (37): {  // inv DCOL&PIX
0835               hfedErrors9->Fill(float(FedId), float(fedChannel));
0836               if (FedId == 6 && fedChannel == 35) {
0837                 spareCounts++;
0838                 cout << errorType << " " << FedId << " " << fedChannel;
0839                 if (subid == 1)
0840                   cout << " BPix: layer " << layer << " ladder " << ladder << " module " << module << endl;
0841                 else
0842                   cout << " FPix: disk " << disk << " " << blade << " " << zindex << endl;
0843               }
0844               break;
0845             }
0846           }
0847 
0848         } else if (errorType == 39) {  // CRC
0849           cout << " CRC error " << endl;
0850           hfedsCRC->Fill(float(FedId));
0851           hfed2d0->Fill(float(FedId), float(errorTypeMod));
0852           htype->Fill(float(errorTypeMod));
0853 
0854         } else {
0855           cout << " unknown error " << errorType << endl;
0856           hfedsUnknown->Fill(float(FedId));
0857           errorTypeMod = 24;
0858           hfed2d0->Fill(float(FedId), float(errorTypeMod));
0859           htype->Fill(float(errorTypeMod));
0860         }
0861 
0862         hfed2d->Fill(float(FedId), float(errorTypeMod));
0863 
0864         if (errorTypeMod >= 0 && errorTypeMod < 40)
0865           countErrors2[errorTypeMod]++;
0866 
0867       }  // for
0868 
0869     }  // if fed/module
0870 
0871   }  // end det loop
0872 }
0873 
0874 #include "FWCore/Framework/interface/MakerMacros.h"
0875 DEFINE_FWK_MODULE(FedErrorDumper);