CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Attributes | Friends

MonitorElementsDb Class Reference

#include <MonitorElementsDb.h>

List of all members.

Public Member Functions

 MonitorElementsDb (const edm::ParameterSet &ps, std::string &xmlFile)
 Constructors.
virtual ~MonitorElementsDb ()
 Destructor.

Protected Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c, coral::ISessionProxy *s)
 Analyze.
void beginJob (void)
void endJob (void)
void htmlOutput (std::string &htmlDir)
void startSession (void)

Private Attributes

DQMStoredqmStore_
int ievt_
std::vector< DB_MEMEinfo_
std::vector< MonitorElement * > MEs_
MonitorXMLParserparser_
std::string prefixME_
std::string xmlFile_

Friends

class EcalBarrelMonitorDbModule
class EcalEndcapMonitorDbModule

Detailed Description

Definition at line 31 of file MonitorElementsDb.h.


Constructor & Destructor Documentation

MonitorElementsDb::MonitorElementsDb ( const edm::ParameterSet ps,
std::string &  xmlFile 
)

Constructors.

Definition at line 38 of file MonitorElementsDb.cc.

References DQMStore::book1D(), DQMStore::book2D(), DQMStore::bookProfile(), DQMStore::bookProfile2D(), dtNoiseDBValidation_cfg::cerr, dqmStore_, alignCSCRings::e, MonitorXMLParser::getDB_ME(), edm::ParameterSet::getUntrackedParameter(), i, MonitorXMLParser::load(), MEinfo_, MEs_, cppFunctionSkipper::operator, parser_, prefixME_, DQMStore::setCurrentFolder(), indexGen::title, tmp, fw3dlego::xbins, xmlFile(), and xmlFile_.

                                                                                   {

  xmlFile_ = xmlFile;

  dqmStore_ = edm::Service<DQMStore>().operator->();

  prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");

  if ( dqmStore_ ) {

    dqmStore_->setCurrentFolder( prefixME_ );

    parser_ = new MonitorXMLParser( xmlFile_ );
    try {
      parser_->load();
    } catch( const std::runtime_error e ) {
      std::cerr << "Error loading parser: " << e.what() << std::endl;
    }

    MEinfo_ = parser_->getDB_ME();

    for( unsigned int i=0; i< MEinfo_.size(); i++ ) {

      MonitorElement* tmp;
      tmp = 0;
      if( strcmp(MEinfo_[i].type.c_str(), "th1d") == 0 ) {
        tmp = dqmStore_->book1D( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto );
      }
      else if( strcmp(MEinfo_[i].type.c_str(), "th2d") == 0 ) {
        tmp = dqmStore_->book2D( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto,
                            MEinfo_[i].ybins, MEinfo_[i].yfrom, MEinfo_[i].yto );
      }
      else if( strcmp(MEinfo_[i].type.c_str(), "tprofile") == 0 ) {
      tmp = dqmStore_->bookProfile( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto,
                               MEinfo_[i].ybins, MEinfo_[i].yfrom, MEinfo_[i].yto );
      }
      else if( strcmp(MEinfo_[i].type.c_str(), "tprofile2d") == 0 ) {
        tmp = dqmStore_->bookProfile2D( MEinfo_[i].title, MEinfo_[i].title, MEinfo_[i].xbins, MEinfo_[i].xfrom, MEinfo_[i].xto,
                                   MEinfo_[i].ybins, MEinfo_[i].yfrom, MEinfo_[i].yto,
                                   MEinfo_[i].zbins, MEinfo_[i].zfrom, MEinfo_[i].zto );
      }

      MEs_.push_back( tmp );
    }

  }

}
MonitorElementsDb::~MonitorElementsDb ( ) [virtual]

Destructor.

Definition at line 87 of file MonitorElementsDb.cc.

                                     {

}

Member Function Documentation

void MonitorElementsDb::analyze ( const edm::Event e,
const edm::EventSetup c,
coral::ISessionProxy *  s 
) [protected]

Analyze.

Definition at line 106 of file MonitorElementsDb.cc.

References cmsCodeRulesChecker::arg, dtNoiseDBValidation_cfg::cerr, relativeConstraints::empty, exception, Exception, cmsRelvalreport::exit, i, ievt_, j, gen::k, prof2calltree::l, MEinfo_, MEs_, o2o::query, and python::IdGenerator::schema.

