Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:48

0001 #include "CalibTracker/SiStripCommon/interface/SiStripDCSStatus.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 
0005 #include "DataFormats/Common/interface/Handle.h"
0006 
0007 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0008 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0009 
0010 // FED cabling and numbering
0011 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0012 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0013 
0014 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0015 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0016 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0017 
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include <iostream>
0020 
0021 //
0022 // -- Constructor
0023 //
0024 SiStripDCSStatus::SiStripDCSStatus(edm::ConsumesCollector& iC)
0025     : TIBTIDinDAQ(false),
0026       TOBinDAQ(false),
0027       TECFinDAQ(false),
0028       TECBinDAQ(false),
0029       trackerAbsent(false),
0030       rawdataAbsent(true),
0031       initialised(false) {
0032   dcsStatusToken_ = iC.consumes<DcsStatusCollection>(edm::InputTag("scalersRawToDigi"));
0033   dcsRecordToken_ = iC.consumes<DCSRecord>(edm::InputTag("onlineMetaDataDigis"));
0034   rawDataToken_ = iC.consumes<FEDRawDataCollection>(edm::InputTag("rawDataCollector"));
0035   tTopoToken_ = iC.esConsumes<TrackerTopology, TrackerTopologyRcd>();
0036   fedCablingToken_ = iC.esConsumes<SiStripFedCabling, SiStripFedCablingRcd>();
0037 }
0038 //
0039 // -- Get State
0040 //
0041 bool SiStripDCSStatus::getStatus(edm::Event const& e, edm::EventSetup const& eSetup) {
0042   bool retVal = true;
0043   if (!initialised)
0044     initialise(e, eSetup);
0045 
0046   edm::Handle<DcsStatusCollection> dcsStatus;
0047   e.getByToken(dcsStatusToken_, dcsStatus);
0048 
0049   edm::Handle<DCSRecord> dcsRecord;
0050   e.getByToken(dcsRecordToken_, dcsRecord);
0051 
0052   bool statusTIBTID(true), statusTOB(true), statusTECF(true), statusTECB(true);
0053   bool dcsTIBTID(true), dcsTOB(true), dcsTECF(true), dcsTECB(true);
0054 
0055   if (trackerAbsent || (!dcsStatus.isValid() && !dcsRecord.isValid())) {
0056     return retVal;
0057   }
0058 
0059   if ((*dcsStatus).empty()) {
0060     if (e.eventAuxiliary().isRealData()) {
0061       dcsTIBTID = (*dcsRecord).highVoltageReady(DCSRecord::Partition::TIBTID);
0062       dcsTOB = (*dcsRecord).highVoltageReady(DCSRecord::Partition::TOB);
0063       dcsTECF = (*dcsRecord).highVoltageReady(DCSRecord::Partition::TECp);
0064       dcsTECB = (*dcsRecord).highVoltageReady(DCSRecord::Partition::TECm);
0065     } else {
0066       return retVal;
0067     }
0068   } else {
0069     dcsTIBTID = ((*dcsStatus)[0].ready(DcsStatus::TIBTID));
0070     dcsTOB = ((*dcsStatus)[0].ready(DcsStatus::TOB));
0071     dcsTECF = ((*dcsStatus)[0].ready(DcsStatus::TECp));
0072     dcsTECB = ((*dcsStatus)[0].ready(DcsStatus::TECm));
0073   }
0074 
0075   if (rawdataAbsent) {
0076     statusTIBTID = dcsTIBTID;
0077     statusTOB = dcsTOB;
0078     statusTECF = dcsTECF;
0079     statusTECB = dcsTECB;
0080   } else {
0081     if (TIBTIDinDAQ && !dcsTIBTID)
0082       statusTIBTID = false;
0083     if (TOBinDAQ && !dcsTOB)
0084       statusTOB = false;
0085     if (TECFinDAQ && !dcsTECF)
0086       statusTECF = false;
0087     if (TECBinDAQ && !dcsTECB)
0088       statusTECB = false;
0089   }
0090 
0091   LogDebug("SiStripDCSStatus") << " SiStripDCSStatus :: Detectors in DAQ (TIBTID, TOB, TEC+ TEC-)" << TIBTIDinDAQ << " "
0092                                << TOBinDAQ << " " << TECFinDAQ << " " << TECBinDAQ << std::endl;
0093   LogDebug("SiStripDCSStatus") << " SiStripDCSStatus :: Detectors in ON (TIBTID, TOB, TEC+ TEC-)" << dcsTIBTID << " "
0094                                << dcsTOB << " " << dcsTECF << " " << dcsTECB << std::endl;
0095 
0096   LogDebug("SiStripDCSStatus") << " SiStripDCSStatus :: Final Flags     (TIBTID, TOB, TEC+ TEC-)" << statusTIBTID << " "
0097                                << statusTOB << " " << statusTECF << " " << statusTECB << std::endl;
0098   if (statusTIBTID && statusTOB && statusTECF && statusTECB)
0099     retVal = true;
0100   else
0101     retVal = false;
0102   LogDebug("SiStripDCSStatus") << " Return Value " << retVal;
0103   return retVal;
0104 }
0105 //
0106 // -- initialise
0107 //
0108 void SiStripDCSStatus::initialise(edm::Event const& e, edm::EventSetup const& eSetup) {
0109   //Retrieve tracker topology from geometry
0110   const auto& tTopo = eSetup.getData(tTopoToken_);
0111   const auto& fedCabling_ = eSetup.getData(fedCablingToken_);
0112 
0113   auto connectedFEDs = fedCabling_.fedIds();
0114 
0115   edm::Handle<FEDRawDataCollection> rawDataHandle;
0116   //  e.getByLabel("source", rawDataHandle);
0117   e.getByToken(rawDataToken_, rawDataHandle);
0118 
0119   if (!rawDataHandle.isValid()) {
0120     rawdataAbsent = true;
0121     return;
0122   }
0123 
0124   rawdataAbsent = false;
0125   const FEDRawDataCollection& rawDataCollection = *rawDataHandle;
0126   for (std::vector<unsigned short>::const_iterator ifed = connectedFEDs.begin(); ifed != connectedFEDs.end(); ifed++) {
0127     auto fedChannels = fedCabling_.fedConnections(*ifed);
0128     if (!(rawDataCollection.FEDData(*ifed).size()) || !(rawDataCollection.FEDData(*ifed).data()))
0129       continue;
0130     // Check Modules Connected
0131     for (std::vector<FedChannelConnection>::const_iterator iconn = fedChannels.begin(); iconn < fedChannels.end();
0132          iconn++) {
0133       if (!iconn->isConnected())
0134         continue;
0135       uint32_t detId = iconn->detId();
0136       StripSubdetector subdet(detId);
0137       if ((subdet.subdetId() == StripSubdetector::TIB) || (subdet.subdetId() == StripSubdetector::TID)) {
0138         TIBTIDinDAQ = true;
0139         break;
0140       } else if (subdet.subdetId() == StripSubdetector::TOB) {
0141         TOBinDAQ = true;
0142         break;
0143       } else if (subdet.subdetId() == StripSubdetector::TEC) {
0144         if (tTopo.tecSide(detId) == 2)
0145           TECFinDAQ = true;
0146         else if (tTopo.tecSide(detId) == 1)
0147           TECBinDAQ = true;
0148         break;
0149       }
0150     }
0151     if (TIBTIDinDAQ && TOBinDAQ && TECFinDAQ && TECBinDAQ)
0152       break;
0153   }
0154   initialised = true;
0155   if (!TIBTIDinDAQ && !TOBinDAQ && !TECFinDAQ && !TECBinDAQ)
0156     trackerAbsent = true;
0157 }