CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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 FEDNumbering numbering;
00130   const int siStripFedIdMin = numbering.MINSiStripFEDID;
00131   const int siStripFedIdMax = numbering.MAXSiStripFEDID; 
00132 
00133   edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd"));
00134   if( eSetup.find( recordKey ) != 0) {
00135 
00136     edm::ESHandle<RunInfo> sumFED;
00137     eSetup.get<RunInfoRcd>().get(sumFED);    
00138     
00139     if ( sumFED.isValid() ) {
00140       std::vector<int> FedsInIds= sumFED->m_fed_in;   
00141       for(unsigned int it = 0; it < FedsInIds.size(); ++it) {
00142         int fedID = FedsInIds[it];     
00143         
00144         if(fedID>=siStripFedIdMin &&  fedID<=siStripFedIdMax)  ++nFEDConnected;
00145       }
00146       edm::LogInfo ("SiStripDaqInfo") <<" SiStripDaqInfo::Total # of FEDs " << nFedTotal 
00147                                       << " Connected FEDs " << nFEDConnected;
00148       if (nFEDConnected > 0) {
00149         DaqFraction_->Reset();
00150         DaqFraction_->Fill(nFEDConnected/nFedTotal);
00151         readSubdetFedFractions(FedsInIds);
00152       }
00153     }
00154   } 
00155 }
00156 //
00157 // -- Analyze
00158 //
00159 void SiStripDaqInfo::analyze(edm::Event const& event, edm::EventSetup const& eSetup) {
00160 }
00161 
00162 //
00163 // -- End Luminosity Block
00164 //
00165 void SiStripDaqInfo::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) {
00166   edm::LogInfo( "SiStripDaqInfo") << "SiStripDaqInfo::endLuminosityBlock";
00167 }
00168 //
00169 // -- End Run
00170 //
00171 void SiStripDaqInfo::endRun(edm::Run const& run, edm::EventSetup const& eSetup){
00172   edm::LogInfo ("SiStripDaqInfo") <<"SiStripDaqInfo::EndRun";
00173 }
00174 //
00175 // -- Read Sub Detector FEDs
00176 //
00177 void SiStripDaqInfo::readFedIds(const edm::ESHandle<SiStripFedCabling>& fedcabling) {
00178   const std::vector<uint16_t>& feds = fedCabling_->feds(); 
00179 
00180   nFedTotal = feds.size();
00181   for(std::vector<unsigned short>::const_iterator ifed = feds.begin(); ifed != feds.end(); ifed++){
00182     const std::vector<FedChannelConnection> fedChannels = fedCabling_->connections( *ifed );
00183     for (std::vector<FedChannelConnection>::const_iterator iconn = fedChannels.begin(); iconn < fedChannels.end(); iconn++){
00184       if (!iconn->isConnected()) continue;
00185       uint32_t detId = iconn->detId();
00186       if (detId == 0 || detId == 0xFFFFFFFF)  continue;
00187       std::string subdet_tag;
00188       SiStripUtility::getSubDetectorTag(detId,subdet_tag);         
00189       subDetFedMap[subdet_tag].push_back(*ifed); 
00190       break;
00191     }
00192   }  
00193 }
00194 //
00195 // -- Fill Subdet FEDIds 
00196 //
00197 void SiStripDaqInfo::readSubdetFedFractions(std::vector<int>& fed_ids) {
00198 
00199   const FEDNumbering numbering;
00200   const int siStripFedIdMin = numbering.MINSiStripFEDID;
00201   const int siStripFedIdMax = numbering.MAXSiStripFEDID; 
00202 
00203   // initialiase 
00204   for (std::map<std::string, std::vector<unsigned short> >::const_iterator it = subDetFedMap.begin();
00205        it != subDetFedMap.end(); it++) {
00206     std::string name = it->first;
00207     std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(name);
00208     if (iPos == SubDetMEsMap.end()) continue;
00209     iPos->second.ConnectedFeds = 0;
00210   }
00211   // count sub detector feds
00212 
00213   
00214   for (std::map<std::string, std::vector<unsigned short> >::const_iterator it = subDetFedMap.begin();
00215            it != subDetFedMap.end(); it++) {
00216     std::string name = it->first;
00217     std::vector<unsigned short> subdetIds = it->second; 
00218     std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(name);
00219     if (iPos == SubDetMEsMap.end()) continue;
00220     iPos->second.ConnectedFeds = 0;
00221     for (std::vector<unsigned short>::iterator iv = subdetIds.begin();
00222          iv != subdetIds.end(); iv++) {
00223       bool fedid_found = false;
00224       for(unsigned int it = 0; it < fed_ids.size(); ++it) {
00225         unsigned short fedID = fed_ids[it];     
00226         if(fedID < siStripFedIdMin ||  fedID > siStripFedIdMax) continue;
00227         if ((*iv) == fedID) {
00228           fedid_found = true;
00229           iPos->second.ConnectedFeds++;
00230           break;
00231         }
00232       }
00233       if (!fedid_found) findExcludedModule((*iv));   
00234     }
00235     int nFedsConnected   = iPos->second.ConnectedFeds;
00236     int nFedSubDet       = subdetIds.size();
00237     if (nFedSubDet > 0) {
00238       iPos->second.DaqFractionME->Reset();
00239       iPos->second.DaqFractionME->Fill(nFedsConnected*1.0/nFedSubDet);
00240     }
00241   }
00242 }
00243 //
00244 // -- find Excluded Modules
00245 //
00246 void SiStripDaqInfo::findExcludedModule(unsigned short fed_id) {
00247   dqmStore_->cd();
00248   std::string mdir = "MechanicalView";
00249   if (!SiStripUtility::goToDir(dqmStore_, mdir)) {
00250     dqmStore_->setCurrentFolder("SiStrip/"+mdir);
00251   }
00252   std::string mechanical_dir = dqmStore_->pwd();
00253   const std::vector<FedChannelConnection> fedChannels = fedCabling_->connections(fed_id);
00254   int ichannel = 0;
00255   std::string tag = "ExcludedFedChannel";
00256   std::string bad_module_folder;
00257   for (std::vector<FedChannelConnection>::const_iterator iconn = fedChannels.begin(); 
00258                                                          iconn < fedChannels.end(); iconn++){
00259     if (!iconn->isConnected()) continue;
00260     uint32_t detId = iconn->detId();
00261     if (detId == 0 || detId == 0xFFFFFFFF)  continue;
00262     
00263     ichannel++;
00264     if (ichannel == 1) {
00265       std::string subdet_folder ;
00266       SiStripFolderOrganizer folder_organizer;
00267       folder_organizer.getSubDetFolder(detId,subdet_folder);
00268       if (!dqmStore_->dirExists(subdet_folder)) {
00269         subdet_folder = mechanical_dir + subdet_folder.substr(subdet_folder.find(mdir)+mdir.size());
00270       }
00271       bad_module_folder = subdet_folder + "/" + "BadModuleList";
00272       dqmStore_->setCurrentFolder(bad_module_folder);    
00273     }
00274     std::ostringstream detid_str;
00275     detid_str << detId;
00276     std::string full_path = bad_module_folder + "/" + detid_str.str();
00277     MonitorElement* me = dqmStore_->get(full_path);
00278     uint16_t flag = 0; 
00279     if (me) {
00280       flag = me->getIntValue();
00281       me->Reset();
00282     } else me = dqmStore_->bookInt(detid_str.str());
00283     SiStripUtility::setBadModuleFlag(tag, flag);
00284     me->Fill(flag);
00285   }
00286   dqmStore_->cd();
00287 }
00288 #include "FWCore/Framework/interface/MakerMacros.h"
00289 DEFINE_FWK_MODULE(SiStripDaqInfo);