Referenced by EcalBarrelMonitorDbModule::analyze(), and EcalEndcapMonitorDbModule::analyze().

                                                                                                       {

  ievt_++;

  bool atLeastAQuery;
  atLeastAQuery = false;

  std::vector<std::string> vars;

  if ( session )  {

    for( unsigned int i=0; i<MEinfo_.size(); i++ ) {

      // i-th ME...

      if( MEs_[i] != 0 && ( ievt_ % MEinfo_[i].ncycle ) == 0 ) {

        MEs_[i]->Reset();

        vars.clear();

        try {

          atLeastAQuery = true;

          session->transaction().start(true);

          coral::ISchema& schema = session->nominalSchema();

          coral::IQuery* query = schema.newQuery();

          for( unsigned int j=0; j<MEinfo_[i].queries.size(); j++ ) {
            if( strcmp(MEinfo_[i].queries[j].query.c_str(), "addToTableList") == 0 ) {
              query->addToTableList( MEinfo_[i].queries[j].arg );
            }
            else if( strcmp(MEinfo_[i].queries[j].query.c_str(), "addToOutputList") == 0 ) {
              query->addToOutputList( MEinfo_[i].queries[j].arg, MEinfo_[i].queries[j].alias );
              vars.push_back( MEinfo_[i].queries[j].alias );
            }
            else if( strcmp(MEinfo_[i].queries[j].query.c_str(), "setCondition") == 0 ) {
              query->setCondition( MEinfo_[i].queries[j].arg, coral::AttributeList() );
            }
            else if( strcmp(MEinfo_[i].queries[j].query.c_str(), "addToOrderList") == 0 ) {
              query->addToOrderList( MEinfo_[i].queries[j].arg );
            }
          }

          coral::ICursor& cursor = query->execute();

          unsigned int k = 0;

          while ( cursor.next() && k < MEinfo_[i].loop ) {
            //while ( cursor.next() ) {

            const coral::AttributeList& row = cursor.currentRow();

            std::vector<float> vvars;
            vvars.clear();
            for( unsigned int l=0; l<vars.size(); l++ ) {
              if( !vars[l].empty() ) {
                vvars.push_back( row[vars[l].c_str()].data<float>() );
              }
            }
            if( vvars.size() == 2 ) {
              //std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] << std::endl;
              MEs_[i]->Fill( vvars[0], vvars[1] );
            }
            else if( vvars.size() == 3 ) {
              //std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] << " -- " << vvars[2] << std::endl;
              MEs_[i]->Fill( vvars[0], vvars[1], vvars[2] );
            }
            else if( vvars.size() == 4 ) {
              //std::cout << k << " -- " << vvars[0] << " -- " << vvars[1] << " -- " << vvars[2] << " -- " << vvars[3] << std::endl;
              MEs_[i]->Fill( vvars[0], vvars[1], vvars[2], vvars[3] );
            }
            else{
              std::cerr << "Too many variables to plot..." << std::endl;
              exit(1);
            }

            k++;

          }

          delete query;

        } catch ( coral::Exception& e ) {
          std::cerr << "CORAL Exception : " << e.what() << std::endl;
        } catch ( std::exception& e ) {
          std::cerr << "Standard C++ exception : " << e.what() << std::endl;
        } catch ( ... ) {
          std::cerr << "Exception caught (...)" << std::endl;
        }

      }

    }

    if( atLeastAQuery ) session->transaction().commit();

  }

}
void MonitorElementsDb::beginJob ( void  ) [protected]

Definition at line 91 of file MonitorElementsDb.cc.

References ievt_.

Referenced by EcalBarrelMonitorDbModule::beginJob(), and EcalEndcapMonitorDbModule::beginJob().

                                      {

  ievt_ = 0;

}
void MonitorElementsDb::endJob ( void  ) [protected]

Definition at line 97 of file MonitorElementsDb.cc.

References gather_cfg::cout, dqmStore_, edm::getName(), i, ievt_, MEs_, and DQMStore::removeElement().

