Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
// -*- C++ -*-
//
// Package:    DQM/SiStripMonitorHardware
// Class:      FEDErrors
//
/**\class FEDErrors DQM/SiStripMonitorHardware/interface/FEDErrors.hh

 Description: class summarising FED errors
*/
//
// Original Author:  Nicholas Cripps in plugin file
//         Created:  2008/09/16
// Modified by    :  Anne-Marie Magnan, code copied from plugin to this class
//

#ifndef DQM_SiStripMonitorHardware_FEDErrors_HH
#define DQM_SiStripMonitorHardware_FEDErrors_HH

#include <sstream>
#include <iostream>
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "DataFormats/FEDRawData/interface/FEDRawData.h"
#include "DataFormats/FEDRawData/interface/FEDNumbering.h"

#include "DQMServices/Core/interface/DQMStore.h"

#include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"

#include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"

class TkHistoMap;
class TrackerTopology;

class FEDErrors {
public:
  typedef dqm::legacy::MonitorElement MonitorElement;
  typedef dqm::legacy::DQMStore DQMStore;

  struct FEDCounters {
    unsigned int nFEDErrors;
    unsigned int nDAQProblems;
    unsigned int nFEDsWithFEProblems;
    unsigned int nCorruptBuffers;
    unsigned int nBadChannels;
    unsigned int nBadActiveChannels;
    unsigned int nFEDsWithFEOverflows;
    unsigned int nFEDsWithFEBadMajorityAddresses;
    unsigned int nFEDsWithMissingFEs;
    unsigned int nTotalBadChannels;
    unsigned int nTotalBadActiveChannels;
  };

  struct ChannelCounters {
    unsigned int nNotConnected;
    unsigned int nUnlocked;
    unsigned int nOutOfSync;
    unsigned int nAPVStatusBit;
    unsigned int nAPVError;
    unsigned int nAPVAddressError;
  };

  struct FECounters {
    unsigned int nFEOverflows;
    unsigned int nFEBadMajorityAddresses;
    unsigned int nFEMissing;
  };

  struct FEDLevelErrors {
    bool HasCabledChannels;
    bool DataPresent;
    bool DataMissing;
    bool InvalidBuffers;
    bool BadFEDCRCs;
    bool BadDAQCRCs;
    bool BadIDs;
    bool BadDAQPacket;
    bool CorruptBuffer;
    bool FEsOverflow;
    bool FEsMissing;
    bool FEsBadMajorityAddress;
    bool BadChannelStatusBit;
    bool BadActiveChannelStatusBit;
  };

  struct FELevelErrors {
    unsigned short FeID;
    unsigned short SubDetID;
    bool Overflow;
    bool Missing;
    bool BadMajorityAddress;
    int TimeDifference;
    unsigned int Apve;
    unsigned int FeMaj;
  };

  struct ChannelLevelErrors {
    unsigned int ChannelID;
    bool Connected;
    bool IsActive;
    bool Unlocked;
    bool OutOfSync;
    bool operator<(const ChannelLevelErrors& aErr) const;
  };

  struct APVLevelErrors {
    unsigned int APVID;
    unsigned int ChannelID;
    bool Connected;
    bool IsActive;
    bool APVStatusBit;
    bool APVError;
    bool APVAddressError;

    bool operator<(const APVLevelErrors& aErr) const;
  };

  struct EventProperties {
    long long deltaBX;
  };

  FEDErrors();

  ~FEDErrors();

  void initialiseLumiBlock();

  void initialiseEvent();

  void initialiseFED(const unsigned int aFedID,
                     const SiStripFedCabling* aCabling,
                     const TrackerTopology* tTopo,
                     bool initVars = true);

  //return false if no data, with or without cabled channels.
  bool checkDataPresent(const FEDRawData& aFedData);

  //perform a sanity check with unpacking code check
  bool failUnpackerFEDCheck();

  //return true if there were no errors at the level they are analysing
  //ie analyze FED returns true if there were no FED level errors which prevent the whole FED being unpacked
  bool fillFatalFEDErrors(const FEDRawData& aFedData, const unsigned int aPrintDebug);

  //expensive check: fatal but kept separate
  bool fillCorruptBuffer(const sistrip::FEDBuffer& aBuffer);

  //FE/Channel check: rate of channels with error (only considering connected channels)
  float fillNonFatalFEDErrors(const sistrip::FEDBuffer* aBuffer, const SiStripFedCabling* aCabling = nullptr);

