CMS 3D CMS Logo

DQMSourceExample.cc

Go to the documentation of this file.
00001 /*
00002  * \file DQMSourceExample.cc
00003  * \author C.Leonidopoulos
00004  * Last Update:
00005  * $Date: 2008/03/28 15:53:38 $
00006  * $Revision: 1.15 $
00007  * $Author: lat $
00008  *
00009  * Description: Simple example showing how to create a DQM Source creating and filling
00010  * monitoring elements
00011 */
00012 
00013 #include "DQMServices/Examples/interface/DQMSourceExample.h"
00014 
00015 #include "FWCore/ServiceRegistry/interface/Service.h"
00016 
00017 #include "TRandom.h" // this is just the random number generator
00018 #include <math.h>
00019 
00020 using namespace std;
00021 using namespace edm;
00022 
00023 //
00024 // constructors and destructor
00025 //
00026 DQMSourceExample::DQMSourceExample( const edm::ParameterSet& ps ) :
00027 counterEvt_(0)
00028 {
00029      dbe_ = Service<DQMStore>().operator->();
00030      parameters_ = ps;
00031      monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","YourSubsystemName");
00032      cout << "Monitor name = " << monitorName_ << endl;
00033      if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
00034      prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00035      cout << "===>DQM event prescale = " << prescaleEvt_ << " events "<< endl;
00036  
00038 //   dbe_->readReferenceME("DQM_referenceME_R000000001.root");
00039 //   dbe_->open("DQM_referenceME_R000000001.root",false,"","prep");
00040 
00042 //  dbe_->open("../test/DQM_YourSubsystemName_R000000002.root");
00043 //  dbe_->open("../test/DQM_YourSubsystemName_R000000003.root");
00044 
00048 
00049 //  dbe_->open("Ecal_000017224.root",true,"","Run017224");
00050 
00052 //  cout << dbe_->getFileReleaseVersion("ref_test.root") << endl;
00053 
00055   const int NBINS = 50; XMIN = 0; XMAX = 50;
00056   
00057   
00058   rooth1 = new TH1F("rooth1","rooth1",NBINS,XMIN,XMAX);
00059   rooth1->GetXaxis()->SetTitle("X axis title");
00060   rooth1->GetYaxis()->SetTitle("Y axis title");
00061 
00062   // create and cd into new folder
00063   dbe_->setCurrentFolder(monitorName_+"C1");
00064   h1 = dbe_->book1D("histo", "Example 1D histogram.", NBINS, XMIN, XMAX);
00065   h1->setAxisTitle("x-axis title", 1);
00066   h1->setAxisTitle("y-axis title", 2);
00067   h2 = dbe_->book2D("histo2", "Example 2 2D histogram.", NBINS, XMIN, XMAX, 
00068                    NBINS, XMIN, XMAX);
00069   p1 = dbe_->bookProfile("prof1","my profile",NBINS,XMIN,XMAX,NBINS,XMIN,XMAX,"");
00070   // create and cd into new folder
00071   dbe_->setCurrentFolder(monitorName_+"C1/C2");
00072   h3 = dbe_->book1D("histo3", "Example 3 1D histogram.", NBINS, XMIN, XMAX);
00073   h4 = dbe_->book1D("histo4", "Example 4 1D histogram.", NBINS, XMIN, XMAX);
00074   h5 = dbe_->book1D("histo5", "Example 5 1D histogram.", NBINS, XMIN, XMAX);
00075   h6 = dbe_->book1D("histo6", "Example 6 1D histogram.", NBINS, XMIN, XMAX);
00076   // create and cd into new folder
00077   dbe_->setCurrentFolder(monitorName_+"C1/C3");
00078   const int NBINS2 = 10;
00079   h7 = dbe_->book1D("histo7", "Example 7 1D histogram.", NBINS2, XMIN, XMAX);
00080   char temp[1024];
00081   for(int i = 1; i <= NBINS2; ++i)
00082     {
00083       sprintf(temp, " bin no. %d", i);
00084       h7->setBinLabel(i, temp);
00085     }
00086   i1 = dbe_->bookInt("int1");
00087   f1 = dbe_->bookFloat("float1");
00088   s1 = dbe_->bookString("s1", "my string");
00089 
00090   h2->setAxisTitle("Customized x-axis", 1);
00091   h2->setAxisTitle("Customized y-axis", 2);
00092 
00093   // assign tag to MEs h1, h2 and h7
00094   const unsigned int detector_id = 17;
00095   dbe_->tag(h1, detector_id);
00096   dbe_->tag(h2, detector_id);
00097   dbe_->tag(h7, detector_id);
00098   // tag full directory
00099   dbe_->tagContents(monitorName_+"C1/C3", detector_id);
00100 
00101   // assign tag to MEs h4 and h6
00102   const unsigned int detector_id2 = 25;
00103   const unsigned int detector_id3 = 50;
00104   dbe_->tag(h4, detector_id2);
00105   dbe_->tag(h6, detector_id3);
00106 
00107   // contents of h5 & h6 will be reset at end of monitoring cycle
00108   h5->setResetMe(true);
00109   h6->setResetMe(true);
00110   dbe_->showDirStructure();
00111   std::vector<std::string> tags;
00112   dbe_->getAllTags(tags);
00113   for (size_t i = 0, e = tags.size(); i < e; ++i)
00114     std::cout << "TAGS [" << i << "] = " << tags[i] << std::endl;
00115 
00117 //  cout << (dbe_->makeReferenceME(h1)?1:0) << endl;
00118 //  MonitorElement* rh1 = dbe_->getReferenceME(h1);
00119 //  cout << rh1->getPathname() << endl;
00120 //  dbe_->deleteME(rh1);
00121 //  cout << h1->getPathname() << endl;
00122 //  cout << (dbe_->isReferenceME(h2)?1:0) << endl;
00123 //  cout << (dbe_->makeReferenceME(h2)?1:0) << endl;
00124 //  MonitorElement* rh2 = dbe_->getReferenceME(h2);
00125 //  cout << (dbe_->isReferenceME(rh2)?1:0) << endl;
00126 //  cout << (dbe_->isReferenceME(h2)?1:0) << endl;
00127 //  dbe_->deleteME(h2);
00128 //  dbe_->deleteME(f1);
00129 //  dbe_->showDirStructure();
00130 }
00131 
00132 
00133 DQMSourceExample::~DQMSourceExample()
00134 {
00135    
00136    // do anything here that needs to be done at desctruction time
00137    // (e.g. close files, deallocate resources etc.)
00138   
00139 }
00140 
00141 
00142 //--------------------------------------------------------
00143 void DQMSourceExample::beginJob(const EventSetup& context){
00144 
00145 }
00146 
00147 //--------------------------------------------------------
00148 void DQMSourceExample::beginRun(const edm::Run& r, const EventSetup& context) {
00149 
00150 }
00151 
00152 //--------------------------------------------------------
00153 void DQMSourceExample::beginLuminosityBlock(const LuminosityBlock& lumiSeg, 
00154      const EventSetup& context) {
00155   
00156 }
00157 
00158 // ----------------------------------------------------------
00159 void DQMSourceExample::analyze(const Event& iEvent, 
00160                                const EventSetup& iSetup )
00161 {  
00162   counterEvt_++;
00163   if (prescaleEvt_ > 0 && counterEvt_%prescaleEvt_!=0) return;
00164   // cout << " processing conterEvt_: " << counterEvt_ <<endl;
00165   
00166   i1->Fill(4);
00167   f1->Fill(-3.14);
00168  
00169    // Filling the histogram with random data
00170   srand( 0 );
00171 
00172   if(counterEvt_%1000 == 0)
00173     cout << " # of events = " << counterEvt_ << endl;
00174 
00175   for(int i = 0; i != 20; ++i ) 
00176     {
00177       float x = gRandom->Uniform(XMAX);
00178       h1->Fill(x,1./log(x+1));
00179       rooth1->Fill(x,1./log(x+1));
00180       h3->Fill(x, 1);
00181       h4->Fill(gRandom->Gaus(30, 3), 1.0);
00182       h5->Fill(gRandom->Poisson(15), 0.5);
00183       h6->Fill(gRandom->Gaus(25, 15), 1.0);
00184       h7->Fill(gRandom->Gaus(25, 8), 1.0);
00185     }
00186 
00187   // fit h4 to gaussian, this should not be done in the source
00188   /*MonitorElementT<TNamed>* ob = dynamic_cast<MonitorElementT<TNamed>*> (h4);
00189   if(ob)
00190     {
00191       TH1F * root_ob = dynamic_cast<TH1F *> (ob->operator->());
00192       if(root_ob)root_ob->Fit("gaus");
00193     }*/
00194   
00195   for ( int i = 0; i != 10; ++i ) 
00196     {
00197       float x = gRandom->Gaus(15, 7);
00198       float y = gRandom->Gaus(20, 5);
00199       h2->Fill(x,y);
00200       p1->Fill(x,y);
00201     }
00202   //      (*(*i1))++;
00203   usleep(100);
00204 
00205 }
00206 
00207 
00208 
00209 
00210 //--------------------------------------------------------
00211 void DQMSourceExample::endLuminosityBlock(const LuminosityBlock& lumiSeg, 
00212                                           const EventSetup& context) {
00213 }
00214 //--------------------------------------------------------
00215 void DQMSourceExample::endRun(const Run& r, const EventSetup& context){
00216 
00217   
00218   dbe_->setCurrentFolder(monitorName_+"C1");
00219   // dbe_->clone1D("cloneh1",rooth1);
00220 
00221 }
00222 //--------------------------------------------------------
00223 void DQMSourceExample::endJob(){
00224 }
00225 
00226 

Generated on Tue Jun 9 17:34:15 2009 for CMSSW by  doxygen 1.5.4