CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DQMOffline/CalibTracker/interface/SiStripBaseServiceFromDQM.h

Go to the documentation of this file.
00001 #ifndef DQMOffline_SiStripBaseServiceFromDQM_SiStripBaseServiceFromDQM_H
00002 #define DQMOffline_SiStripBaseServiceFromDQM_SiStripBaseServiceFromDQM_H
00003 
00004 #include "FWCore/Framework/interface/Frameworkfwd.h"
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "DQMServices/Core/interface/DQMStore.h"
00007 #include "CondTools/SiStrip/interface/SiStripCondObjBuilderBase.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 
00012 #include "TH1.h"
00013 
00014 #include <string>
00015 #include <memory>
00016 #include <sstream>
00017 #include <algorithm>
00018 #include <boost/lexical_cast.hpp>
00019 #include <boost/shared_ptr.hpp>
00020 
00021 
00022 
00029 template <class T>
00030 class SiStripBaseServiceFromDQM : public SiStripCondObjBuilderBase<T>
00031 {
00032  public:
00033 
00034   explicit SiStripBaseServiceFromDQM(const edm::ParameterSet&);
00035   virtual ~SiStripBaseServiceFromDQM();
00036 
00038   virtual void getMetaDataString(std::stringstream& ss);
00040   virtual bool checkForCompatibility(std::string ss);
00041 
00042  protected:
00043 
00045   void openRequestedFile();
00047   bool goToDir(const std::string & name);
00049   void getModuleFolderList(std::vector<std::string>& mfolders);
00051   uint32_t getRunNumber() const;
00058   MonitorElement * getModuleHistogram(const uint32_t detId, const std::string & name);
00059 
00060   DQMStore* dqmStore_;
00061   edm::ParameterSet iConfig_;
00062   boost::shared_ptr<SiStripFolderOrganizer> folderOrganizer_;
00063 
00064   // Simple functor to remove unneeded ME
00065   struct StringNotMatch
00066   {
00067     StringNotMatch(const std::string & name) :
00068       name_(name)
00069     {
00070     }
00071     bool operator()(const MonitorElement * ME) const
00072     {
00073       return( ME->getName().find(name_) == std::string::npos );
00074     }
00075   protected:
00076     std::string name_;
00077   };
00078 
00079 };
00080 
00081 template <class T>
00082 SiStripBaseServiceFromDQM<T>::SiStripBaseServiceFromDQM(const edm::ParameterSet& iConfig):
00083   SiStripCondObjBuilderBase<T>::SiStripCondObjBuilderBase(iConfig),
00084   iConfig_(iConfig),
00085   folderOrganizer_(boost::shared_ptr<SiStripFolderOrganizer>(new SiStripFolderOrganizer))
00086 {
00087   // Needed because this is a template inheriting from another template, so it cannot
00088   // access directly unnamed (independent from the template parameters) members.
00089   this->obj_ = 0;
00090 }
00091 
00092 template <class T>
00093 SiStripBaseServiceFromDQM<T>::~SiStripBaseServiceFromDQM()
00094 {
00095 }
00096 
00097 template <class T>
00098 void SiStripBaseServiceFromDQM<T>::openRequestedFile()
00099 {
00100   dqmStore_ = edm::Service<DQMStore>().operator->();
00101 
00102   // ** FIXME ** // 
00103   dqmStore_->setVerbose(0); //add config param
00104 
00105   if( iConfig_.getParameter<bool>("accessDQMFile") ){
00106     
00107     std::string fileName = iConfig_.getUntrackedParameter<std::string>("FILE_NAME","");
00108     
00109     edm::LogInfo("SiStripBaseServiceFromDQM") <<  "[SiStripBaseServiceFromDQM::openRequestedFile] Accessing root File" << fileName;
00110 
00111     dqmStore_->open(fileName, false); 
00112   } else {
00113     edm::LogInfo("SiStripBaseServiceFromDQM") <<  "[SiStripBaseServiceFromDQM::openRequestedFile] Accessing dqmStore stream in Online Operation";
00114   }
00115 }
00116 
00117 template <class T>
00118 bool SiStripBaseServiceFromDQM<T>::goToDir(const std::string & name)
00119 {
00120   std::string currDir = dqmStore_->pwd();
00121   std::string dirName = currDir.substr(currDir.find_last_of("/")+1);
00122   // Protection vs directories written with a trailing "/"
00123   if( dirName.length() == 0 ) {
00124     std::string currDirCopy(currDir, 0, currDir.length()-1);
00125     dirName = currDirCopy.substr(currDirCopy.find_last_of("/")+1);
00126   }
00127   if (dirName.find(name) == 0) {
00128     return true;
00129   }
00130   std::vector<std::string> subDirVec = dqmStore_->getSubdirs();
00131   for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
00132        ic != subDirVec.end(); ic++) {
00133     dqmStore_->cd(*ic);
00134     if (!goToDir(name))  dqmStore_->goUp();
00135     else return true;
00136   }
00137   return false;
00138 }
00139 
00140 template <class T>
00141 void SiStripBaseServiceFromDQM<T>::getModuleFolderList(std::vector<std::string>& mfolders)
00142 {
00143   std::string currDir = dqmStore_->pwd();
00144   if (currDir.find("module_") != std::string::npos)  {
00145     //    std::string mId = currDir.substr(currDir.find("module_")+7, 9);
00146     mfolders.push_back(currDir);
00147   } else {
00148     std::vector<std::string> subdirs = dqmStore_->getSubdirs();
00149     for( std::vector<std::string>::const_iterator it = subdirs.begin();
00150          it != subdirs.end(); ++it) {
00151       dqmStore_->cd(*it);
00152       getModuleFolderList(mfolders);
00153       dqmStore_->goUp();
00154     }
00155   }
00156 }
00157 
00158 // template <class T>
00159 // MonitorElement * SiStripBaseServiceFromDQM<T>::getModuleHistogram(const uint32_t detId, const std::string & name)
00160 // {
00161 //   // Take the full path to the histogram
00162 //   std::string path;
00163 //   folderOrganizer_->getFolderName(detId, path);
00164 //   std::cout << "path = " << path << std::endl;
00165 //   // build the name of the histogram
00166 //   std::cout << "pwd = " << dqmStore_->pwd() << std::endl;
00167 //   // std::string fullName(dqmStore_->pwd()+"/"+path+"/"+name+"__det__");
00168 //   std::string fullName(path+"/"+name+"__det__");
00169 //   fullName += boost::lexical_cast<std::string>(detId);
00170 
00171 //   // ATTENTION: fixing the problem in the folderOrganizer
00172 //   size_t firstSlash = fullName.find_first_of("/");
00173 //   fullName = fullName.substr(firstSlash, fullName.size());
00174 //   // fullName = dqmStore_->pwd() + "/SiStrip/Run summary" + fullName;
00175 //   fullName = "SiStrip/Run summary" + fullName;
00176 
00177 //   std::cout << "fullName = " << fullName << std::endl;
00178 
00179 //   return dqmStore_->get(fullName);
00180 // }
00181 
00182 template <class T>
00183 uint32_t SiStripBaseServiceFromDQM<T>::getRunNumber() const
00184 {
00185   edm::LogInfo("SiStripBaseServiceFromDQM") <<  "[SiStripBaseServiceFromDQM::getRunNumber] " << iConfig_.getParameter<uint32_t>("RunNb");
00186   return iConfig_.getParameter<uint32_t>("RunNb");
00187 }
00188 
00189 template <class T>
00190 void SiStripBaseServiceFromDQM<T>::getMetaDataString(std::stringstream& ss)
00191 {
00192   std::cout << "SiStripPedestalsDQMService::getMetaDataString" << std::endl;
00193   ss << "Run " << getRunNumber() << std::endl;
00194 }
00195 
00196 template <class T>
00197 bool SiStripBaseServiceFromDQM<T>::checkForCompatibility(std::string ss)
00198 {
00199   std::stringstream localString;
00200   getMetaDataString(localString);
00201   if( ss == localString.str() ) return false;
00202 
00203   return true;
00204 }
00205 
00206 #endif //DQMOffline_SiStripBaseServiceFromDQM_SiStripBaseServiceFromDQM_H