CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CalibTracker/SiStripCommon/src/SiStripDCSStatus.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripCommon/interface/SiStripDCSStatus.h" 
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "DataFormats/Scalers/interface/DcsStatus.h"
00008 
00009 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00010 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00011 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00012 
00013 // FED cabling and numbering                                                                                                                  
00014 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
00015 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00016 
00017 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00018 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00019 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00020 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00021 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00022 
00023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00024 #include <iostream>
00025  
00026 //
00027 // -- Constructor
00028 //
00029 SiStripDCSStatus::SiStripDCSStatus() :
00030   TIBTIDinDAQ(false),
00031   TOBinDAQ(false),
00032   TECFinDAQ(false),
00033   TECBinDAQ(false),
00034   trackerAbsent(false),
00035   rawdataAbsent(true),
00036   initialised(false) {
00037 }
00038 //
00039 // -- Destructor
00040 //
00041 SiStripDCSStatus::~SiStripDCSStatus() {
00042 }
00043 //
00044 // -- Get State
00045 //
00046 bool SiStripDCSStatus::getStatus(edm::Event const& e, edm::EventSetup const& eSetup){
00047 
00048   bool retVal = true;
00049   if (!initialised) initialise(e, eSetup);
00050 
00051   edm::Handle<DcsStatusCollection> dcsStatus;
00052   e.getByLabel("scalersRawToDigi", dcsStatus);
00053   if ( trackerAbsent || !dcsStatus.isValid())  return retVal;
00054   if ((*dcsStatus).size() == 0) return retVal;
00055 
00056   statusTIBTID = true;
00057   statusTOB    = true;
00058   statusTECF   = true;
00059   statusTECB   = true;
00060 
00061   bool dcsTIBTID = ((*dcsStatus)[0].ready(DcsStatus::TIBTID));
00062   bool dcsTOB    = ((*dcsStatus)[0].ready(DcsStatus::TOB));
00063   bool dcsTECF   = ((*dcsStatus)[0].ready(DcsStatus::TECp));
00064   bool dcsTECB   = ((*dcsStatus)[0].ready(DcsStatus::TECm));
00065   if (rawdataAbsent) {
00066     statusTIBTID = dcsTIBTID;
00067     statusTOB    = dcsTOB;
00068     statusTECF   = dcsTECF;
00069     statusTECB   = dcsTECB;
00070   } else {
00071     if ( TIBTIDinDAQ && !dcsTIBTID ) statusTIBTID = false;
00072     if ( TOBinDAQ    && !dcsTOB )    statusTOB    = false;
00073     if ( TECFinDAQ   && !dcsTECF )   statusTECF   = false;
00074     if ( TECBinDAQ   && !dcsTECB )   statusTECB   = false;
00075   }
00076   
00077   LogDebug("SiStripDCSStatus") << " SiStripDCSStatus :: Detectors in DAQ (TIBTID, TOB, TEC+ TEC-)" 
00078             << TIBTIDinDAQ << " " 
00079             << TOBinDAQ << " " 
00080             << TECFinDAQ << " " 
00081             << TECBinDAQ << std::endl;
00082   LogDebug("SiStripDCSStatus") << " SiStripDCSStatus :: Detectors in ON (TIBTID, TOB, TEC+ TEC-)"
00083             << dcsTIBTID << " "
00084             << dcsTOB << " "
00085             << dcsTECF << " "
00086             << dcsTECB << std::endl;
00087   
00088   LogDebug("SiStripDCSStatus") << " SiStripDCSStatus :: Final Flags     (TIBTID, TOB, TEC+ TEC-)"
00089             << statusTIBTID << " " 
00090             << statusTOB  << " " 
00091             << statusTECF << " " 
00092             << statusTECB << std::endl;
00093   if (statusTIBTID && statusTOB && statusTECF && statusTECB) retVal = true;
00094   else retVal = false;
00095   LogDebug("SiStripDCSStatus") << " Return Value " << retVal ;
00096   return retVal;
00097 }
00098 //
00099 // -- initialise
00100 //
00101 void SiStripDCSStatus::initialise(edm::Event const& e, edm::EventSetup const& eSetup) {
00102 
00103   edm::ESHandle< SiStripFedCabling > fedCabling_;
00104   eSetup.get<SiStripFedCablingRcd>().get(fedCabling_);
00105   const std::vector<uint16_t>& connectedFEDs = fedCabling_->feds();
00106 
00107   edm::Handle<FEDRawDataCollection> rawDataHandle;
00108   e.getByLabel("source", rawDataHandle);
00109 
00110   if ( !rawDataHandle.isValid() ) {
00111     rawdataAbsent = true;
00112     return;
00113   }
00114 
00115   rawdataAbsent = false;
00116   const FEDRawDataCollection& rawDataCollection = *rawDataHandle;
00117   for(std::vector<unsigned short>::const_iterator ifed = connectedFEDs.begin(); ifed != connectedFEDs.end(); ifed++){
00118     const std::vector<FedChannelConnection> fedChannels = fedCabling_->connections( *ifed );
00119     if (!(rawDataCollection.FEDData(*ifed).size()) || !(rawDataCollection.FEDData(*ifed).data()) ) continue;
00120     // Check Modules Connected
00121     for (std::vector<FedChannelConnection>::const_iterator iconn = fedChannels.begin();
00122          iconn < fedChannels.end(); iconn++){
00123       if (!iconn->isConnected()) continue;
00124       uint32_t detId = iconn->detId();
00125       StripSubdetector subdet(detId);
00126       if ( (subdet.subdetId() == StripSubdetector::TIB) || (subdet.subdetId() == StripSubdetector::TID)) {
00127         TIBTIDinDAQ = true;
00128         break;
00129       } else if (subdet.subdetId() == StripSubdetector::TOB) {
00130         TOBinDAQ = true;
00131         break;
00132       } else if (subdet.subdetId() == StripSubdetector::TEC) {
00133         if (TECDetId(detId).side() == 2) TECFinDAQ = true;
00134         else if (TECDetId(detId).side() == 1) TECBinDAQ = true;
00135         break;
00136       }
00137     }
00138     if (TIBTIDinDAQ && TOBinDAQ && TECFinDAQ && TECBinDAQ) break;
00139   } 
00140   initialised = true;
00141   if (!TIBTIDinDAQ && !TOBinDAQ && !TECFinDAQ && !TECBinDAQ) trackerAbsent = true;
00142 }