CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiStripMonitorClient/src/SiStripDaqInfo.cc

Go to the documentation of this file.
00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 
00005 #include "DQMServices/Core/interface/DQMStore.h"
00006 #include "DQMServices/Core/interface/MonitorElement.h"
00007 
00008 #include "DQM/SiStripMonitorClient/interface/SiStripDaqInfo.h"
00009 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
00010 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00011 
00012 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00013 
00014 //Run Info
00015 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
00016 #include "CondFormats/RunInfo/interface/RunSummary.h"
00017 #include "CondFormats/RunInfo/interface/RunInfo.h"
00018 // FED cabling and numbering
00019 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
00020 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00021 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00022 
00023 #include <iostream>
00024 #include <iomanip>
00025 #include <stdio.h>
00026 #include <string>
00027 #include <sstream>
00028 #include <math.h>
00029 #include <vector>
00030 
00031 //
00032 // -- Contructor
00033 //
00034 SiStripDaqInfo::SiStripDaqInfo(edm::ParameterSet const& pSet) {
00035   // Create MessageSender
00036   edm::LogInfo( "SiStripDaqInfo") << "SiStripDaqInfo::Deleting SiStripDaqInfo ";
00037 
00038   // get back-end interface
00039   dqmStore_ = edm::Service<DQMStore>().operator->();
00040   nFedTotal = 0;
00041   bookedStatus_ = false;
00042 }
00043 SiStripDaqInfo::~SiStripDaqInfo() {
00044   edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo::Deleting SiStripDaqInfo ";
00045 
00046 }
00047 //
00048 // -- Begin Job
00049 //
00050 void SiStripDaqInfo::beginJob() {
00051  
00052 }
00053 //
00054 // -- Book MEs for SiStrip Daq Fraction
00055 //
00056 void SiStripDaqInfo::bookStatus() {
00057    edm::LogInfo( "SiStripDcsInfo") << " SiStripDaqInfo::bookStatus " << bookedStatus_;
00058   if (!bookedStatus_) {
00059     dqmStore_->cd();
00060     std::string strip_dir = "";
00061     SiStripUtility::getTopFolderPath(dqmStore_, "SiStrip", strip_dir);
00062     if (strip_dir.size() > 0) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo");
00063     else dqmStore_->setCurrentFolder("SiStrip/EventInfo");
00064 
00065     
00066     DaqFraction_= dqmStore_->bookFloat("DAQSummary");  
00067 
00068     dqmStore_->cd();    
00069     if (strip_dir.size() > 0) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo/DAQContents");
00070     else dqmStore_->setCurrentFolder("SiStrip/EventInfo/DAQContents");
00071       
00072     std::vector<std::string> det_type;
00073     det_type.push_back("TIB");
00074     det_type.push_back("TOB");
00075     det_type.push_back("TIDF");
00076     det_type.push_back("TIDB");
00077     det_type.push_back("TECF");
00078     det_type.push_back("TECB");
00079       
00080     for ( std::vector<std::string>::iterator it = det_type.begin(); it != det_type.end(); it++) {
00081       std::string det = (*it);
00082       
00083       SubDetMEs local_mes;      
00084       std::string me_name;
00085       me_name = "SiStrip_" + det;    
00086       local_mes.DaqFractionME = dqmStore_->bookFloat(me_name);          
00087       local_mes.ConnectedFeds = 0;
00088       SubDetMEsMap.insert(make_pair(det, local_mes));
00089     } 
00090     bookedStatus_ = true;
00091     dqmStore_->cd();
00092   }
00093 }
00094 //
00095 // -- Fill with Dummy values
00096 //
00097 void SiStripDaqInfo::fillDummyStatus() {
00098   if (!bookedStatus_) bookStatus();
00099   if (bookedStatus_) {
00100     for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
00101       it->second.DaqFractionME->Reset();
00102       it->second.DaqFractionME->Fill(-1.0);
00103     }
00104     DaqFraction_->Reset();
00105     DaqFraction_->Fill(-1.0);
00106   }
00107 }
00108 //
00109 // -- Begin Run
00110 //
00111 void SiStripDaqInfo::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
00112   edm::LogInfo ("SiStripDaqInfo") <<"SiStripDaqInfo:: Begining of Run";
00113 
00114   // Check latest Fed cabling and create TrackerMapCreator
00115   unsigned long long cacheID = eSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
00116   if (m_cacheID_ != cacheID) {
00117     m_cacheID_ = cacheID;       
00118 
00119     eSetup.get<SiStripFedCablingRcd>().get(fedCabling_); 
00120 
00121     readFedIds(fedCabling_, eSetup);
00122   }
00123   if (!bookedStatus_) bookStatus();  
00124   if (nFedTotal == 0) {
00125     fillDummyStatus();
00126     edm::LogInfo ("SiStripDaqInfo") <<" SiStripDaqInfo::No FEDs Connected!!!";
00127     return;
00128   }
00129   
00130   float nFEDConnected = 0.0;
00131   const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
00132   const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID; 
00133 
00134   edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd"));
00135   if( eSetup.find( recordKey ) != 0) {
00136 
00137     edm::ESHandle<RunInfo> sumFED;
00138     eSetup.get<RunInfoRcd>().get(sumFED);    
00139     
00140     if ( sumFED.isValid() ) {
00141       std::vector<int> FedsInIds= sumFED->m_fed_in;   
00142       for(unsigned int it = 0; it < FedsInIds.size(); ++it) {
00143         int fedID = FedsInIds[it];     
00144         
00145         if(fedID>=siStripFedIdMin &&  fedID<=siStripFedIdMax)  ++nFEDConnected;
00146       }
00147       edm::LogInfo ("SiStripDaqInfo") <<" SiStripDaqInfo::Total # of FEDs " << nFedTotal 
00148                                       << " Connected FEDs " << nFEDConnected;
00149       if (nFEDConnected > 0) {
00150         DaqFraction_->Reset();
00151         DaqFraction_->Fill(nFEDConnected/nFedTotal);
00152         readSubdetFedFractions(FedsInIds,eSetup);
00153       }
00154     }
00155   } 
00156 }
00157 //
00158 // -- Analyze
00159 //
00160 void SiStripDaqInfo::analyze(edm::Event const& event, edm::EventSetup const& eSetup) {
00161 }
00162 
00163 //
00164 // -- End Luminosity Block
00165 //
00166 void SiStripDaqInfo::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) {
00167   edm::LogInfo( "SiStripDaqInfo") << "SiStripDaqInfo::endLuminosityBlock";
00168 }
00169 //
00170 // -- End Run
00171 //
00172 void SiStripDaqInfo::endRun(edm::Run const& run, edm::EventSetup const& eSetup){
00173   edm::LogInfo ("SiStripDaqInfo") <<"SiStripDaqInfo::EndRun";
00174 }
00175 //
00176 // -- Read Sub Detector FEDs
00177 //
00178 void SiStripDaqInfo::readFedIds(const edm::ESHandle<SiStripFedCabling>& fedcabling, edm::EventSetup const& iSetup) {
00179 
00180   //Retrieve tracker topology from geometry
00181   edm::ESHandle<TrackerTopology> tTopoHandle;
00182   iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
00183   const TrackerTopology* const tTopo = tTopoHandle.product();
00184 
00185   const std::vector<uint16_t>& feds = fedCabling_->feds(); 
00186 
00187   nFedTotal = feds.size();
00188   for(std::vector<unsigned short>::const_iterator ifed = feds.begin(); ifed != feds.end(); ifed++){
00189     const std::vector<FedChannelConnection> fedChannels = fedCabling_->connections( *ifed );
00190     for (std::vector<FedChannelConnection>::const_iterator iconn = fedChannels.begin(); iconn < fedChannels.end(); iconn++){
00191       if (!iconn->isConnected()) continue;
00192       uint32_t detId = iconn->detId();
00193       if (detId == 0 || detId == 0xFFFFFFFF)  continue;
00194       std::string subdet_tag;
00195       SiStripUtility::getSubDetectorTag(detId,subdet_tag,tTopo);
00196       subDetFedMap[subdet_tag].push_back(*ifed); 
00197       break;
00198     }
00199   }  
00200 }
00201 //
00202 // -- Fill Subdet FEDIds 
00203 //
00204 void SiStripDaqInfo::readSubdetFedFractions(std::vector<int>& fed_ids, edm::EventSetup const& iSetup) {
00205 
00206   //Retrieve tracker topology from geometry
00207   edm::ESHandle<TrackerTopology> tTopoHandle;
00208   iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
00209   const TrackerTopology* const tTopo = tTopoHandle.product();
00210 
00211   const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
00212   const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID; 
00213 
00214   // initialiase 
00215   for (std::map<std::string, std::vector<unsigned short> >::const_iterator it = subDetFedMap.begin();
00216        it != subDetFedMap.end(); it++) {
00217     std::string name = it->first;
00218     std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(name);
00219     if (iPos == SubDetMEsMap.end()) continue;
00220     iPos->second.ConnectedFeds = 0;
00221   }
00222   // count sub detector feds
00223 
00224   
00225   for (std::map<std::string, std::vector<unsigned short> >::const_iterator it = subDetFedMap.begin();
00226            it != subDetFedMap.end(); it++) {
00227     std::string name = it->first;
00228     std::vector<unsigned short> subdetIds = it->second; 
00229     std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(name);
00230     if (iPos == SubDetMEsMap.end()) continue;
00231     iPos->second.ConnectedFeds = 0;
00232     for (std::vector<unsigned short>::iterator iv = subdetIds.begin();
00233          iv != subdetIds.end(); iv++) {
00234       bool fedid_found = false;
00235       for(unsigned int it = 0; it < fed_ids.size(); ++it) {
00236         unsigned short fedID = fed_ids[it];     
00237         if(fedID < siStripFedIdMin ||  fedID > siStripFedIdMax) continue;
00238         if ((*iv) == fedID) {
00239           fedid_found = true;
00240           iPos->second.ConnectedFeds++;
00241           break;
00242         }
00243       }
00244       if (!fedid_found) findExcludedModule((*iv),tTopo);   
00245     }
00246     int nFedsConnected   = iPos->second.ConnectedFeds;
00247     int nFedSubDet       = subdetIds.size();
00248     if (nFedSubDet > 0) {
00249       iPos->second.DaqFractionME->Reset();
00250       iPos->second.DaqFractionME->Fill(nFedsConnected*1.0/nFedSubDet);
00251     }
00252   }
00253 }
00254 //
00255 // -- find Excluded Modules
00256 //
00257 void SiStripDaqInfo::findExcludedModule(unsigned short fed_id, const TrackerTopology* tTopo) {
00258   dqmStore_->cd();
00259   std::string mdir = "MechanicalView";
00260   if (!SiStripUtility::goToDir(dqmStore_, mdir)) {
00261     dqmStore_->setCurrentFolder("SiStrip/"+mdir);
00262   }
00263   std::string mechanical_dir = dqmStore_->pwd();
00264   const std::vector<FedChannelConnection> fedChannels = fedCabling_->connections(fed_id);
00265   int ichannel = 0;
00266   std::string tag = "ExcludedFedChannel";
00267   std::string bad_module_folder;
00268   for (std::vector<FedChannelConnection>::const_iterator iconn = fedChannels.begin(); 
00269                                                          iconn < fedChannels.end(); iconn++){
00270     if (!iconn->isConnected()) continue;
00271     uint32_t detId = iconn->detId();
00272     if (detId == 0 || detId == 0xFFFFFFFF)  continue;
00273     
00274     ichannel++;
00275     if (ichannel == 1) {
00276       std::string subdet_folder ;
00277       SiStripFolderOrganizer folder_organizer;
00278       folder_organizer.getSubDetFolder(detId,tTopo,subdet_folder);
00279       if (!dqmStore_->dirExists(subdet_folder)) {
00280         subdet_folder = mechanical_dir + subdet_folder.substr(subdet_folder.find(mdir)+mdir.size());
00281       }
00282       bad_module_folder = subdet_folder + "/" + "BadModuleList";
00283       dqmStore_->setCurrentFolder(bad_module_folder);    
00284     }
00285     std::ostringstream detid_str;
00286     detid_str << detId;
00287     std::string full_path = bad_module_folder + "/" + detid_str.str();
00288     MonitorElement* me = dqmStore_->get(full_path);
00289     uint16_t flag = 0; 
00290     if (me) {
00291       flag = me->getIntValue();
00292       me->Reset();
00293     } else me = dqmStore_->bookInt(detid_str.str());
00294     SiStripUtility::setBadModuleFlag(tag, flag);
00295     me->Fill(flag);
00296   }
00297   dqmStore_->cd();
00298 }
00299 #include "FWCore/Framework/interface/MakerMacros.h"
00300 DEFINE_FWK_MODULE(SiStripDaqInfo);