Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:13

0001 // Class removed until concurrency issue is finalized
0002 #if 0
0003 
0004 #include "DQM/EcalCommon/interface/MESetChannel.h"
0005 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0006 
0007 #include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h"
0008 #include "DataFormats/EcalDetId/interface/EcalPnDiodeDetId.h"
0009 
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 #include <limits>
0013 #include <iomanip>
0014 
0015 namespace ecaldqm
0016 {
0017   static const unsigned maxTableSize(100);
0018 
0019   MESetChannel::MESetChannel(std::string const& _fullPath, binning::ObjectType _otype, binning::BinningType _btype, MonitorElement::Kind _kind) :
0020     MESet(_fullPath, _otype, _btype, _kind),
0021     meTable_()
0022   {
0023     switch(kind_){
0024     case MonitorElement::Kind::TH1F:
0025     case MonitorElement::Kind::TPROFILE:
0026       break;
0027     default:
0028       throw_("Unsupported MonitorElement kind");
0029     }
0030 
0031     switch(btype_){
0032     case binning::kCrystal:
0033     case binning::kTriggerTower:
0034     case binning::kSuperCrystal:
0035     case binning::kTCC:
0036     case binning::kDCC:
0037       break;
0038     default:
0039       throw_("MESetChannel configured with wrong binning type");
0040     }
0041   }
0042 
0043   MESetChannel::MESetChannel(MESetChannel const& _orig) :
0044     MESet(_orig),
0045     meTable_(_orig.meTable_)
0046   {
0047   }
0048 
0049   MESetChannel::~MESetChannel()
0050   {
0051   }
0052 
0053   MESet&
0054   MESetChannel::operator=(MESet const& _rhs)
0055   {
0056     MESetChannel const* pRhs(dynamic_cast<MESetChannel const*>(&_rhs));
0057     if(pRhs) meTable_ = pRhs->meTable_;
0058     return MESet::operator=(_rhs);
0059   }
0060 
0061   MESet*
0062   MESetChannel::clone(std::string const& _path/* = ""*/) const
0063   {
0064     std::string path(path_);
0065     if(_path != "") path_ = _path;
0066     MESet* copy(new MESetChannel(*this));
0067     path_ = path;
0068     return copy;
0069   }
0070 
0071   void
0072   MESetChannel::book(DQMStore::IBooker&)
0073   {
0074     clear();
0075     active_ = true;
0076   }
0077 
0078   bool
0079   MESetChannel::retrieve(DQMStore::IGetter&, std::string*/* = 0*/) const
0080   {
0081     checkDirectory();
0082 
0083     active_ = true;
0084     return true;
0085   }
0086 
0087   void
0088   MESetChannel::clear() const
0089   {
0090     MESet::clear();
0091     dqmStore_->rmdir(path_.substr(0, path_.find_last_of('/')));
0092     meTable_.clear();
0093   }
0094 
0095   void
0096   MESetChannel::fill(DetId const& _id, double _w/* = 1.*/, double, double)
0097   {
0098     if(!active_) return;
0099 
0100     unsigned iME(preparePlot_(getIndex_(_id)));
0101     if(iME == unsigned(-1)) return;
0102     checkME_(iME);
0103 
0104     mes_[iME]->Fill(0.5, _w);
0105   }
0106 
0107   void
0108   MESetChannel::fill(EcalElectronicsId const& _id, double _w/* = 1.*/, double, double)
0109   {
0110     if(!active_) return;
0111 
0112     unsigned iME(preparePlot_(getIndex_(_id)));
0113     if(iME == unsigned(-1)) return;
0114     checkME_(iME);
0115 
0116     mes_[iME]->Fill(0.5, _w);
0117   }
0118 
0119   void
0120   MESetChannel::setBinContent(DetId const& _id, double _content)
0121   {
0122     if(!active_) return;
0123 
0124     unsigned iME(preparePlot_(getIndex_(_id)));
0125     if(iME == unsigned(-1)) return;
0126     checkME_(iME);
0127 
0128     mes_[iME]->setBinContent(1, _content);
0129   }
0130    
0131   void
0132   MESetChannel::setBinContent(EcalElectronicsId const& _id, double _content)
0133   {
0134     if(!active_) return;
0135 
0136     unsigned iME(preparePlot_(getIndex_(_id)));
0137     if(iME == unsigned(-1)) return;
0138     checkME_(iME);
0139 
0140     mes_[iME]->setBinContent(1, _content);
0141   }
0142 
0143   void
0144   MESetChannel::setBinError(DetId const& _id, double _error)
0145   {
0146     if(!active_) return;
0147 
0148     unsigned iME(preparePlot_(getIndex_(_id)));
0149     if(iME == unsigned(-1)) return;
0150     checkME_(iME);
0151 
0152     mes_[iME]->setBinError(1, _error);
0153   }
0154    
0155   void
0156   MESetChannel::setBinError(EcalElectronicsId const& _id, double _error)
0157   {
0158     if(!active_) return;
0159 
0160     unsigned iME(preparePlot_(getIndex_(_id)));
0161     if(iME == unsigned(-1)) return;
0162     checkME_(iME);
0163 
0164     mes_[iME]->setBinError(1, _error);
0165   }
0166 
0167   void
0168   MESetChannel::setBinEntries(DetId const& _id, double _entries)
0169   {
0170     if(!active_) return;
0171 
0172     unsigned iME(preparePlot_(getIndex_(_id)));
0173     if(iME == unsigned(-1)) return;
0174     checkME_(iME);
0175 
0176     mes_[iME]->setBinEntries(1, _entries);
0177   }
0178    
0179   void
0180   MESetChannel::setBinEntries(EcalElectronicsId const& _id, double _entries)
0181   {
0182     if(!active_) return;
0183 
0184     unsigned iME(preparePlot_(getIndex_(_id)));
0185     if(iME == unsigned(-1)) return;
0186     checkME_(iME);
0187 
0188     mes_[iME]->setBinEntries(1, _entries);
0189   }
0190 
0191   double
0192   MESetChannel::getBinContent(DetId const& _id, int) const
0193   {
0194     if(!active_) return 0.;
0195 
0196     unsigned iME(findPlot_(getIndex_(_id)));
0197     if(iME == unsigned(-1)) return 0.;
0198     checkME_(iME);
0199 
0200     return mes_[iME]->getBinContent(1);
0201   }
0202 
0203   double
0204   MESetChannel::getBinContent(EcalElectronicsId const& _id, int) const
0205   {
0206     if(!active_) return 0.;
0207 
0208     unsigned iME(findPlot_(getIndex_(_id)));
0209     if(iME == unsigned(-1)) return 0.;
0210     checkME_(iME);
0211 
0212     return mes_[iME]->getBinContent(1);
0213   }
0214 
0215   double
0216   MESetChannel::getBinError(DetId const& _id, int) const
0217   {
0218     if(!active_) return 0.;
0219 
0220     unsigned iME(findPlot_(getIndex_(_id)));
0221     if(iME == unsigned(-1)) return 0.;
0222     checkME_(iME);
0223 
0224     return mes_[iME]->getBinError(1);
0225   }
0226 
0227   double
0228   MESetChannel::getBinError(EcalElectronicsId const& _id, int) const
0229   {
0230     if(!active_) return 0.;
0231 
0232     unsigned iME(findPlot_(getIndex_(_id)));
0233     if(iME == unsigned(-1)) return 0.;
0234     checkME_(iME);
0235 
0236     return mes_[iME]->getBinError(1);
0237   }
0238 
0239   double
0240   MESetChannel::getBinEntries(DetId const& _id, int) const
0241   {
0242     if(!active_) return 0.;
0243 
0244     unsigned iME(findPlot_(getIndex_(_id)));
0245     if(iME == unsigned(-1)) return 0.;
0246     checkME_(iME);
0247 
0248     return mes_[iME]->getBinEntries(1);
0249   }
0250 
0251   double
0252   MESetChannel::getBinEntries(EcalElectronicsId const& _id, int) const
0253   {
0254     if(!active_) return 0.;
0255 
0256     unsigned iME(findPlot_(getIndex_(_id)));
0257     if(iME == unsigned(-1)) return 0.;
0258     checkME_(iME);
0259 
0260     return mes_[iME]->getBinEntries(1);
0261   }
0262 
0263   void
0264   MESetChannel::reset(double _content/* = 0.*/, double _err/* = 0.*/, double _entries/* = 0.*/)
0265   {
0266     if(!active_) return;
0267 
0268     if(_content == 0. && _entries == 0.){
0269       mes_.clear();
0270       meTable_.clear();
0271       dqmStore_->rmdir(path_);
0272       return;
0273     }
0274 
0275     unsigned nME(mes_.size());
0276     for(unsigned iME(0); iME < nME; iME++){
0277       mes_[iME]->setBinContent(1, _content);
0278       mes_[iME]->setBinError(1, _err);
0279       if(kind_ == MonitorElement::Kind::TPROFILE)
0280     mes_[iME]->setBinEntries(1, _entries);
0281     }
0282   }
0283 
0284   void
0285   MESetChannel::checkDirectory() const
0286   {
0287     using namespace std;
0288 
0289     vector<MonitorElement*> storeMEs(dqmStore_->getContents(path_));
0290 
0291     unsigned nME(storeMEs.size());
0292     for(unsigned iME(0); iME < nME; iME++){
0293       MonitorElement* me(storeMEs[iME]);
0294       if(find(mes_.begin(), mes_.end(), me) != mes_.end()) continue;
0295 
0296       uint32_t id(binning::idFromName(me->getName()));
0297       if(id != 0){
0298     mes_.push_back(me);
0299     meTable_[id] = mes_.size() - 1;
0300       }
0301     }
0302   }
0303 
0304   unsigned
0305   MESetChannel::preparePlot_(uint32_t _rawId) const
0306   {
0307     if(_rawId == 0) return -1;
0308 
0309     std::map<uint32_t, unsigned>::iterator tableItr(meTable_.find(_rawId));
0310     if(tableItr == meTable_.end()){
0311       if(meTable_.size() == maxTableSize){
0312         edm::LogWarning("EcalDQM") << "max table size";
0313         return -1;
0314       }
0315 
0316       std::string name(binning::channelName(_rawId, btype_));
0317       std::string pwd(dqmStore_->pwd());
0318       dqmStore_->setCurrentFolder(path_);
0319 
0320       MonitorElement* me(0);
0321       if(kind_ == MonitorElement::Kind::TH1F)
0322         me = dqmStore_->book1D(name, name, 1, 0., 1.);
0323       else
0324         me = dqmStore_->bookProfile(name, name, 1, 0., 1., -std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
0325 
0326       dqmStore_->setCurrentFolder(pwd);
0327 
0328       if(me){
0329         mes_.push_back(me);
0330         tableItr = meTable_.insert(std::pair<uint32_t, unsigned>(_rawId, mes_.size() - 1)).first;
0331       }
0332     }
0333     if(tableItr == meTable_.end()){
0334       edm::LogError("EcalDQM") << "insertion error";
0335       return -1;
0336     }
0337     
0338     return tableItr->second;
0339   }
0340 
0341   unsigned
0342   MESetChannel::findPlot_(uint32_t _rawId) const
0343   {
0344     if(_rawId == 0) return -1;
0345 
0346     std::map<uint32_t, unsigned>::const_iterator tableItr(meTable_.find(_rawId));
0347 
0348     if(tableItr == meTable_.end()) return -1;
0349 
0350     return tableItr->second;
0351   }
0352 
0353   uint32_t
0354   MESetChannel::getIndex_(DetId const& _id) const
0355   {
0356     int subdet(_id.subdetId());
0357 
0358     switch(btype_){
0359     case binning::kCrystal:
0360       if(isCrystalId(_id)) return getElectronicsMap()->getElectronicsId(_id).rawId();
0361       else if(_id.subdetId() == EcalLaserPnDiode){
0362         EcalPnDiodeDetId pnid(_id);
0363         return EcalElectronicsId(pnid.iDCCId(), pnid.iPnId() < 6 ? 69 : 70, 1, (pnid.iPnId() - 1) % 5 + 1).rawId();
0364       }
0365       break;
0366 
0367     case binning::kTriggerTower:
0368       if(subdet == EcalTriggerTower){
0369         std::vector<DetId> ids(getTrigTowerMap()->constituentsOf(EcalTrigTowerDetId(_id)));
0370         if(ids.size() > 0){
0371           EcalTriggerElectronicsId teid(getElectronicsMap()->getTriggerElectronicsId(ids[0]));
0372           return EcalTriggerElectronicsId(teid.tccId(), teid.ttId(), 1, 1).rawId();
0373         }
0374       }
0375       else if(isCrystalId(_id)){
0376         EcalTriggerElectronicsId teid(getElectronicsMap()->getTriggerElectronicsId(_id));
0377         return EcalTriggerElectronicsId(teid.tccId(), teid.ttId(), 1, 1).rawId();
0378       }
0379       break;
0380 
0381     case binning::kSuperCrystal:
0382       if(isCrystalId(_id)){
0383         EcalElectronicsId eid(getElectronicsMap()->getElectronicsId(_id));
0384         return EcalElectronicsId(eid.dccId(), eid.towerId(), 1, 1).rawId();
0385       }
0386       else if(isEcalScDetId(_id)){
0387         std::pair<int, int> dccsc(getElectronicsMap()->getDCCandSC(EcalScDetId(_id)));
0388         return EcalElectronicsId(dccsc.first, dccsc.second, 1, 1).rawId();
0389       }
0390       else if(subdet == EcalTriggerTower && !isEndcapTTId(_id)){
0391         std::vector<DetId> ids(getTrigTowerMap()->constituentsOf(EcalTrigTowerDetId(_id)));
0392         if(ids.size() > 0){
0393           EcalElectronicsId eid(getElectronicsMap()->getElectronicsId(ids[0]));
0394           return EcalElectronicsId(eid.dccId(), eid.towerId(), 1, 1).rawId();
0395         }
0396       }
0397       break;
0398 
0399     case binning::kTCC:
0400       return tccId(_id) + binning::nDCC;
0401 
0402     case binning::kDCC:
0403       return dccId(_id);
0404 
0405     default:
0406       break;
0407     }
0408 
0409     return 0;
0410   }
0411 
0412   uint32_t
0413   MESetChannel::getIndex_(EcalElectronicsId const& _id) const
0414   {
0415     switch(btype_){
0416     case binning::kCrystal:
0417       return _id.rawId();
0418 
0419     case binning::kTriggerTower:
0420       {
0421     EcalTriggerElectronicsId teid(getElectronicsMap()->getTriggerElectronicsId(_id));
0422     return EcalTriggerElectronicsId(teid.tccId(), teid.ttId(), 1, 1).rawId();
0423       }
0424 
0425     case binning::kSuperCrystal:
0426       return EcalElectronicsId(_id.dccId(), _id.towerId(), 1, 1).rawId();
0427 
0428     case binning::kTCC:
0429       return tccId(_id) + binning::nDCC;
0430 
0431     case binning::kDCC:
0432       return _id.dccId();
0433 
0434     default:
0435       break;
0436     }
0437 
0438     return 0;
0439   }
0440 }
0441 
0442 #endif