  //fill errors: define the order of importance.
  bool fillFEDErrors(const FEDRawData& aFedData,
                     bool& aFullDebug,
                     const unsigned int aPrintDebug,
                     unsigned int& aCounterMonitoring,
                     unsigned int& aCounterUnpacker,
                     const bool aDoMeds,
                     MonitorElement* aMedianHist0,
                     MonitorElement* aMedianHist1,
                     const bool aDoFEMaj,
                     std::vector<std::vector<std::pair<unsigned int, unsigned int> > >& aFeMajFrac);

  bool fillFEErrors(const sistrip::FEDBuffer& aBuffer,
                    const bool aDoFEMaj,
                    std::vector<std::vector<std::pair<unsigned int, unsigned int> > >& aFeMajFrac);

  bool fillChannelErrors(const sistrip::FEDBuffer& aBuffer,
                         bool& aFullDebug,
                         const unsigned int aPrintDebug,
                         unsigned int& aCounterMonitoring,
                         unsigned int& aCounterUnpacker,
                         const bool aDoMeds,
                         MonitorElement* aMedianHist0,
                         MonitorElement* aMedianHist1);

  //1--Add all channels of a FED if anyFEDErrors or corruptBuffer
  //2--if aFillAll = true, add all channels anyway with 0 if no errors, so TkHistoMap is filled for all valid channels ...
  void fillBadChannelList(const bool doTkHistoMap,
                          TkHistoMap* aTkMapPointer,
                          MonitorElement* aFedIdVsApvId,
                          unsigned int& aNBadChannels,
                          unsigned int& aNBadActiveChannels,
                          unsigned int& aNBadChannels_perFEDID,
                          std::vector<unsigned int>& nTotal,
                          std::vector<unsigned int>& nErrors);

  void fillEventProperties(long long dbx);

  //bool foundFEDErrors();

  const bool failMonitoringFEDCheck();

  const bool anyDAQProblems();

  const bool anyFEDErrors();

  const bool anyFEProblems();

  const bool printDebug();

  const unsigned int fedID();

  FEDCounters& getFEDErrorsCounters();

  ChannelCounters& getChannelErrorsCounters();

  FECounters& getFEErrorsCounters();

  FEDLevelErrors& getFEDLevelErrors();

  EventProperties& getEventProperties();

  std::vector<FELevelErrors>& getFELevelErrors();

  std::vector<ChannelLevelErrors>& getChannelLevelErrors();

  std::vector<APVLevelErrors>& getAPVLevelErrors();

  std::vector<std::pair<unsigned int, bool> >& getBadChannels();

  void addBadFE(const FELevelErrors& aFE);

  void addBadChannel(const ChannelLevelErrors& aChannel);

  void addBadAPV(const APVLevelErrors& aAPV, bool& aFirst);

  void incrementFEDCounters();

  void incrementChannelCounters(const FEDErrors::ChannelLevelErrors& aChannel);

  void incrementAPVCounters(const FEDErrors::APVLevelErrors& aAPV);

  void print(const FEDCounters& aFEDCounter, std::ostream& aOs = std::cout);
  void print(const FECounters& aFECounter, std::ostream& aOs = std::cout);
  void print(const FEDLevelErrors& aFEDErr, std::ostream& aOs = std::cout);
  void print(const FELevelErrors& aFEErr, std::ostream& aOs = std::cout);
  void print(const ChannelLevelErrors& aErr, std::ostream& aOs = std::cout);
  void print(const APVLevelErrors& aErr, std::ostream& aOs = std::cout);

protected:
private:
  void incrementLumiErrors(const bool hasError,
                           const unsigned int aSubDet,
                           std::vector<unsigned int>& nTotal,
                           std::vector<unsigned int>& nErrors);

  void processDet(const uint32_t aPrevId,
                  const uint16_t aPrevTot,
                  const bool doTkHistoMap,
                  uint16_t& nBad,
                  TkHistoMap* aTkMapPointer);

  unsigned int fedID_;

  std::vector<bool> connected_;
  std::vector<unsigned int> detid_;
  std::vector<unsigned short> nChInModule_;

  std::vector<unsigned short> subDetId_;

  FECounters feCounter_;
  FEDLevelErrors fedErrors_;
  ChannelCounters lChCounter_;
  FEDCounters lFedCounter_;

  std::vector<FELevelErrors> feErrors_;
  std::vector<ChannelLevelErrors> chErrorsDetailed_;
  std::vector<APVLevelErrors> apvErrors_;
  std::vector<std::pair<unsigned int, bool> > chErrors_;

  bool failUnpackerFEDCheck_;

  EventProperties eventProp_;

};  //class

#endif  //DQM_SiStripMonitorHardware_FEDErrors_HH