CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQM/SiStripHistoricInfoClient/bin/WebTrackingHDQMInspector.cc

Go to the documentation of this file.
00001 #include "DQMServices/Diagnostic/interface/HDQMInspector.h"
00002 #include "DQM/SiStripHistoricInfoClient/interface/HDQMInspectorConfigTracking.h"
00003 #include "DQMServices/Diagnostic/interface/DQMHistoryTrendsConfig.h"
00004 #include "DQMServices/Diagnostic/interface/DQMHistoryCreateTrend.h"
00005 #include <string>
00006 #include <fstream>
00007 #include <map>
00008 #include <boost/algorithm/string.hpp>
00009 #include <vector>
00010 #include <sstream>
00011 #include <fstream>
00012 #include <iostream>
00013 #include "FWCore/FWLite/interface/AutoLibraryLoader.h"
00014 #include <TROOT.h>
00015 #include <TFile.h>
00016 #include <TSystem.h>
00017 
00018 using namespace std;
00019 
00027 //struct for holding the data for super imposed plots
00028 struct plotData
00029 {
00030   plotData(const std::string & data)
00031   {
00032     std::vector<std::string> strs;
00033     boost::split(strs,data, boost::is_any_of(" "));
00034     names = strs[0];
00035     fill(strs[1], logY);
00036     fill(strs[2], firstRun);
00037     fill(strs[3], lastRun);
00038     fill(strs[5], minY);
00039     fill(strs[6], maxY);
00040     //fill(strs[8], condition);
00041     //fill(strs[7], runsQuality);
00042     
00043   }
00044  
00045 plotData()
00046 {}
00047 
00048   template<typename T>
00049   void fill(const std::string & value, T & var)
00050   {
00051     std::stringstream ss;
00052     ss << value;
00053     ss >> var;
00054   }
00055 
00056   std::string names;
00057   int firstRun;
00058   int lastRun;
00059   double minY;
00060   double maxY;
00061   int logY;
00062   string condition;
00063  // int runsQuality;
00064         
00065 };
00066 
00067 
00068 std::string concatNames(const string & line)
00069 {
00070   std::vector<std::string> nameVector;
00071   std::string concatValues="";
00072   boost::split(nameVector,line, boost::is_any_of(",@"));
00073   int time=0;   
00074   for (unsigned int i=0;i<nameVector.size();i++)
00075   {
00076     if (time==1)
00077     {   
00078       concatValues+=","+nameVector[i];
00079       time++;
00080     }
00081     else if (time==2)
00082     {
00083       concatValues+=nameVector[i];
00084       time=0;
00085     }
00086     else
00087     {
00088       time++;
00089     }
00090         
00091                 
00092   }
00093   return concatValues;
00094 }
00095 
00096 void runInspector( const string & dbName, const string &tagName, const string & Password, const string & whiteListFile,const string & selectedTrends, const int Start, const int End , const string &CondList = "")
00097 {
00098   // IMPORTANT SETTINGS:
00099   // string siStripTracker = "268435456";
00100   // string condition = siStripTracker+"@Chi2oNDF_GenTk@entries > 100";  // Use for collision data
00101   string condition = "";  // Use for collision data
00102   string blackList = "";
00103   // -------------------
00104 
00105   HDQMInspectorConfigTracking trackingConfig;
00106   // Select quantities you want the integral of
00107   vector<string> ItemsForIntegration;
00108   ItemsForIntegration.push_back("Chi2oNDF_GenTk_entries");
00109   ItemsForIntegration.push_back("NumberOfTracks_GenTk_entries");
00110   trackingConfig.computeIntegralList(ItemsForIntegration);
00111   // Create the functor
00112   DQMHistoryCreateTrend makeTrend(&trackingConfig);
00113 
00114   // Database and output configuration
00115   makeTrend.setDB(dbName,tagName,"/afs/cern.ch/cms/DB/conddb");
00116   // makeTrend.setDB(dbName,tagName,"cms_dqm_31x_offline", Password,"");
00117   makeTrend.setDebug(1);
00118   makeTrend.setDoStat(1);
00119   makeTrend.setSkip99s(true);
00120   makeTrend.setBlackList(blackList);
00121   makeTrend.setWhiteListFromFile(whiteListFile);
00122 
00123   // Definition of trends
00124   typedef DQMHistoryTrendsConfig Trend;
00125   vector<Trend> config;
00126 
00127 
00128 
00129   std::string trendsFileName(selectedTrends);
00130   std::ifstream trendsFile;
00131   trendsFile.open(trendsFileName.c_str());
00132   if( !trendsFile ) {
00133     std::cout << "Error: trends configuration file: " << trendsFileName << " not found" << std::endl;
00134     exit(1);
00135   }
00136 
00137   //Creating condition string
00138   if ( CondList != "" ){
00139     std::ifstream condFile;
00140     condFile.open(CondList.c_str());
00141     if ( condFile ){
00142       //Read the file
00143       bool first = true;
00144       while (!condFile.eof()){
00145         std::string line;
00146         getline(condFile, line);
00147         if ( line != ""){
00148           if (!first)
00149             condition+= " && ";
00150           else 
00151             first = false;
00152           condition+= line;
00153         }
00154       }
00155       cout << condition << endl; 
00156     }
00157     else
00158       std::cout << "Warning: File " << CondList << " not found : conditions will not be used" << std::endl; 
00159   }
00160 
00161   
00162   
00163   std::string configLine;
00164 
00165   typedef std::map<std::string,plotData> trendsMap;
00166   //map for holding the super imposed plots
00167   std::map<std::string,plotData> superImposedtrendsMap;
00168   //vector for holding the normal plots
00169   std::vector<plotData> trendsVector;
00170   //iterator for Map
00171   typedef std::map<std::string,plotData>::iterator trendsMapIter;
00172 
00173 
00174   while( !trendsFile.eof() ) 
00175   {
00176     std::string line;
00177     getline(trendsFile, line);
00178     if( line != "" ) 
00179     {
00180       std::vector<std::string> strs;
00181       boost::split(strs, line, boost::is_any_of(" "));
00182         
00183                 
00184      if( strs.size() == 8 ) 
00185      {
00186        //Tracker name                   
00187        std::string index=strs[4];       
00188        plotData plot(line);     
00189        if (index=="0")
00190          trendsVector.push_back(plot);
00191        else
00192        {
00193          pair<trendsMapIter, bool> insertResult = superImposedtrendsMap.insert(std::make_pair(index,plot));
00194          if(!insertResult.second) 
00195          {
00196            std::string newName=strs[0];
00197            superImposedtrendsMap[index].names += "," + newName;
00198          }
00199        }                
00200      }//if
00201      else 
00202      {
00203        std::cout << "Warning: trend configuration line: " << line << " is not formatted correctly. It will be skipped." << std::endl;
00204      }//else
00205         
00206     } //if
00207   } //while
00208 
00209   //creating super imposed plots
00210   for(map<std::string,plotData>::const_iterator it = superImposedtrendsMap.begin(); it != superImposedtrendsMap.end(); ++it)
00211   {
00212     plotData plot=it->second;
00213     if (plot.maxY<plot.minY)
00214     {
00215       plot.minY=0;              
00216       plot.maxY=100;
00217     }
00218     //pushing back the superimposed plots into the vector 
00219     config.push_back(Trend(plot.names, plot.names+".gif",plot.logY, condition, plot.names, plot.firstRun,plot.lastRun,0,plot.minY,plot.maxY));
00220   }  
00221   //creating normal plots 
00222   for (unsigned int i=0; i<trendsVector.size();i++)
00223   {
00224     plotData plot=trendsVector[i];
00225     printf("New Trend:\n%s %d %d %d %d %f %f\n",plot.names.c_str(),plot.logY, plot.firstRun,plot.lastRun,0,plot.minY,plot.maxY);
00226     config.push_back(Trend(plot.names, plot.names+".gif",plot.logY, condition, plot.names, plot.firstRun,plot.lastRun,0,plot.minY,plot.maxY));
00227   }    
00228 
00229   cout << "Test Web: Trends created. " << endl;
00230   // Creation of trend
00231   for_each(config.begin(), config.end(), makeTrend);
00232   cout << "Test Web: Trends maded" << endl;
00233   // Close the output file
00234   makeTrend.closeFile();
00235 }
00236 
00237 
00238 
00239 int main (int argc, char* argv[])
00240 {
00241   // load framework libraries
00242   gSystem->Load( "libFWCoreFWLite" );
00243   AutoLibraryLoader::enable();
00244 
00245   if (argc < 9) {
00246     std::cerr << argv[0] << " [Database] [TagName] [Password] [WhiteListFile] [SelectedTrends] [FirstRun] [LastRun] [CondList]" << std::endl;
00247   return 1;
00248   }
00249 
00250   std::cout << "Creating trends for range:  " << argv[6] << " " << argv[7] << " for tag: " << argv[1] << std::endl;
00251   runInspector( argv[1], argv[2], argv[3], argv[4], argv[5], atoi(argv[6]), atoi(argv[7]), argv[8] );
00252   return 0;
00253 }