CMS 3D CMS Logo

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