Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:14

0001 
0002 #include "DataFormats/SiStripCommon/interface/SiStripEventSummary.h"
0003 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <iostream>
0006 #include <iomanip>
0007 
0008 using namespace sistrip;
0009 
0010 // -----------------------------------------------------------------------------
0011 //
0012 SiStripEventSummary::SiStripEventSummary()
0013     : valid_(true),
0014       triggerFed_(0),
0015       runType_(sistrip::UNDEFINED_RUN_TYPE),
0016       event_(0),
0017       bx_(0),
0018       spillNumber_(0),
0019       nDataSenders_(0),
0020       fedReadoutMode_(sistrip::UNDEFINED_FED_READOUT_MODE),
0021       apvReadoutMode_(sistrip::UNDEFINED_APV_READOUT_MODE),
0022       apveAddress_(0),
0023       nApvsInSync_(0),
0024       nApvsOutOfSync_(0),
0025       nApvsErrors_(0),
0026       params_(5, 0) {
0027   ;
0028 }
0029 
0030 // -----------------------------------------------------------------------------
0031 //
0032 void SiStripEventSummary::commissioningInfo(const uint32_t* const buffer, const uint32_t& event) {
0033   // Set RunType
0034   uint16_t run = static_cast<uint16_t>(buffer[10] & 0xFFFF);
0035   runType_ = SiStripEnumsAndStrings::runType(run);
0036 
0037   // Set spill number
0038   spillNumber_ = buffer[0];
0039 
0040   // Set number of DataSenders
0041   nDataSenders_ = buffer[20];
0042 
0043   // Set FED readout mode
0044   if (buffer[15] == 0) {
0045     fedReadoutMode_ = sistrip::FED_SCOPE_MODE;
0046   } else if (buffer[15] == 1) {
0047     fedReadoutMode_ = sistrip::FED_VIRGIN_RAW;
0048   } else if (buffer[15] == 2) {
0049     fedReadoutMode_ = sistrip::FED_PROC_RAW;
0050   } else if (buffer[15] == 3) {
0051     fedReadoutMode_ = sistrip::FED_ZERO_SUPPR;
0052   } else if (buffer[15] == 4) {
0053     fedReadoutMode_ = sistrip::FED_ZERO_SUPPR_LITE;
0054   } else {
0055     fedReadoutMode_ = sistrip::UNKNOWN_FED_READOUT_MODE;
0056   }
0057 
0058   // Set hardware parameters
0059   if (runType_ == sistrip::CALIBRATION || runType_ == sistrip::CALIBRATION_DECO ||
0060       runType_ == sistrip::CALIBRATION_SCAN || runType_ == sistrip::CALIBRATION_SCAN_DECO ||
0061       runType_ == sistrip::APV_LATENCY) {
0062     params_[0] = buffer[11];  // latency
0063     params_[1] = buffer[12];  // cal_chan
0064     params_[2] = buffer[13];  // cal_sel
0065     params_[3] = buffer[15];  // isha
0066     params_[4] = buffer[16];  // vfs
0067 
0068   } else if (runType_ == sistrip::OPTO_SCAN) {
0069     params_[0] = buffer[11];  // opto gain
0070     params_[1] = buffer[12];  // opto bias
0071 
0072   } else if (runType_ == sistrip::APV_TIMING || runType_ == sistrip::FED_TIMING) {
0073     params_[0] = buffer[11];                     // pll coarse delay
0074     params_[1] = buffer[12];                     // pll fine delay
0075     params_[2] = buffer[13];                     // ttcrx delay
0076   } else if (runType_ == sistrip::FINE_DELAY ||  //@@ layer
0077              runType_ == sistrip::FINE_DELAY_PLL || runType_ == sistrip::FINE_DELAY_TTC) {
0078     params_[0] = buffer[11];  // pll coarse delay
0079     params_[1] = buffer[12];  // pll fine delay
0080     params_[2] = buffer[13];  // ttcrx delay
0081     params_[3] = buffer[14];  // layer (private format: DDSSLLLL, det, side, layer)
0082 
0083   } else if (runType_ == sistrip::FAST_CABLING) {
0084     params_[0] = buffer[11];  // bin number
0085     params_[1] = buffer[12];  // fec instance
0086     params_[2] = buffer[13];  // fec ip
0087     params_[3] = buffer[14];  // dcu hard id
0088 
0089   } else if (runType_ == sistrip::FED_CABLING || runType_ == sistrip::QUITE_FAST_CABLING) {
0090     if (runType_ == sistrip::QUITE_FAST_CABLING) {
0091       uint16_t ii = 0;
0092       bool found = false;
0093       while (!found && ii < 20) {
0094         uint32_t dcu = buffer[21 + 3 * ii];
0095         uint32_t key = buffer[21 + 3 * ii + 1];
0096         uint32_t evt = buffer[21 + 3 * ii + 2];
0097         if (evt == event) {
0098           params_[0] = key;  // device id
0099           params_[1] = 0;    // process id
0100           params_[2] = 0;    // process ip
0101           params_[3] = dcu;  // dcu hard id
0102           found = true;
0103         }
0104         ii++;
0105       }
0106       if (!found) {
0107         if (edm::isDebugEnabled()) {
0108           std::stringstream ss;
0109           ss << "[SiStripEventSummary::" << __func__ << "]"
0110              << " Did not find DeviceId/DCUid for event " << event << "!";
0111           edm::LogWarning(mlDigis_) << ss.str();
0112         }
0113         params_[0] = 0;
0114         params_[1] = 0;
0115         params_[2] = 0;
0116         params_[3] = 0;
0117       } else {
0118         if (edm::isDebugEnabled()) {
0119           std::stringstream ss;
0120           ss << "[SiStripEventSummary::" << __func__ << "]"
0121              << " Found DeviceId/DCUid for event " << event << ": 0x" << std::hex << std::setw(8) << std::setfill('0')
0122              << params_[0] << std::dec << "/0x" << std::hex << std::setw(8) << std::setfill('0') << params_[3]
0123              << std::dec;
0124           LogTrace(mlDigis_) << ss.str();
0125         }
0126       }
0127 
0128     } else {
0129       params_[0] = buffer[11];  // device id
0130       params_[1] = buffer[12];  // process id
0131       params_[2] = buffer[13];  // process ip
0132       params_[3] = buffer[14];  // dcu hard id
0133     }
0134 
0135   } else if (runType_ == sistrip::VPSP_SCAN) {
0136     params_[0] = buffer[11];  // vpsp value
0137     params_[1] = buffer[12];  // ccu channel
0138 
0139   } else if (runType_ == sistrip::DAQ_SCOPE_MODE) {
0140     // nothing interesting!
0141 
0142   } else if (runType_ == sistrip::PHYSICS || runType_ == sistrip::PHYSICS_ZS || runType_ == sistrip::PEDESTALS) {
0143     //@@ do anything?...
0144 
0145   } else {
0146     if (edm::isDebugEnabled()) {
0147       edm::LogWarning(mlDigis_) << "[SiStripEventSummary::" << __func__ << "]"
0148                                 << " Unexpected commissioning task: " << runType_;
0149     }
0150   }
0151 }
0152 
0153 // -----------------------------------------------------------------------------
0154 //
0155 
0156 // -----------------------------------------------------------------------------
0157 //
0158 void SiStripEventSummary::commissioningInfo(const uint32_t& daq1, const uint32_t& daq2) {
0159   // Extract if commissioning info are valid or not
0160   uint16_t temp = static_cast<uint16_t>((daq1 >> 8) & 0x3);
0161   if (temp == uint16_t(1)) {
0162     valid_ = true;
0163   } else if (temp == uint16_t(2)) {
0164     valid_ = false;
0165   } else if (temp == uint16_t(3) && daq1 == sistrip::invalid32_) {
0166     if (edm::isDebugEnabled()) {
0167       edm::LogWarning(mlDigis_) << "[SiStripEventSummary::" << __func__ << "]"
0168                                 << " DAQ register contents set to invalid: 0x" << std::hex << std::setw(8)
0169                                 << std::setfill('0') << daq1 << std::dec;
0170     }
0171     valid_ = false;
0172   } else {
0173     if (edm::isDebugEnabled()) {
0174       edm::LogWarning(mlDigis_) << "[SiStripEventSummary::" << __func__ << "]"
0175                                 << " Unexpected bit pattern set in DAQ1: 0x" << std::hex << std::setw(8)
0176                                 << std::setfill('0') << daq1 << std::dec;
0177     }
0178     valid_ = false;
0179   }
0180 
0181   // Set RunType
0182   uint16_t run = static_cast<uint16_t>(daq1 & 0xFF);
0183   runType_ = SiStripEnumsAndStrings::runType(run);
0184 
0185   // Set hardware parameters
0186   if (runType_ == sistrip::PHYSICS) {
0187   } else if (runType_ == sistrip::PHYSICS_ZS) {
0188   } else if (runType_ == sistrip::PEDESTALS) {
0189   } else if (runType_ == sistrip::DAQ_SCOPE_MODE) {
0190   } else if (runType_ == sistrip::CALIBRATION or runType_ == sistrip::CALIBRATION_DECO) {
0191     params_[0] = (daq2 >> 8) & 0xFF;  // latency
0192     params_[1] = (daq2 >> 4) & 0x0F;  // cal_chan
0193     params_[2] = (daq2 >> 0) & 0x0F;  // cal_sel
0194   } else if (runType_ == sistrip::CALIBRATION_SCAN or runType_ == sistrip::CALIBRATION_SCAN_DECO) {
0195     params_[0] = (daq2 >> 8) & 0xFF;   // latency
0196     params_[1] = (daq2 >> 4) & 0x0F;   // cal_chan
0197     params_[2] = (daq2 >> 0) & 0x0F;   // cal_sel
0198     params_[3] = (daq2 >> 16) & 0xFF;  // isha
0199     params_[4] = (daq2 >> 24);         // vfs
0200   } else if (runType_ == sistrip::OPTO_SCAN) {
0201     params_[0] = (daq2 >> 8) & 0xFF;  // opto gain
0202     params_[1] = (daq2 >> 0) & 0xFF;  // opto bias
0203   } else if (runType_ == sistrip::APV_TIMING) {
0204     params_[1] = (daq2 >> 0) & 0xFF;  // pll fine delay
0205   } else if (runType_ == sistrip::APV_LATENCY) {
0206     params_[0] = (daq2 >> 0) & 0xFF;  // latency
0207   } else if (runType_ == sistrip::FINE_DELAY_PLL) {
0208   } else if (runType_ == sistrip::FINE_DELAY_TTC) {
0209   } else if (runType_ == sistrip::FINE_DELAY) {            //@@ layer
0210     params_[2] = (daq2 >> 0) & 0xFFFF;                     // ttcrx delay
0211     params_[0] = params_[2] / 25;                          // pll coarse delay
0212     params_[1] = uint32_t((params_[2] % 25) * 24. / 25.);  // pll fine delay
0213     params_[3] = (daq2 >> 0) & 0xFFFF0000;                 // layer (private format: DDSSLLLL (det, side, layer)
0214   } else if (runType_ == sistrip::FED_TIMING) {
0215     params_[1] = (daq2 >> 0) & 0xFF;  // pll fine delay
0216   } else if (runType_ == sistrip::VPSP_SCAN) {
0217     params_[0] = (daq2 >> 8) & 0xFF;  // vpsp value
0218     params_[1] = (daq2 >> 0) & 0xFF;  // ccu channel
0219   } else if (runType_ == sistrip::FED_CABLING) {
0220   } else if (runType_ == sistrip::QUITE_FAST_CABLING) {
0221   } else if (runType_ == sistrip::FAST_CABLING) {
0222     params_[0] = (daq2 >> 0) & 0xFF;  // key
0223   } else {
0224     if (edm::isDebugEnabled()) {
0225       edm::LogWarning(mlDigis_) << "[SiStripEventSummary::" << __func__ << "]"
0226                                 << " Unexpected commissioning task: " << runType_;
0227     }
0228   }
0229 }
0230 
0231 // -----------------------------------------------------------------------------
0232 //
0233 void SiStripEventSummary::fedReadoutMode(const uint16_t& mode) {
0234   if (mode == 1) {
0235     fedReadoutMode_ = sistrip::FED_SCOPE_MODE;
0236   } else if (mode == 2) {
0237     fedReadoutMode_ = sistrip::FED_VIRGIN_RAW;
0238   } else if (mode == 6) {
0239     fedReadoutMode_ = sistrip::FED_PROC_RAW;
0240   } else if (mode == 10) {
0241     fedReadoutMode_ = sistrip::FED_ZERO_SUPPR;
0242   } else if (mode == 12) {
0243     fedReadoutMode_ = sistrip::FED_ZERO_SUPPR_LITE;
0244   } else {
0245     fedReadoutMode_ = sistrip::UNKNOWN_FED_READOUT_MODE;
0246   }
0247 }
0248 
0249 // -----------------------------------------------------------------------------
0250 //
0251 std::ostream& operator<<(std::ostream& os, const SiStripEventSummary& input) {
0252   return os << "[SiStripEventSummary::" << __func__ << "]" << std::endl
0253             << " isSet                : " << std::boolalpha << input.isSet() << std::noboolalpha << std::endl
0254             << " Trigger FED id       : " << input.triggerFed() << std::endl
0255             << " isValid              : " << std::boolalpha << input.valid() << std::noboolalpha << std::endl
0256             << " Run type             : " << SiStripEnumsAndStrings::runType(input.runType()) << std::endl
0257             << " Event number         : " << input.event() << std::endl
0258             << " Bunch crossing       : " << input.bx() << std::endl
0259             << " FED readout mode     : " << SiStripEnumsAndStrings::fedReadoutMode(input.fedReadoutMode()) << std::endl
0260             << " APV readout mode     : " << SiStripEnumsAndStrings::apvReadoutMode(input.apvReadoutMode()) << std::endl
0261             << " Commissioning params : " << input.params()[0] << ", " << input.params()[1] << ", " << input.params()[2]
0262             << ", " << input.params()[3] << std::endl;
0263 }