CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/EcalCommon/src/MESetChannel.cc

Go to the documentation of this file.
00001 #include "DQM/EcalCommon/interface/MESetChannel.h"
00002 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
00003 
00004 #include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h"
00005 
00006 #include "FWCore/Utilities/interface/Exception.h"
00007 
00008 namespace ecaldqm
00009 {
00010   MESetChannel::MESetChannel(std::string const& _fullpath, MEData const& _data, bool _readOnly/* = false*/) :
00011     MESet(_fullpath, _data, _readOnly),
00012     meTable_()
00013   {
00014   }
00015 
00016   MESetChannel::~MESetChannel()
00017   {
00018   }
00019 
00020   bool
00021   MESetChannel::retrieve() const
00022   {
00023     active_ = true;
00024     return true;
00025   }
00026 
00027   void
00028   MESetChannel::clear() const
00029   {
00030     MESet::clear();
00031     if(!readOnly_) dqmStore_->rmdir(dir_);
00032     mes_.clear();
00033     meTable_.clear();
00034   }
00035 
00036   void
00037   MESetChannel::fill(DetId const& _id, double _w/* = 1.*/, double, double)
00038   {
00039     uint32_t rawId(getIndex_(_id));
00040 
00041     std::map<uint32_t, unsigned>::iterator tableItr(meTable_.find(rawId));
00042     if(tableItr == meTable_.end()){
00043       std::string name(binService_->channelName(rawId, data_->btype));
00044       tableItr = append_(name, rawId);
00045     }
00046     if(tableItr == meTable_.end()) return;
00047 
00048     mes_.at(tableItr->second)->Fill(0.5, _w);
00049   }
00050 
00051   void
00052   MESetChannel::fill(EcalElectronicsId const& _id, double _w/* = 1.*/, double, double)
00053   {
00054     uint32_t rawId(getIndex_(_id));
00055 
00056     std::map<uint32_t, unsigned>::iterator tableItr(meTable_.find(rawId));
00057     if(tableItr == meTable_.end()){
00058       std::string name(binService_->channelName(rawId, data_->btype));
00059       tableItr = append_(name, rawId);
00060     }
00061     if(tableItr == meTable_.end()) return;
00062 
00063     mes_.at(tableItr->second)->Fill(0.5, _w);
00064   }
00065 
00066   void
00067   MESetChannel::setBinContent(DetId const& _id, double _content, double _err/* = 0.*/)
00068   {
00069     uint32_t rawId(getIndex_(_id));
00070 
00071     std::map<uint32_t, unsigned>::iterator tableItr(meTable_.find(rawId));
00072     if(tableItr == meTable_.end()){
00073       std::string name(binService_->channelName(rawId, data_->btype));
00074       tableItr = append_(name, rawId);
00075     }
00076     if(tableItr == meTable_.end()) return;
00077 
00078     mes_.at(tableItr->second)->setBinContent(1, _content);
00079     mes_.at(tableItr->second)->setBinError(1, _err);
00080   }
00081    
00082   void
00083   MESetChannel::setBinContent(EcalElectronicsId const& _id, double _content, double _err/* = 0.*/)
00084   {
00085     uint32_t rawId(getIndex_(_id));
00086 
00087     std::map<uint32_t, unsigned>::iterator tableItr(meTable_.find(rawId));
00088     if(tableItr == meTable_.end()){
00089       std::string name(binService_->channelName(rawId, data_->btype));
00090       tableItr = append_(name, rawId);
00091     }
00092     if(tableItr == meTable_.end()) return;
00093 
00094     mes_.at(tableItr->second)->setBinContent(1, _content);
00095     mes_.at(tableItr->second)->setBinError(1, _err);
00096   }
00097 
00098   void
00099   MESetChannel::reset(double _content/* = 0.*/, double _err/* = 0.*/, double _entries/* = 0.*/)
00100   {
00101     if(readOnly_) return;
00102 
00103     if(_content == 0. && _entries == 0.){
00104       mes_.clear();
00105       meTable_.clear();
00106       dqmStore_->rmdir(dir_);
00107       return;
00108     }
00109 
00110     for(unsigned iME(0); iME < mes_.size(); iME++){
00111       mes_[iME]->setBinContent(1, _content);
00112       mes_[iME]->setBinContent(1, _err);
00113       if(data_->kind == MonitorElement::DQM_KIND_TPROFILE)
00114         mes_[iME]->setBinEntries(1, _entries);
00115     }
00116   }
00117 
00118   double
00119   MESetChannel::getBinContent(DetId const& _id, int) const
00120   {
00121     uint32_t rawId(getIndex_(_id));
00122 
00123     std::map<uint32_t, unsigned>::const_iterator tableItr(meTable_.find(rawId));
00124 
00125     if(tableItr == meTable_.end()) return 0.;
00126 
00127     return mes_.at(tableItr->second)->getBinContent(1);
00128   }
00129 
00130   double
00131   MESetChannel::getBinContent(EcalElectronicsId const& _id, int) const
00132   {
00133     uint32_t rawId(getIndex_(_id));
00134 
00135     std::map<uint32_t, unsigned>::const_iterator tableItr(meTable_.find(rawId));
00136 
00137     if(tableItr == meTable_.end()) return 0.;
00138 
00139     return mes_.at(tableItr->second)->getBinContent(1);
00140   }
00141 
00142   void
00143   MESetChannel::checkDirectory() const
00144   {
00145     using namespace std;
00146 
00147     vector<MonitorElement*> storeMEs(dqmStore_->getContents(dir_));
00148     for(vector<MonitorElement*>::iterator storeItr(storeMEs.begin()); storeItr != storeMEs.end(); ++storeItr){
00149       if(find(mes_.begin(), mes_.end(), *storeItr) != mes_.end()) continue;
00150 
00151       uint32_t id(binService_->idFromName((*storeItr)->getName()));
00152       if(id != 0){
00153         mes_.push_back(*storeItr);
00154         meTable_[id] = mes_.size() - 1;
00155       }
00156     }
00157   }
00158 
00159   std::map<uint32_t, unsigned>::iterator
00160   MESetChannel::append_(std::string const& _name, uint32_t _rawId)
00161   {
00162     std::string pwd(dqmStore_->pwd());
00163     dqmStore_->setCurrentFolder(dir_);
00164 
00165     MonitorElement* me(dqmStore_->book1D(_name, _name, 1, 0., 1.));
00166 
00167     dqmStore_->setCurrentFolder(pwd);
00168 
00169     if(!me) return meTable_.end();
00170 
00171     mes_.push_back(me);
00172     std::pair<std::map<uint32_t, unsigned>::iterator, bool> ins(meTable_.insert(std::pair<uint32_t, unsigned>(_rawId, mes_.size() - 1)));
00173     
00174     return ins.first;
00175   }
00176 
00177   uint32_t
00178   MESetChannel::getIndex_(DetId const& _id) const
00179   {
00180     switch(data_->btype){
00181     case BinService::kCrystal:
00182       return getElectronicsMap()->getElectronicsId(_id).rawId();
00183     case BinService::kTriggerTower:
00184       {
00185         if(_id.subdetId() == EcalTriggerTower){
00186           EcalTrigTowerDetId ttid(_id);
00187           return EcalTriggerElectronicsId(getElectronicsMap()->TCCid(ttid), getElectronicsMap()->iTT(ttid), 1, 1).rawId();
00188         }
00189         else{
00190           EcalTriggerElectronicsId teid(getElectronicsMap()->getTriggerElectronicsId(_id));
00191           return EcalTriggerElectronicsId(teid.tccId(), teid.ttId(), 1, 1).rawId();
00192         }
00193       }
00194     case BinService::kSuperCrystal:
00195       {
00196         EcalElectronicsId eid(getElectronicsMap()->getElectronicsId(_id));
00197         return EcalElectronicsId(eid.dccId(), eid.towerId(), 1, 1).rawId();
00198       }
00199     case BinService::kTCC:
00200       {
00201         EcalTriggerElectronicsId teid(getElectronicsMap()->getTriggerElectronicsId(_id));
00202         return BinService::nDCC + teid.tccId();
00203       }
00204     case BinService::kDCC:
00205       {
00206         EcalElectronicsId eid(getElectronicsMap()->getElectronicsId(_id));
00207         return eid.dccId();
00208       }
00209     default:
00210       throw cms::Exception("InvalidConfiguration") << "MESetChannel configured with bin type " << data_->btype;
00211       return 0;
00212     }
00213   }
00214 
00215   uint32_t
00216   MESetChannel::getIndex_(EcalElectronicsId const& _id) const
00217   {
00218     switch(data_->btype){
00219     case BinService::kCrystal:
00220       return _id.rawId();
00221     case BinService::kTriggerTower:
00222       {
00223         EcalTriggerElectronicsId teid(getElectronicsMap()->getTriggerElectronicsId(_id));
00224         return EcalTriggerElectronicsId(teid.tccId(), teid.ttId(), 1, 1).rawId();
00225       }
00226     case BinService::kSuperCrystal:
00227       return EcalElectronicsId(_id.dccId(), _id.towerId(), 1, 1).rawId();
00228     case BinService::kTCC:
00229       {
00230         EcalTriggerElectronicsId teid(getElectronicsMap()->getTriggerElectronicsId(_id));
00231         return BinService::nDCC + teid.tccId();
00232       }
00233     case BinService::kDCC:
00234       return _id.dccId();
00235     default:
00236       throw cms::Exception("InvalidConfiguration") << "MESetChannel configured with bin type " << data_->btype;
00237       return 0;
00238     }
00239   }
00240 
00241 }