CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/DQM/SiStripCommissioningClients/src/CommissioningHistograms.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningClients/interface/CommissioningHistograms.h"
00002 #include "CondFormats/SiStripObjects/interface/CommissioningAnalysis.h"
00003 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00005 #include "DataFormats/SiStripCommon/interface/SiStripDetKey.h"
00006 #include "DQM/SiStripCommissioningSummary/interface/SummaryGenerator.h"
00007 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include <iomanip>
00010 
00011 using namespace std;
00012 using namespace sistrip;
00013 
00014 
00015 // -----------------------------------------------------------------------------
00017 CommissioningHistograms::CommissioningHistograms( const edm::ParameterSet& pset,
00018                                                   DQMStore* bei,
00019                                                   const sistrip::RunType& task )
00020   : factory_(0),
00021     task_(task),
00022     bei_(bei),
00023     data_(),
00024     histos_(),
00025     pset_(pset)
00026 {
00027   LogTrace(mlDqmClient_)
00028     << "[" << __PRETTY_FUNCTION__ << "]"
00029     << " Constructing object...";
00030 
00031   // DQMStore
00032   if ( !bei_ ) {
00033     edm::LogError(mlDqmClient_)
00034       << "[CommissioningHistograms::" << __func__ << "]"
00035       << " NULL pointer to DQMStore!";
00036   }
00037   
00038   clearHistosMap();
00039 }
00040 
00041 // -----------------------------------------------------------------------------
00043 CommissioningHistograms::CommissioningHistograms() 
00044   : factory_(0),
00045     task_(sistrip::UNDEFINED_RUN_TYPE),
00046     bei_(0),
00047     data_(),
00048     histos_()
00049 {
00050   LogTrace(mlDqmClient_)
00051     << "[" << __PRETTY_FUNCTION__ << "]"
00052     << " Constructing object...";
00053 }
00054 
00055 // -----------------------------------------------------------------------------
00057 CommissioningHistograms::~CommissioningHistograms() {
00058   LogTrace(mlDqmClient_)
00059     << "[" << __PRETTY_FUNCTION__ << "]"
00060     << " Destructing object...";
00061   clearHistosMap();
00062   //@@ do not delete BEI ptrs!
00063 }
00064 
00065 // -----------------------------------------------------------------------------
00067 void CommissioningHistograms::Histo::print( std::stringstream& ss ) const {
00068   ss << " [Histo::" << __func__ << "]" << std::endl
00069      << " Histogram title   : " << title_ << std::endl
00070      << " MonitorElement*   : 0x" 
00071      << std::hex
00072      << std::setw(8) << std::setfill('0') << me_ << std::endl
00073      << std::dec
00074      << " CollateME*        : 0x" 
00075      << std::hex
00076      << std::setw(8) << std::setfill('0') << cme_ << std::endl
00077      << std::dec;
00078 }
00079 
00080 // -----------------------------------------------------------------------------
00081 //
00082 uint32_t CommissioningHistograms::runNumber( DQMStore* const bei,
00083                                              const std::vector<std::string>& contents ) {
00084   
00085   // Check if histograms present
00086   if ( contents.empty() ) { 
00087     edm::LogError(mlDqmClient_)
00088       << "[CommissioningHistograms::" << __func__ << "]"
00089       << " Found no histograms!";
00090     return 0; 
00091   }
00092   
00093   // Iterate through added contents
00094   std::vector<std::string>::const_iterator istr = contents.begin();
00095   while ( istr != contents.end() ) {
00096     
00097     // Extract source directory path 
00098     std::string source_dir = istr->substr( 0, istr->find(":") );
00099     
00100     // Generate corresponding client path (removing trailing "/")
00101     SiStripFecKey path( source_dir );
00102     std::string client_dir = path.path();
00103     std::string slash = client_dir.substr( client_dir.size()-1, 1 ); 
00104     if ( slash == sistrip::dir_ ) { client_dir = client_dir.substr( 0, client_dir.size()-1 ); }
00105     client_dir = std::string(sistrip::collate_) + sistrip::dir_ + client_dir;
00106     
00107     // Iterate though MonitorElements from source directory
00108     std::vector<MonitorElement*> me_list = bei->getContents( source_dir );
00109     std::vector<MonitorElement*>::iterator ime = me_list.begin(); 
00110     for ( ; ime != me_list.end(); ime++ ) {
00111       
00112       if ( !(*ime) ) {
00113         edm::LogError(mlDqmClient_)
00114           << "[CommissioningHistograms::" << __func__ << "]"
00115           << " NULL pointer to MonitorElement!";
00116         continue;
00117       }
00118 
00119       // Search for run type in string
00120       std::string title = (*ime)->getName();
00121       std::string::size_type pos = title.find( sistrip::runNumber_ );
00122       
00123       // Extract run number from string 
00124       if ( pos != std::string::npos ) { 
00125         std::string value = title.substr( pos+sizeof(sistrip::runNumber_) , std::string::npos ); 
00126         if ( !value.empty() ) { 
00127           LogTrace(mlDqmClient_)
00128             << "[CommissioningHistograms::" << __func__ << "]"
00129             << " Found string \"" <<  title.substr(pos,std::string::npos)
00130             << "\" with value \"" << value << "\"";
00131           if ( !(bei->get(client_dir+"/"+title.substr(pos,std::string::npos))) ) { 
00132             bei->setCurrentFolder(client_dir);
00133             bei->bookString( title.substr(pos,std::string::npos), value ); 
00134             LogTrace(mlDqmClient_)
00135               << "[CommissioningHistograms::" << __func__ << "]"
00136               << " Booked string \"" << title.substr(pos,std::string::npos)
00137               << "\" in directory \"" << client_dir << "\"";
00138           }
00139           uint32_t run;
00140           std::stringstream ss;
00141           ss << value;
00142           ss >> std::dec >> run;
00143           return run; 
00144         }
00145       }
00146 
00147     }
00148 
00149     istr++;
00150     
00151   }
00152   return 0;
00153 }
00154 
00155 // -----------------------------------------------------------------------------
00157 sistrip::RunType CommissioningHistograms::runType( DQMStore* const bei,
00158                                                    const std::vector<std::string>& contents ) {
00159   
00160   // Check if histograms present
00161   if ( contents.empty() ) { 
00162     edm::LogError(mlDqmClient_)
00163       << "[CommissioningHistograms::" << __func__ << "]"
00164       << " Found no histograms!";
00165     return sistrip::UNKNOWN_RUN_TYPE; 
00166   }
00167   
00168   // Iterate through added contents
00169   std::vector<std::string>::const_iterator istr = contents.begin();
00170   while ( istr != contents.end() ) {
00171 
00172     // Extract source directory path 
00173     std::string source_dir = istr->substr( 0, istr->find(":") );
00174 
00175     // Generate corresponding client path (removing trailing "/")
00176     SiStripFecKey path( source_dir );
00177     std::string client_dir = path.path();
00178     std::string slash = client_dir.substr( client_dir.size()-1, 1 ); 
00179     if ( slash == sistrip::dir_ ) { client_dir = client_dir.substr( 0, client_dir.size()-1 ); } 
00180     client_dir = std::string(sistrip::collate_) + sistrip::dir_ + client_dir;
00181     
00182     // Iterate though MonitorElements from source directory
00183     std::vector<MonitorElement*> me_list = bei->getContents( source_dir );
00184 
00185     if ( me_list.empty() ) {
00186       edm::LogError(mlDqmClient_)
00187         << "[CommissioningHistograms::" << __func__ << "]"
00188         << " No MonitorElements found in dir " << source_dir;
00189       return sistrip::UNKNOWN_RUN_TYPE;
00190     }
00191 
00192     std::vector<MonitorElement*>::iterator ime = me_list.begin(); 
00193     for ( ; ime != me_list.end(); ime++ ) {
00194 
00195       if ( !(*ime) ) {
00196         edm::LogError(mlDqmClient_)
00197           << "[CommissioningHistograms::" << __func__ << "]"
00198           << " NULL pointer to MonitorElement!";
00199         continue;
00200       }
00201 
00202       // Search for run type in string
00203       std::string title = (*ime)->getName();
00204       std::string::size_type pos = title.find( sistrip::taskId_ );
00205 
00206       // Extract commissioning task from string 
00207       if ( pos != std::string::npos ) { 
00208         std::string value = title.substr( pos+sizeof(sistrip::taskId_) , std::string::npos ); 
00209         if ( !value.empty() ) { 
00210           LogTrace(mlDqmClient_)
00211             << "[CommissioningHistograms::" << __func__ << "]"
00212             << " Found string \"" <<  title.substr(pos,std::string::npos)
00213             << "\" with value \"" << value << "\"";
00214           if ( !(bei->get(client_dir+sistrip::dir_+title.substr(pos,std::string::npos))) ) { 
00215             bei->setCurrentFolder(client_dir);
00216             bei->bookString( title.substr(pos,std::string::npos), value ); 
00217             LogTrace(mlDqmClient_)
00218               << "[CommissioningHistograms::" << __func__ << "]"
00219               << " Booked string \"" << title.substr(pos,std::string::npos)
00220               << "\" in directory \"" << client_dir << "\"";
00221           }
00222           return SiStripEnumsAndStrings::runType( value ); 
00223         }
00224       }
00225 
00226     }
00227 
00228     istr++;
00229     
00230   }
00231 
00232   edm::LogError(mlDqmClient_)
00233     << "[CommissioningHistograms::" << __func__ << "]"
00234     << " Unable to extract RunType!";
00235   return sistrip::UNKNOWN_RUN_TYPE;
00236 
00237 }
00238 
00239 // -----------------------------------------------------------------------------
00240 // Temporary fix: builds a list of histogram directories
00241 void CommissioningHistograms::getContents( DQMStore* const bei,
00242                                            std::vector<std::string>& contents ) {  
00243 }
00244 
00245 // -----------------------------------------------------------------------------
00246 //
00247 void CommissioningHistograms::copyCustomInformation( DQMStore* const bei,
00248                                                      const std::vector<std::string>& contents ) {
00249   
00250   // Check if histograms present
00251   if ( contents.empty() ) {
00252     edm::LogWarning(mlDqmClient_)
00253       << "[CommissioningHistograms::" << __func__  << "]"
00254       << " Found no histograms!";
00255     return;
00256   }
00257   
00258   // Iterate through added contents
00259   std::vector<std::string>::const_iterator istr = contents.begin();
00260   while ( istr != contents.end() ) {
00261 
00262     // Extract source directory path
00263     std::string source_dir = istr->substr( 0, istr->find(":") );
00264 
00265     // Generate corresponding client path (removing trailing "/")
00266     SiStripFecKey path( source_dir );
00267     std::string client_dir = path.path();
00268     std::string slash = client_dir.substr( client_dir.size()-1, 1 );
00269     if ( slash == sistrip::dir_ ) { client_dir = client_dir.substr( 0, client_dir.size()-1 ); }
00270 
00271     // Iterate though MonitorElements from source directory
00272     std::vector<MonitorElement*> me_list = bei->getContents( source_dir );
00273     std::vector<MonitorElement*>::iterator ime = me_list.begin();
00274     for ( ; ime != me_list.end(); ime++ ) {
00275 
00276       if ( !(*ime) ) {
00277         edm::LogWarning(mlDqmClient_)
00278           << "[CommissioningHistograms::" << __func__ << "]"
00279           << " NULL pointer to MonitorElement!";
00280         continue;
00281       }
00282       // Search for calchan, isha or vfs
00283       if((*ime)->kind()==MonitorElement::DQM_KIND_INT) {
00284         std::string title = (*ime)->getName();
00285         std::string::size_type pos = title.find("calchan");
00286         if( pos == std::string::npos ) pos = title.find("isha");
00287         if( pos == std::string::npos ) pos = title.find("vfs");
00288         if( pos != std::string::npos ) {
00289           int value = (*ime)->getIntValue();
00290           if ( value>=0 ) {
00291             edm::LogVerbatim(mlDqmClient_)
00292               << "[CommissioningHistograms::" << __func__ << "]"
00293               << " Found \"" << title.substr(pos,std::string::npos)
00294               << "\" with value \"" << value << "\"";
00295             if ( !(bei->get(client_dir+"/"+title.substr(pos,std::string::npos))) ) {
00296               bei->setCurrentFolder(client_dir);
00297               bei->bookInt( title.substr(pos,std::string::npos))->Fill(value);
00298               edm::LogVerbatim(mlDqmClient_)
00299                 << "[CommissioningHistograms::" << __func__ << "]"
00300                 << " Booked \"" << title.substr(pos,std::string::npos)
00301                 << "\" in directory \"" << client_dir << "\"";
00302             }
00303           }
00304         }
00305       }
00306     }
00307     istr++;
00308   }
00309 }
00310 
00311 // -----------------------------------------------------------------------------
00312 
00314 void CommissioningHistograms::extractHistograms( const std::vector<std::string>& contents ) {
00315   LogTrace(mlDqmClient_)
00316     << "[CommissioningHistograms::" << __func__ << "]"
00317     << " Extracting available histograms...";
00318   
00319   // Check pointer
00320   if ( !bei_ ) {
00321     edm::LogError(mlDqmClient_)
00322       << "[CommissioningHistograms::" << __func__ << "]"
00323       << " NULL pointer to DQMStore!";
00324     return;
00325   }
00326   
00327   // Check list of histograms
00328   if ( contents.empty() ) { 
00329     edm::LogError(mlDqmClient_)
00330       << "[CommissioningHistograms::" << __func__ << "]"
00331       << " Empty contents vector!";
00332     return; 
00333   }
00334   
00335   // Iterate through list of histograms
00336   std::vector<std::string>::const_iterator idir;
00337   for ( idir = contents.begin(); idir != contents.end(); idir++ ) {
00338     
00339     // Ignore "DQM source" directories if looking in client file
00340     if ( idir->find(sistrip::collate_) == std::string::npos ) { continue; }
00341     
00342     // Extract source directory path 
00343     std::string source_dir = idir->substr( 0, idir->find(":") );
00344 
00345     // Extract view and create key
00346     sistrip::View view = SiStripEnumsAndStrings::view( source_dir );
00347     SiStripKey path;
00348     if ( view == sistrip::CONTROL_VIEW ) { path = SiStripFecKey( source_dir ); }
00349     else if ( view == sistrip::READOUT_VIEW ) { path = SiStripFedKey( source_dir ); }
00350     else if ( view == sistrip::DETECTOR_VIEW ) { path = SiStripDetKey( source_dir ); }
00351     else { path = SiStripKey(); }
00352     
00353     // Check path is valid
00354     if ( path.granularity() == sistrip::UNKNOWN_GRAN ||
00355          path.granularity() == sistrip::UNDEFINED_GRAN ) { 
00356       continue; 
00357     }
00358     
00359     // Generate corresponding client path (removing trailing "/")
00360     std::string client_dir(sistrip::undefinedView_);
00361     if ( view == sistrip::CONTROL_VIEW ) { client_dir = SiStripFecKey( path.key() ).path(); }
00362     else if ( view == sistrip::READOUT_VIEW ) { client_dir = SiStripFedKey( path.key() ).path(); }
00363     else if ( view == sistrip::DETECTOR_VIEW ) { client_dir = SiStripDetKey( path.key() ).path(); }
00364     else { client_dir = SiStripKey( path.key() ).path(); }
00365     std::string slash = client_dir.substr( client_dir.size()-1, 1 ); 
00366     if ( slash == sistrip::dir_ ) { client_dir = client_dir.substr( 0, client_dir.size()-1 ); }
00367     client_dir = std::string(sistrip::collate_) + sistrip::dir_ + client_dir;
00368 
00369     // Retrieve MonitorElements from source directory
00370     std::vector<MonitorElement*> me_list = bei_->getContents( source_dir );
00371 
00372     // Iterate though MonitorElements and create CMEs
00373     std::vector<MonitorElement*>::iterator ime = me_list.begin(); 
00374     for ( ; ime != me_list.end(); ime++ ) {
00375 
00376       // Retrieve histogram title
00377       SiStripHistoTitle title( (*ime)->getName() );
00378 
00379       // Check histogram type
00380       //if ( title.histoType() != sistrip::EXPERT_HISTO ) { continue; }
00381 
00382       // Check granularity
00383       uint16_t channel = sistrip::invalid_;
00384       if ( title.granularity() == sistrip::APV ) {
00385         channel = SiStripFecKey::lldChan( title.channel() );
00386       } else if ( title.granularity() == sistrip::UNKNOWN_GRAN || 
00387                   title.granularity() == sistrip::UNDEFINED_GRAN ) {
00388         std::stringstream ss;
00389         ss << "[CommissioningHistograms::" << __func__ << "]"
00390            << " Unexpected granularity for histogram title: " 
00391            << std::endl << title 
00392            << " found in path " 
00393            << std::endl << path;
00394         edm::LogError(mlDqmClient_) << ss.str();
00395       } else {
00396         channel = title.channel();
00397       }
00398 
00399       // Build key 
00400       uint32_t key = sistrip::invalid32_;
00401 
00402       if ( view == sistrip::CONTROL_VIEW ) { 
00403 
00404         // for all runs except cabling
00405         SiStripFecKey temp( path.key() ); 
00406         key = SiStripFecKey( temp.fecCrate(),
00407                              temp.fecSlot(),
00408                              temp.fecRing(),
00409                              temp.ccuAddr(),
00410                              temp.ccuChan(),
00411                              channel ).key();
00412         mapping_[title.keyValue()] = key;
00413 
00414       } else if ( view == sistrip::READOUT_VIEW ) { 
00415 
00416         // for cabling run
00417         key = SiStripFedKey( path.key() ).key();
00418         uint32_t temp = SiStripFecKey( sistrip::invalid_,
00419                                        sistrip::invalid_,
00420                                        sistrip::invalid_,
00421                                        sistrip::invalid_,
00422                                        sistrip::invalid_,
00423                                        channel ).key(); // just record lld channel
00424         mapping_[title.keyValue()] = temp;
00425 
00426       } else if ( view == sistrip::DETECTOR_VIEW ) { 
00427 
00428         SiStripDetKey temp( path.key() ); 
00429         key = SiStripDetKey( temp.partition() ).key();
00430         mapping_[title.keyValue()] = key;
00431 
00432       } else { key = SiStripKey( path.key() ).key(); }
00433       
00434       // Find CME in histos map
00435       Histo* histo = 0;
00436       HistosMap::iterator ihistos = histos_.find( key );
00437       if ( ihistos != histos_.end() ) { 
00438         Histos::iterator ihis = ihistos->second.begin();
00439         while ( !histo && ihis < ihistos->second.end() ) {
00440           if ( (*ime)->getName() == (*ihis)->title_ ) { histo = *ihis; }
00441           ihis++;
00442         }
00443       }
00444 
00445       // Create CollateME if it doesn't exist
00446       if ( !histo ) {
00447 
00448         histos_[key].push_back( new Histo() );
00449         histo = histos_[key].back();
00450         histo->title_ = (*ime)->getName();
00451 
00452         // If histogram present in client directory, add to map
00453         if ( source_dir.find(sistrip::collate_) != std::string::npos ) { 
00454           histo->me_ = bei_->get( client_dir +"/"+(*ime)->getName() ); 
00455           if ( !histo->me_ ) { 
00456             edm::LogError(mlDqmClient_)
00457               << "[CommissioningHistograms::" << __func__ << "]"
00458               << " NULL pointer to MonitorElement!";
00459           }
00460         }
00461 
00462       }
00463 
00464     }
00465     
00466   }
00467   
00468   //printHistosMap();
00469   
00470   edm::LogVerbatim(mlDqmClient_)
00471     << "[CommissioningHistograms::" << __func__ << "]"
00472     << " Found histograms for " << histos_.size()
00473     << " structures in cached histogram map!";
00474   
00475 }
00476 
00477 
00478 // -----------------------------------------------------------------------------
00480 void CommissioningHistograms::histoAnalysis( bool debug ) {
00481   LogTrace(mlDqmClient_)
00482     << "[CommissioningHistograms::" << __func__ << "]"
00483     << " (Derived) implementation to come...";
00484 }
00485 
00486 // -----------------------------------------------------------------------------
00488 void CommissioningHistograms::printAnalyses() {
00489   Analyses::iterator ianal = data().begin();
00490   Analyses::iterator janal = data().end();
00491   for ( ; ianal != janal; ++ianal ) { 
00492     if ( ianal->second ) { 
00493       std::stringstream ss;
00494       ianal->second->print( ss ); 
00495       if ( ianal->second->isValid() ) { LogTrace(mlDqmClient_) << ss.str(); 
00496       } else { edm::LogWarning(mlDqmClient_) << ss.str(); }
00497     }
00498   }
00499 }
00500 
00501 // -----------------------------------------------------------------------------
00503 void CommissioningHistograms::printSummary() {
00504 
00505   std::stringstream good;
00506   std::stringstream bad;
00507   
00508   Analyses::iterator ianal = data().begin();
00509   Analyses::iterator janal = data().end();
00510   for ( ; ianal != janal; ++ianal ) { 
00511     if ( ianal->second ) { 
00512       if ( ianal->second->isValid() ) { ianal->second->summary( good ); }
00513       else { ianal->second->summary( bad ); }
00514     }
00515   }
00516 
00517   if ( good.str().empty() ) { good << "None found!"; }
00518   LogTrace(mlDqmClient_) 
00519     << "[CommissioningHistograms::" << __func__ << "]"
00520     << " Printing summary of good analyses:" << "\n"
00521     << good.str();
00522   
00523   if ( bad.str().empty() ) { return; } //@@ bad << "None found!"; }
00524   LogTrace(mlDqmClient_) 
00525     << "[CommissioningHistograms::" << __func__ << "]"
00526     << " Printing summary of bad analyses:" << "\n"
00527     << bad.str();
00528   
00529 }
00530 
00531 // -----------------------------------------------------------------------------
00533 void CommissioningHistograms::printHistosMap() {
00534   LogTrace(mlDqmClient_)
00535     << "[CommissioningHistograms::" << __func__ << "]"
00536     << " Printing histogram map, which has "
00537     << histos_.size() << " entries...";
00538   HistosMap::const_iterator ihistos = histos_.begin();
00539   for ( ; ihistos != histos_.end(); ihistos++ ) {
00540     std::stringstream ss;
00541     ss << " Found " << ihistos->second.size()
00542        << " histogram(s) for key: " << std::endl
00543        << SiStripFedKey(ihistos->first) << std::endl;
00544     Histos::const_iterator ihisto = ihistos->second.begin();
00545     for ( ; ihisto != ihistos->second.end(); ihisto++ ) {
00546       if ( *ihisto ) { (*ihisto)->print(ss); }
00547       else { ss << " NULL pointer to Histo object!"; }
00548     }
00549     LogTrace(mlDqmClient_) << ss.str();
00550   }
00551 }
00552 
00553 // -----------------------------------------------------------------------------
00555 void CommissioningHistograms::clearHistosMap() {
00556   LogTrace(mlDqmClient_)
00557     << "[CommissioningHistograms::" << __func__ << "]"
00558     << " Clearing histogram map...";
00559   HistosMap::iterator ihistos = histos_.begin();
00560   for ( ; ihistos != histos_.end(); ihistos++ ) {
00561     Histos::iterator ihisto = ihistos->second.begin();
00562     for ( ; ihisto != ihistos->second.end(); ihisto++ ) {
00563       if ( *ihisto ) { delete *ihisto; }
00564     }
00565     ihistos->second.clear();
00566   }
00567   histos_.clear();
00568 }
00569 
00570 // -----------------------------------------------------------------------------
00572 void CommissioningHistograms::createSummaryHisto( const sistrip::Monitorable& mon, 
00573                                                   const sistrip::Presentation& pres, 
00574                                                   const std::string& dir,
00575                                                   const sistrip::Granularity& gran ) {
00576   LogTrace(mlDqmClient_)
00577     << "[CommissioningHistograms::" << __func__ << "]";
00578   
00579   // Check view 
00580   sistrip::View view = SiStripEnumsAndStrings::view(dir);
00581   if ( view == sistrip::UNKNOWN_VIEW ) { return; }
00582   
00583   // Analyze histograms
00584   if ( data().empty() ) { histoAnalysis( false ); }
00585 
00586   // Check
00587   if ( data().empty() ) { 
00588     edm::LogError(mlDqmClient_)
00589       << "[CommissioningHistograms::" << __func__ << "]"
00590       << " No analyses generated!";
00591     return;
00592   }
00593   
00594   // Extract data to be histogrammed
00595   uint32_t xbins = factory()->init( mon, pres, view, dir, gran, data() );
00596   
00597   // Only create histograms if entries are found!
00598   if ( !xbins ) { return; }
00599   
00600   // Create summary histogram (if it doesn't already exist)
00601   TH1* summary = 0;
00602   if ( pres != sistrip::HISTO_1D ) { summary = histogram( mon, pres, view, dir, xbins ); }
00603   else { summary = histogram( mon, pres, view, dir, sistrip::FED_ADC_RANGE, 0., sistrip::FED_ADC_RANGE*1. ); }
00604   
00605   // Fill histogram with data
00606   factory()->fill( *summary );
00607   
00608 }
00609 
00610 // -----------------------------------------------------------------------------
00612 void CommissioningHistograms::remove( std::string pattern ) {
00613   
00614   if ( !bei_ ) { 
00615     edm::LogError(mlDqmClient_)
00616       << "[CommissioningHistograms::" << __func__ << "]"
00617       << " NULL pointer to DQMStore!"; 
00618     return;
00619   }
00620   
00621   bei_->setVerbose(0);
00622 
00623   LogTrace(mlDqmClient_)
00624     << "[CommissioningHistograms::" << __func__ << "]"
00625     << " Removing histograms...";
00626   
00627   if ( !pattern.empty() ) {
00628     
00629     if ( bei_->dirExists(pattern) ) {
00630       bei_->rmdir(pattern); 
00631     }
00632     
00633     LogTrace(mlDqmClient_)
00634       << "[CommissioningHistograms::" << __func__ << "]"
00635       << " Removing directories (and MonitorElements"
00636       << " therein) that match the pattern \""
00637       << pattern << "\"";
00638     
00639   } else {
00640     
00641     bei_->cd();
00642     bei_->removeContents(); 
00643     
00644     if( bei_->dirExists("Collector") ) {
00645       bei_->rmdir("Collector");
00646     }
00647     if( bei_->dirExists("EvF") ) {
00648       bei_->rmdir("EvF");
00649     }
00650     if( bei_->dirExists("SiStrip") ) {
00651       bei_->rmdir("SiStrip");
00652     }
00653 
00654     LogTrace(mlDqmClient_)
00655       << "[CommissioningHistograms::" << __func__ << "]"
00656       << " Removing \"DQM source\" directories (and MonitorElements therein)";
00657     
00658   }
00659 
00660   LogTrace(mlDqmClient_)
00661     << "[CommissioningHistograms::" << __func__ << "]"
00662     << " Removed histograms!";
00663 
00664   bei_->setVerbose(1);
00665 
00666 }
00667 
00668 // -----------------------------------------------------------------------------
00670 void CommissioningHistograms::save( std::string& path,
00671                                     uint32_t run_number ) {
00672   
00673   // Construct path and filename
00674   std::stringstream ss; 
00675 
00676   if ( !path.empty() ) { 
00677 
00678     ss << path; 
00679     if ( ss.str().find(".root") == std::string::npos ) { ss << ".root"; }
00680 
00681   } else {
00682 
00683     // Retrieve SCRATCH directory
00684     std::string scratch = "SCRATCH";
00685     std::string dir = "";
00686     if ( getenv(scratch.c_str()) != NULL ) { 
00687       dir = getenv(scratch.c_str()); 
00688     }
00689     
00690     // Add directory path 
00691     if ( !dir.empty() ) { ss << dir << "/"; }
00692     else { ss << "/tmp/"; }
00693     
00694     // Add filename with run number and ".root" extension
00695     ss << sistrip::dqmClientFileName_ << "_" 
00696        << std::setfill('0') << std::setw(8) << run_number
00697        << ".root";
00698     
00699   }
00700   
00701   // Save file with appropriate filename
00702   LogTrace(mlDqmClient_)
00703     << "[CommissioningHistograms::" << __func__ << "]"
00704     << " Saving histograms to root file"
00705     << " (This may take some time!)";
00706   path = ss.str();
00707   bei_->save( path, sistrip::collate_ ); 
00708   edm::LogVerbatim(mlDqmClient_)
00709     << "[CommissioningHistograms::" << __func__ << "]"
00710     << " Saved histograms to root file \""
00711     << ss.str() << "\"!";
00712   
00713 }
00714 
00715 // -----------------------------------------------------------------------------
00716 // 
00717 TH1* CommissioningHistograms::histogram( const sistrip::Monitorable& mon, 
00718                                          const sistrip::Presentation& pres, 
00719                                          const sistrip::View& view,
00720                                          const std::string& directory,
00721                                          const uint32_t& xbins, 
00722                                          const float& xlow,
00723                                          const float& xhigh ) {
00724   
00725   // Remember pwd 
00726   std::string pwd = bei_->pwd();
00727   bei_->setCurrentFolder( std::string(sistrip::collate_) + sistrip::dir_ + directory );
00728   
00729   // Construct histogram name 
00730   std::string name = SummaryGenerator::name( task_, mon, pres, view, directory );
00731   
00732   // Check if summary plot already exists and remove
00733   MonitorElement* me = bei_->get( bei_->pwd() + "/" + name );
00734   if ( me ) { 
00735     bei_->removeElement( name );
00736     me = 0;
00737   } 
00738   
00739   // Create summary plot
00740   float high = static_cast<float>( xbins );
00741   if ( pres == sistrip::HISTO_1D ) { 
00742     if ( xlow < 1. * sistrip::valid_ && 
00743          xhigh < 1. * sistrip::valid_ ) { 
00744       me = bei_->book1D( name, name, xbins, xlow, xhigh ); 
00745     } else {
00746       me = bei_->book1D( name, name, xbins, 0., high ); 
00747     }
00748   } else if ( pres == sistrip::HISTO_2D_SUM ) { 
00749     me = bei_->book1D( name, name, 
00750                                          xbins, 0., high ); 
00751   } else if ( pres == sistrip::HISTO_2D_SCATTER ) { 
00752     me = bei_->book2D( name, name, xbins, 0., high, 
00753                                          sistrip::FED_ADC_RANGE+1, 
00754                                          0., 
00755                                          sistrip::FED_ADC_RANGE*1. ); 
00756   } else if ( pres == sistrip::PROFILE_1D ) { 
00757     me = bei_->bookProfile( name, name, xbins, 0., high, 
00758                                               sistrip::FED_ADC_RANGE+1, 
00759                                               0., 
00760                                               sistrip::FED_ADC_RANGE*1. ); 
00761   } else { 
00762     me = 0; 
00763     edm::LogWarning(mlDqmClient_)
00764       << "[CommissioningHistograms::" << __func__ << "]"
00765       << " Unexpected presentation \"" 
00766       << SiStripEnumsAndStrings::presentation( pres )
00767       << "\" Unable to create summary plot!";
00768   }
00769   
00770   // Check pointer
00771   if ( me ) { 
00772     LogTrace(mlDqmClient_)
00773       << "[CommissioningHistograms::" << __func__ << "]"
00774       << " Created summary plot with name \"" << me->getName()
00775       << "\" in directory \""
00776       << bei_->pwd() << "\"!"; 
00777   } else {
00778     edm::LogWarning(mlDqmClient_)
00779       << "[CommissioningHistograms::" << __func__ << "]"
00780       << " NULL pointer to MonitorElement!"
00781       << " Unable to create summary plot!";
00782   }
00783   
00784   // Extract root object
00785   TH1* summary = ExtractTObject<TH1>().extract( me ); 
00786   if ( !summary ) {
00787     edm::LogWarning(mlDqmClient_)
00788       << "[CommissioningHistograms::" << __func__ << "]"
00789       << " Unable to extract root object!"
00790       << " Returning NULL pointer!"; 
00791   }
00792   
00793   // Return to pwd
00794   bei_->setCurrentFolder( pwd );
00795   
00796   return summary;
00797   
00798 }
00799