Referenced by EcalEndcapMonitorDbModule::endJob(), and EcalBarrelMonitorDbModule::endJob().

                                    {

  std::cout << "MonitorElementsDb: analyzed " << ievt_ << " events" << std::endl;
  for( unsigned int i = 0; i<MEs_.size(); i++ ) {
    if( MEs_[i] != 0 ) dqmStore_->removeElement( MEs_[i]->getName() );
  }

}
void MonitorElementsDb::htmlOutput ( std::string &  htmlDir) [protected]

Definition at line 210 of file MonitorElementsDb.cc.

References alignmentValidation::c1, h, i, ievt_, MEinfo_, MEs_, n, mergeVDriftHistosByStation::name, and fw3dlego::xbins.

Referenced by EcalBarrelMonitorDbModule::analyze(), and EcalEndcapMonitorDbModule::analyze().

                                                    {

  gStyle->SetOptStat(0);
  gStyle->SetOptFit();
  gStyle->SetPalette(1,0);

  for( unsigned int i=0; i<MEinfo_.size(); i++ ) {

    if( MEs_[i] != 0 && ( ievt_ % MEinfo_[i].ncycle ) == 0 ) {

      TCanvas* c1;
      int n = MEinfo_[i].xbins > MEinfo_[i].ybins ? int( round( float( MEinfo_[i].xbins ) / float( MEinfo_[i].ybins ) ) ) :
        int( round( float( MEinfo_[i].ybins ) / float( MEinfo_[i].xbins ) ) );
      if( MEinfo_[i].xbins > MEinfo_[i].ybins ) {
        c1 = new TCanvas( "c1", "dummy", 400*n, 400 );
      }
      else {
        c1 = new TCanvas( "c1", "dummy", 400, 400*n );
      }
      c1->SetGrid();
      c1->cd();

      const double histMax = 1.e15;

      TObject* ob = const_cast<MonitorElement*>(MEs_[i])->getRootObject();
      if ( ob ) {
        if( dynamic_cast<TH1F*>( ob ) ) {
          TH1F* h = dynamic_cast<TH1F*> ( ob );
          h->Draw( );
        }
        else if( dynamic_cast<TH2F*>( ob ) ) {
          TH2F* h = dynamic_cast<TH2F*>( ob );
          if( h->GetMaximum(histMax) > 1.e4 ) {
            gPad->SetLogz(1);
          } else {
            gPad->SetLogz(0);
          }
          h->Draw( "colz" );
        }
        else if( dynamic_cast<TProfile*>( ob ) ) {
          TProfile* h = dynamic_cast<TProfile*>( ob );
          if( h->GetMaximum(histMax) > 1.e4 ) {
            gPad->SetLogz(1);
          } else {
            gPad->SetLogz(0);
          }
          h->Draw( "colz" );
        }
      }

      c1->Update();
      std::string name = htmlDir + "/" + MEinfo_[i].title + ".png";
      c1->SaveAs( name.c_str() );

      delete c1;

    }
  }
}
void MonitorElementsDb::startSession ( void  ) [protected]

Friends And Related Function Documentation

friend class EcalBarrelMonitorDbModule [friend]

Definition at line 33 of file MonitorElementsDb.h.

friend class EcalEndcapMonitorDbModule [friend]

Definition at line 34 of file MonitorElementsDb.h.


Member Data Documentation

Definition at line 68 of file MonitorElementsDb.h.

Referenced by endJob(), and MonitorElementsDb().

int MonitorElementsDb::ievt_ [private]

Definition at line 67 of file MonitorElementsDb.h.

Referenced by analyze(), beginJob(), endJob(), and htmlOutput().

std::vector<DB_ME> MonitorElementsDb::MEinfo_ [private]

Definition at line 65 of file MonitorElementsDb.h.

Referenced by analyze(), htmlOutput(), and MonitorElementsDb().

std::vector<MonitorElement*> MonitorElementsDb::MEs_ [private]

Definition at line 66 of file MonitorElementsDb.h.

Referenced by analyze(), endJob(), htmlOutput(), and MonitorElementsDb().

Definition at line 64 of file MonitorElementsDb.h.

Referenced by MonitorElementsDb().

std::string MonitorElementsDb::prefixME_ [private]

Definition at line 62 of file MonitorElementsDb.h.

Referenced by MonitorElementsDb().

std::string MonitorElementsDb::xmlFile_ [private]

Definition at line 63 of file MonitorElementsDb.h.

Referenced by MonitorElementsDb().