CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMHistoryServiceBase.cc
Go to the documentation of this file.
5 #include <string>
6 #include <sstream>
7 #include <cctype>
8 #include <time.h>
9 #include <boost/cstdint.hpp>
10 #include <boost/regex.hpp>
11 
13  iConfig_(iConfig),
14  fSep("@")
15 {
16  edm::LogInfo("DQMHistoryServiceBase") << "[DQMHistoryServiceBase::DQMHistoryServiceBase]";
17 }
18 
19 
21  edm::LogInfo("DQMHistoryServiceBase") << "[DQMHistoryServiceBase::~DQMHistoryServiceBase]";
22 }
23 
25  edm::LogInfo("DQMHistoryServiceBase") << "[DQMHistoryServiceBase::initialize]";
26  fitME = new HDQMfitUtilities();
27 }
28 
30  fSep = in;
31  return;
32 }
33 
35  edm::LogInfo("DQMHistoryServiceBase") << "[DQMHistoryServiceBase::checkForCompatibility]";
36  if(ss=="")
37  return true;
38 
39  uint32_t previousRun=atoi(ss.substr(ss.find("Run ")+4).c_str());
40 
41  edm::LogInfo("DQMHistoryServiceBase") << "[DQMHistoryServiceBase::checkForCompatibility] extracted string " << previousRun ;
42  return previousRun<getRunNumber();
43 }
44 
46 
47  //LOOP OVER THE LIST OF SUMMARY OBJECTS TO INSERT IN DB
48 
49  obj_=new HDQMSummary();
50 
52 
53  // DISCOVER SET OF HISTOGRAMS & QUANTITIES TO BE UPLOADED
54  std::vector<std::string> userDBContent;
55  typedef std::vector<edm::ParameterSet> VParameters;
56  VParameters histoList = iConfig_.getParameter<VParameters>("histoList");
57  VParameters::iterator ithistoList = histoList.begin();
58  VParameters::iterator ithistoListEnd = histoList.end();
59 
60  for(; ithistoList != ithistoListEnd; ++ithistoList ) {
61  std::string keyName = ithistoList->getUntrackedParameter<std::string>("keyName");
62  std::vector<std::string> Quantities = ithistoList->getUntrackedParameter<std::vector<std::string> >("quantitiesToExtract");
63  for (size_t i=0;i<Quantities.size();++i){
64 
65  if ( Quantities[i] == "landau" )
66  setDBLabelsForLandau(keyName, userDBContent);
67  else if ( Quantities[i] == "gauss" )
68  setDBLabelsForGauss(keyName, userDBContent);
69  else if ( Quantities[i] == "stat" )
70  setDBLabelsForStat(keyName, userDBContent);
71  else
72  setDBLabelsForUser(keyName, userDBContent, Quantities[i]);
73  }
74  }
75  obj_->setUserDBContent(userDBContent);
76 
77  std::stringstream ss;
78  ss << "[DQMHistoryServiceBase::scanTreeAndFillSummary] QUANTITIES TO BE INSERTED IN DB :" << std::endl;
79  std::vector<std::string> userDBContentA = obj_->getUserDBContent();
80  for (size_t i=0;i<userDBContentA.size();++i){
81  ss << userDBContentA[i]<< std::endl;
82  }
83  edm::LogInfo("HDQMSummary") << ss.str();
84 
85  // OPEN DQM FILE
87  const std::vector<MonitorElement*>& MEs = dqmStore_->getAllContents(iConfig_.getUntrackedParameter<std::string>("ME_DIR","DQMData"));
88 
89  // FILL SUMMARY
90  edm::LogInfo("HDQMSummary") << "\nSTARTING TO FILL OBJECT " << std::endl;
91  ithistoList = histoList.begin();
92  for(; ithistoList != ithistoListEnd; ++ithistoList ) {
93  std::string keyName = ithistoList->getUntrackedParameter<std::string>("keyName");
94  std::vector<std::string> Quantities = ithistoList->getUntrackedParameter<std::vector<std::string> >("quantitiesToExtract");
95  scanTreeAndFillSummary(MEs, obj_, keyName, Quantities);
96  }
97 }
98 
100 
102 
103  if( iConfig_.getParameter<bool>("accessDQMFile") ){
104 
106 
107  edm::LogInfo("DQMHistoryServiceBase") << "[DQMHistoryServiceBase::openRequestedFile] Accessing root File" << fileName;
108 
109  dqmStore_->open(fileName, false);
110  } else {
111  edm::LogInfo("DQMHistoryServiceBase") << "[DQMHistoryServiceBase::openRequestedFile] Accessing dqmStore stream in Online Operation";
112  }
113 }
114 
115 
116 void DQMHistoryServiceBase::scanTreeAndFillSummary(const std::vector<MonitorElement*>& MEs,HDQMSummary* summary,std::string& keyName, std::vector<std::string>& Quantities){
117  //
118  // -- Scan full root file and fill module numbers and histograms
119  //
120  //-----------------------------------------------------------------------------------------------
121 
122  edm::LogInfo("DQMHistoryServiceBase") << "[DQMHistoryServiceBase::scanTreeAndFillSummary] keyName " << keyName;
123 
124  std::vector<MonitorElement*>::const_iterator iterMes = MEs.begin();
125  std::vector<MonitorElement*>::const_iterator iterMesEnd = MEs.end();
126  std::stringstream ss;
127 
128  // Use boost regex for more flexibility
129  boost::regex re;
130  try {
131  re.assign(keyName);
132  }
133  catch( boost::regex_error& e ) {
134  std::cout << "Error: " << keyName << " is not a valid regular expression: \""
135  << e.what() << "\"" << std::endl;
136  std::cout << "Skip search for matches" << std::endl;
137  return;
138  }
139  for (; iterMes!=iterMesEnd; ++iterMes){
140  // Name including path
141  std::string me_name;
142  if( iConfig_.getUntrackedParameter<bool>("useFullPath", false) ) {
143  me_name = (*iterMes)->getFullname();
144  }
145  else {
146  me_name = (*iterMes)->getName();
147  // If the line does not start with a "^" add it
148  if( me_name.find("^") != 0 ) {
149  me_name = "^" + me_name;
150  }
151  }
152  // regex_search has grep-like behaviour
153  if( boost::regex_search(me_name, re) ) {
154 
156  std::vector<std::string> userDBContent;
157 
158  ss << "\nFound compatible ME " << me_name << " for key " << keyName << std::endl;
159 
160  for(size_t i=0;i<Quantities.size();++i) {
161 
162  if(Quantities[i] == "landau"){
163  setDBLabelsForLandau(keyName, userDBContent);
164  setDBValuesForLandau(iterMes,values);
165  }
166  else if(Quantities[i] == "gauss"){
167  setDBLabelsForGauss(keyName, userDBContent);
168  setDBValuesForGauss(iterMes,values);
169  }
170  else if(Quantities[i] == "stat"){
171  setDBLabelsForStat(keyName, userDBContent);
172  setDBValuesForStat(iterMes,values);
173  }
174  else{
175  setDBLabelsForUser(keyName, userDBContent,Quantities[i]);
176  setDBValuesForUser(iterMes,values,Quantities[i]);
177  }
178  }
179  uint32_t detid=returnDetComponent(*iterMes);
180 
181  ss << "detid " << detid << " \n";
182  for(size_t i=0;i<values.size();++i)
183  ss << "Quantity " << userDBContent[i] << " value " << values[i] << std::endl;
184 
185  summary->put(detid,values,userDBContent);
186  }
187  }
188  edm::LogInfo("DQMHistoryServiceBase") << "[DQMHistoryServiceBase::scanTreeAndFillSummary] " << ss.str();
189 }
190 
191 
192 bool DQMHistoryServiceBase::setDBLabelsForLandau(std::string& keyName, std::vector<std::string>& userDBContent){
193  userDBContent.push_back(keyName+fSep+std::string("landauPeak"));
194  userDBContent.push_back(keyName+fSep+std::string("landauPeakErr"));
195  userDBContent.push_back(keyName+fSep+std::string("landauSFWHM"));
196  userDBContent.push_back(keyName+fSep+std::string("landauChi2NDF"));
197  return true;
198 }
199 
200 bool DQMHistoryServiceBase::setDBLabelsForGauss(std::string& keyName, std::vector<std::string>& userDBContent){
201  userDBContent.push_back(keyName+fSep+std::string("gaussMean"));
202  userDBContent.push_back(keyName+fSep+std::string("gaussSigma"));
203  userDBContent.push_back(keyName+fSep+std::string("gaussChi2NDF"));
204  return true;
205 }
206 bool DQMHistoryServiceBase::setDBLabelsForStat(std::string& keyName, std::vector<std::string>& userDBContent){
207  userDBContent.push_back(keyName+fSep+std::string("entries"));
208  userDBContent.push_back(keyName+fSep+std::string("mean"));
209  userDBContent.push_back(keyName+fSep+std::string("rms"));
210  return true;
211 }
212 
213 bool DQMHistoryServiceBase::setDBValuesForLandau(std::vector<MonitorElement*>::const_iterator iterMes, HDQMSummary::InputVector& values){
214  fitME->doLanGaussFit(*iterMes);
215  values.push_back( fitME->getLanGaussPar("mpv") );
216  values.push_back( fitME->getLanGaussParErr("mpv") );
217  values.push_back( fitME->getLanGaussConv("fwhm") );
218  if (fitME->getFitnDof()!=0 ) values.push_back( fitME->getFitChi()/fitME->getFitnDof() );
219  else values.push_back(-99.);
220  return true;
221 }
222 
223 bool DQMHistoryServiceBase::setDBValuesForGauss(std::vector<MonitorElement*>::const_iterator iterMes, HDQMSummary::InputVector& values){
224  fitME->doGaussFit(*iterMes);
225  values.push_back( fitME->getGaussPar("mean") );
226  values.push_back( fitME->getGaussPar("sigma") );
227  if (fitME->getFitnDof()!=0 ) values.push_back( fitME->getFitChi()/fitME->getFitnDof() );
228  else values.push_back(-99.);
229  return true;
230 }
231 
232 bool DQMHistoryServiceBase::setDBValuesForStat(std::vector<MonitorElement*>::const_iterator iterMes, HDQMSummary::InputVector& values){
233  values.push_back( (*iterMes)->getEntries());
234  values.push_back( (*iterMes)->getMean());
235  values.push_back( (*iterMes)->getRMS());
236  return true;
237 }
238 
240  edm::LogInfo("DQMHistoryServiceBase") << "[DQMHistoryServiceBase::getRunNumber] " << iConfig_.getParameter<uint32_t>("RunNb");
241  return iConfig_.getParameter<uint32_t>("RunNb");
242 }
243 
virtual bool setDBValuesForGauss(std::vector< MonitorElement * >::const_iterator iterMes, HDQMSummary::InputVector &values)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual uint32_t getRunNumber() const
void setRunNr(int inputRunNr)
Definition: HDQMSummary.h:112
double getLanGaussParErr(std::string s)
bool put(const uint32_t &detID, InputVector &input, std::vector< std::string > &userContent)
Definition: HDQMSummary.cc:26
virtual bool checkForCompatibility(std::string ss)
double doGaussFit(MonitorElement *ME)
double getLanGaussConv(std::string s)
std::vector< MonitorElement * > getAllContents(const std::string &path, uint32_t runNumber=0, uint32_t lumi=0) const
Definition: DQMStore.cc:1909
virtual bool setDBValuesForUser(std::vector< MonitorElement * >::const_iterator iterMes, HDQMSummary::InputVector &values, std::string &quantity)
HDQMfitUtilities * fitME
void setUserDBContent(const std::vector< std::string > &userDBContent)
Definition: HDQMSummary.h:111
std::vector< float > InputVector
Definition: HDQMSummary.h:62
DQMHistoryServiceBase(const edm::ParameterSet &, const edm::ActivityRegistry &)
virtual bool setDBLabelsForStat(std::string &keyName, std::vector< std::string > &userDBContent)
double getLanGaussPar(std::string s)
double getGaussPar(std::string s)
edm::ParameterSet iConfig_
virtual uint32_t returnDetComponent(const MonitorElement *MEs)
virtual bool setDBLabelsForGauss(std::string &keyName, std::vector< std::string > &userDBContent)
virtual bool setDBLabelsForUser(std::string &keyName, std::vector< std::string > &userDBContent, std::string &quantity)
virtual void setSeparator(std::string const &)
virtual bool setDBLabelsForLandau(std::string &keyName, std::vector< std::string > &userDBContent)
bool open(const std::string &filename, bool overwrite=false, const std::string &path="", const std::string &prepend="", OpenRunDirs stripdirs=KeepRunDirs, bool fileMustExist=true)
Definition: DQMStore.cc:2845
tuple cout
Definition: gather_cfg.py:121
virtual void scanTreeAndFillSummary(const std::vector< MonitorElement * > &MEs, HDQMSummary *summary, std::string &histoName, std::vector< std::string > &Quantities)
virtual bool setDBValuesForLandau(std::vector< MonitorElement * >::const_iterator iterMes, HDQMSummary::InputVector &values)
std::vector< std::string > getUserDBContent() const
Definition: HDQMSummary.h:116
double doLanGaussFit(MonitorElement *ME)
virtual bool setDBValuesForStat(std::vector< MonitorElement * >::const_iterator iterMes, HDQMSummary::InputVector &values)