CMS 3D CMS Logo

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 "DQM/SiStripCommissioningSummary/interface/SummaryGenerator.h"
00006 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include <iomanip>
00009 
00010 using namespace std;
00011 using namespace sistrip;
00012 
00013 // -----------------------------------------------------------------------------
00015 CommissioningHistograms::CommissioningHistograms( DQMOldReceiver* mui,
00016                                                   const sistrip::RunType& task ) 
00017   : factory_(0),
00018     task_(task),
00019     mui_(mui),
00020     bei_(0),
00021     data_(),
00022     histos_()
00023 {
00024   LogTrace(mlDqmClient_)
00025     << "[" << __PRETTY_FUNCTION__ << "]"
00026     << " Constructing object...";
00027 
00028   // DQMOldReceiver
00029   if ( mui_ ) { bei_ = mui_->getBEInterface(); }
00030   else {
00031     edm::LogError(mlDqmClient_)
00032       << "[CommissioningHistograms::" << __func__ << "]"
00033       << " NULL pointer to DQMOldReceiver!";
00034   }
00035   
00036   // DQMStore
00037   if ( !bei_ ) {
00038     edm::LogError(mlDqmClient_)
00039       << "[CommissioningHistograms::" << __func__ << "]"
00040       << " NULL pointer to DQMStore!";
00041   }
00042   
00043   clearHistosMap();
00044 }
00045 
00046 // -----------------------------------------------------------------------------
00048 CommissioningHistograms::CommissioningHistograms( DQMStore* bei,
00049                                                   const sistrip::RunType& task ) 
00050   : factory_(0),
00051     task_(task),
00052     mui_(0),
00053     bei_(bei),
00054     data_(),
00055     histos_()
00056 {
00057   LogTrace(mlDqmClient_)
00058     << "[" << __PRETTY_FUNCTION__ << "]"
00059     << " Constructing object...";
00060 
00061   // DQMStore
00062   if ( !bei_ ) {
00063     edm::LogError(mlDqmClient_)
00064       << "[CommissioningHistograms::" << __func__ << "]"
00065       << " NULL pointer to DQMStore!";
00066   }
00067   
00068   clearHistosMap();
00069 }
00070 
00071 // -----------------------------------------------------------------------------
00073 CommissioningHistograms::CommissioningHistograms() 
00074   : factory_(0),
00075     task_(sistrip::UNDEFINED_RUN_TYPE),
00076     mui_(0),
00077     bei_(0),
00078     data_(),
00079     histos_()
00080 {
00081   LogTrace(mlDqmClient_)
00082     << "[" << __PRETTY_FUNCTION__ << "]"
00083     << " Constructing object...";
00084 }
00085 
00086 // -----------------------------------------------------------------------------
00088 CommissioningHistograms::~CommissioningHistograms() {
00089   LogTrace(mlDqmClient_)
00090     << "[" << __PRETTY_FUNCTION__ << "]"
00091     << " Destructing object...";
00092   clearHistosMap();
00093   //@@ do not delete MUI or BEI ptrs!
00094 }
00095 
00096 // -----------------------------------------------------------------------------
00098 void CommissioningHistograms::Histo::print( std::stringstream& ss ) const {
00099   ss << " [Histo::" << __func__ << "]" << std::endl
00100      << " Histogram title   : " << title_ << std::endl
00101      << " MonitorElement*   : 0x" 
00102      << std::hex
00103      << std::setw(8) << std::setfill('0') << me_ << std::endl
00104      << std::dec
00105      << " CollateME*        : 0x" 
00106      << std::hex
00107      << std::setw(8) << std::setfill('0') << cme_ << std::endl
00108      << std::dec;
00109 }
00110 
00111 // -----------------------------------------------------------------------------
00112 //
00113 uint32_t CommissioningHistograms::runNumber( DQMStore* const bei,
00114                                              const std::vector<std::string>& contents ) {
00115   
00116   // Check if histograms present
00117   if ( contents.empty() ) { 
00118     edm::LogError(mlDqmClient_)
00119       << "[CommissioningHistograms::" << __func__ << "]"
00120       << " Found no histograms!";
00121     return 0; 
00122   }
00123   
00124   // Iterate through added contents
00125   std::vector<std::string>::const_iterator istr = contents.begin();
00126   while ( istr != contents.end() ) {
00127     
00128     // Extract source directory path 
00129     std::string source_dir = istr->substr( 0, istr->find(":") );
00130     
00131     // Generate corresponding client path (removing trailing "/")
00132     SiStripFecKey path( source_dir );
00133     std::string client_dir = path.path();
00134     std::string slash = client_dir.substr( client_dir.size()-1, 1 ); 
00135     if ( slash == sistrip::dir_ ) { client_dir = client_dir.substr( 0, client_dir.size()-1 ); }
00136     client_dir = sistrip::collate_ + sistrip::dir_ + client_dir;
00137     
00138     // Iterate though MonitorElements from source directory
00139     std::vector<MonitorElement*> me_list = bei->getContents( source_dir );
00140     std::vector<MonitorElement*>::iterator ime = me_list.begin(); 
00141     for ( ; ime != me_list.end(); ime++ ) {
00142       
00143       if ( !(*ime) ) {
00144         edm::LogError(mlDqmClient_)
00145           << "[CommissioningHistograms::" << __func__ << "]"
00146           << " NULL pointer to MonitorElement!";
00147         continue;
00148       }
00149 
00150       // Search for run type in string
00151       std::string title = (*ime)->getName();
00152       std::string::size_type pos = title.find( sistrip::runNumber_ );
00153       
00154       // Extract run number from string 
00155       if ( pos != std::string::npos ) { 
00156         std::string value = title.substr( pos+sistrip::runNumber_.size()+1, std::string::npos ); 
00157         if ( !value.empty() ) { 
00158           LogTrace(mlDqmClient_)
00159             << "[CommissioningHistograms::" << __func__ << "]"
00160             << " Found string \"" <<  title.substr(pos,std::string::npos)
00161             << "\" with value \"" << value << "\"";
00162           if ( !(bei->get(client_dir+"/"+title.substr(pos,std::string::npos))) ) { 
00163             bei->setCurrentFolder(client_dir);
00164             bei->bookString( title.substr(pos,std::string::npos), value ); 
00165             LogTrace(mlDqmClient_)
00166               << "[CommissioningHistograms::" << __func__ << "]"
00167               << " Booked string \"" << title.substr(pos,std::string::npos)
00168               << "\" in directory \"" << client_dir << "\"";
00169           }
00170           uint32_t run;
00171           std::stringstream ss;
00172           ss << value;
00173           ss >> std::dec >> run;
00174           return run; 
00175         }
00176       }
00177 
00178     }
00179 
00180     istr++;
00181     
00182   }
00183   return 0;
00184 }
00185 
00186 // -----------------------------------------------------------------------------
00188 sistrip::RunType CommissioningHistograms::runType( DQMStore* const bei,
00189                                                    const std::vector<std::string>& contents ) {
00190   
00191   // Check if histograms present
00192   if ( contents.empty() ) { 
00193     edm::LogError(mlDqmClient_)
00194       << "[CommissioningHistograms::" << __func__ << "]"
00195       << " Found no histograms!";
00196     return sistrip::UNKNOWN_RUN_TYPE; 
00197   }
00198   
00199   // Iterate through added contents
00200   std::vector<std::string>::const_iterator istr = contents.begin();
00201   while ( istr != contents.end() ) {
00202 
00203     // Extract source directory path 
00204     std::string source_dir = istr->substr( 0, istr->find(":") );
00205 
00206     // Generate corresponding client path (removing trailing "/")
00207     SiStripFecKey path( source_dir );
00208     std::string client_dir = path.path();
00209     std::string slash = client_dir.substr( client_dir.size()-1, 1 ); 
00210     if ( slash == sistrip::dir_ ) { client_dir = client_dir.substr( 0, client_dir.size()-1 ); } 
00211     client_dir = sistrip::collate_ + sistrip::dir_ + client_dir;
00212     
00213     // Iterate though MonitorElements from source directory
00214     std::vector<MonitorElement*> me_list = bei->getContents( source_dir );
00215 
00216     if ( me_list.empty() ) {
00217       edm::LogError(mlDqmClient_)
00218         << "[CommissioningHistograms::" << __func__ << "]"
00219         << " No MonitorElements found in dir " << source_dir;
00220       return sistrip::UNKNOWN_RUN_TYPE;
00221     }
00222 
00223     std::vector<MonitorElement*>::iterator ime = me_list.begin(); 
00224     for ( ; ime != me_list.end(); ime++ ) {
00225 
00226       if ( !(*ime) ) {
00227         edm::LogError(mlDqmClient_)
00228           << "[CommissioningHistograms::" << __func__ << "]"
00229           << " NULL pointer to MonitorElement!";
00230         continue;
00231       }
00232 
00233       // Search for run type in string
00234       std::string title = (*ime)->getName();
00235       std::string::size_type pos = title.find( sistrip::taskId_ );
00236 
00237       // Extract commissioning task from string 
00238       if ( pos != std::string::npos ) { 
00239         std::string value = title.substr( pos+sistrip::taskId_.size()+1, std::string::npos ); 
00240         if ( !value.empty() ) { 
00241           LogTrace(mlDqmClient_)
00242             << "[CommissioningHistograms::" << __func__ << "]"
00243             << " Found string \"" <<  title.substr(pos,std::string::npos)
00244             << "\" with value \"" << value << "\"";
00245           if ( !(bei->get(client_dir+sistrip::dir_+title.substr(pos,std::string::npos))) ) { 
00246             bei->setCurrentFolder(client_dir);
00247             bei->bookString( title.substr(pos,std::string::npos), value ); 
00248             LogTrace(mlDqmClient_)
00249               << "[CommissioningHistograms::" << __func__ << "]"
00250               << " Booked string \"" << title.substr(pos,std::string::npos)
00251               << "\" in directory \"" << client_dir << "\"";
00252           }
00253           return SiStripEnumsAndStrings::runType( value ); 
00254         }
00255       }
00256 
00257     }
00258 
00259     istr++;
00260     
00261   }
00262 
00263   edm::LogError(mlDqmClient_)
00264     << "[CommissioningHistograms::" << __func__ << "]"
00265     << " Unable to extract RunType!";
00266   return sistrip::UNKNOWN_RUN_TYPE;
00267 
00268 }
00269 
00270 // -----------------------------------------------------------------------------
00271 // Temporary fix: builds a list of histogram directories
00272 void CommissioningHistograms::getContents( DQMStore* const bei,
00273                                            std::vector<std::string>& contents ) {
00274 
00275 #ifndef USING_NEW_COLLATE_METHODS
00276   
00277   LogTrace(mlDqmClient_) 
00278     << "[CommissioningHistograms::" << __func__ << "]"
00279     << " Building histogram list...";
00280 
00281   contents.clear();
00282 
00283   if ( !bei ) {
00284     edm::LogError(mlDqmClient_)
00285       << "[CommissioningHistograms::" << __func__ << "]"
00286       << " NULL pointer to DQMStore!";
00287   }
00288 
00289   bei->cd();
00290   std::vector<MonitorElement*> mons;
00291   mons = bei->getAllContents( bei->pwd() );
00292   std::vector<MonitorElement*>::const_iterator iter = mons.begin();
00293   for ( ; iter != mons.end(); iter++ ) {
00294     std::vector<std::string>::iterator istr = contents.begin();
00295     bool found = false;
00296     while ( !found && istr != contents.end()  ) {
00297       if ( std::string((*iter)->getPathname()+"/:") == *istr ) { found = true; }
00298       istr++;
00299     }
00300     if ( istr == contents.end() ) { 
00301       std::string temp = (*iter)->getPathname() + "/:"; // + (*iter)->getName();
00302       contents.push_back( temp ); 
00303     }
00304   }
00305   
00306   LogTrace(mlDqmClient_) 
00307     << "[CommissioningHistograms::" << __func__ << "]"
00308     << " Found " << contents.size() << " directories!";
00309 
00310   if ( contents.empty() ) { 
00311     edm::LogError(mlDqmClient_) 
00312       << "[CommissioningHistograms::" << __func__ << "]"
00313       << " No directories found when building list!";
00314   }
00315 
00316 #endif
00317   
00318 }
00319 
00320 // -----------------------------------------------------------------------------
00321 //
00322 void CommissioningHistograms::copyCustomInformation( DQMStore* const bei,
00323                                                      const std::vector<std::string>& contents ) {
00324   
00325   // Check if histograms present
00326   if ( contents.empty() ) {
00327     edm::LogWarning(mlDqmClient_)
00328       << "[CommissioningHistograms::" << __func__  << "]"
00329       << " Found no histograms!";
00330     return;
00331   }
00332   
00333   // Iterate through added contents
00334   std::vector<std::string>::const_iterator istr = contents.begin();
00335   while ( istr != contents.end() ) {
00336 
00337     // Extract source directory path
00338     std::string source_dir = istr->substr( 0, istr->find(":") );
00339 
00340     // Generate corresponding client path (removing trailing "/")
00341     SiStripFecKey path( source_dir );
00342     std::string client_dir = path.path();
00343     std::string slash = client_dir.substr( client_dir.size()-1, 1 );
00344     if ( slash == sistrip::dir_ ) { client_dir = client_dir.substr( 0, client_dir.size()-1 ); }
00345 
00346     // Iterate though MonitorElements from source directory
00347     std::vector<MonitorElement*> me_list = bei->getContents( source_dir );
00348     std::vector<MonitorElement*>::iterator ime = me_list.begin();
00349     for ( ; ime != me_list.end(); ime++ ) {
00350 
00351       if ( !(*ime) ) {
00352         edm::LogWarning(mlDqmClient_)
00353           << "[CommissioningHistograms::" << __func__ << "]"
00354           << " NULL pointer to MonitorElement!";
00355         continue;
00356       }
00357       // Search for calchan, isha or vfs
00358       if((*ime)->kind()==MonitorElement::DQM_KIND_INT) {
00359         std::string title = (*ime)->getName();
00360         std::string::size_type pos = title.find("calchan");
00361         if( pos == std::string::npos ) pos = title.find("isha");
00362         if( pos == std::string::npos ) pos = title.find("vfs");
00363         if( pos != std::string::npos ) {
00364           int value = (*ime)->getIntValue();
00365           if ( value>=0 ) {
00366             edm::LogVerbatim(mlDqmClient_)
00367               << "[CommissioningHistograms::" << __func__ << "]"
00368               << " Found \"" << title.substr(pos,std::string::npos)
00369               << "\" with value \"" << value << "\"";
00370             if ( !(bei->get(client_dir+"/"+title.substr(pos,std::string::npos))) ) {
00371               bei->setCurrentFolder(client_dir);
00372               bei->bookInt( title.substr(pos,std::string::npos))->Fill(value);
00373               edm::LogVerbatim(mlDqmClient_)
00374                 << "[CommissioningHistograms::" << __func__ << "]"
00375                 << " Booked \"" << title.substr(pos,std::string::npos)
00376                 << "\" in directory \"" << client_dir << "\"";
00377             }
00378           }
00379         }
00380       }
00381     }
00382     istr++;
00383   }
00384 }
00385 
00386 // -----------------------------------------------------------------------------
00387 
00389 void CommissioningHistograms::extractHistograms( const std::vector<std::string>& contents ) {
00390   LogTrace(mlDqmClient_)
00391     << "[CommissioningHistograms::" << __func__ << "]"
00392     << " Extracting available histograms...";
00393   
00394   // Check pointer
00395   if ( !bei_ ) {
00396     edm::LogError(mlDqmClient_)
00397       << "[CommissioningHistograms::" << __func__ << "]"
00398       << " NULL pointer to DQMStore!";
00399     return;
00400   }
00401   
00402   // Check list of histograms
00403   if ( contents.empty() ) { 
00404     edm::LogError(mlDqmClient_)
00405       << "[CommissioningHistograms::" << __func__ << "]"
00406       << " Empty contents vector!";
00407     return; 
00408   }
00409   
00410   // Iterate through list of histograms
00411   std::vector<std::string>::const_iterator idir;
00412   for ( idir = contents.begin(); idir != contents.end(); idir++ ) {
00413     
00414     // Ignore "DQM source" directories if looking in client file
00415     if ( idir->find(sistrip::collate_) == std::string::npos ) { continue; }
00416     
00417     // Extract source directory path 
00418     std::string source_dir = idir->substr( 0, idir->find(":") );
00419 
00420     // Extract view and create key
00421     sistrip::View view = SiStripEnumsAndStrings::view( source_dir );
00422     SiStripKey path;
00423     if ( view == sistrip::CONTROL_VIEW ) { path = SiStripFecKey( source_dir ); }
00424     else if ( view == sistrip::READOUT_VIEW ) { path = SiStripFedKey( source_dir ); }
00425     else { path = SiStripKey(); }
00426     
00427     // Check path is valid
00428     if ( path.granularity() == sistrip::UNKNOWN_GRAN ||
00429          path.granularity() == sistrip::UNDEFINED_GRAN ) { 
00430       continue; 
00431     }
00432     
00433     // Generate corresponding client path (removing trailing "/")
00434     std::string client_dir(sistrip::undefinedView_);
00435     if ( view == sistrip::CONTROL_VIEW ) { client_dir = SiStripFecKey( path.key() ).path(); }
00436     else if ( view == sistrip::READOUT_VIEW ) { client_dir = SiStripFedKey( path.key() ).path(); }
00437     else { client_dir = SiStripKey( path.key() ).path(); }
00438     std::string slash = client_dir.substr( client_dir.size()-1, 1 ); 
00439     if ( slash == sistrip::dir_ ) { client_dir = client_dir.substr( 0, client_dir.size()-1 ); }
00440     client_dir = sistrip::collate_ + sistrip::dir_ + client_dir;
00441 
00442     // Retrieve MonitorElements from source directory
00443     std::vector<MonitorElement*> me_list = bei_->getContents( source_dir );
00444 
00445     // Iterate though MonitorElements and create CMEs
00446     std::vector<MonitorElement*>::iterator ime = me_list.begin(); 
00447     for ( ; ime != me_list.end(); ime++ ) {
00448 
00449       // Retrieve histogram title
00450       SiStripHistoTitle title( (*ime)->getName() );
00451 
00452       // Check histogram type
00453       //if ( title.histoType() != sistrip::EXPERT_HISTO ) { continue; }
00454 
00455       // Check granularity
00456       uint16_t channel = sistrip::invalid_;
00457       if ( title.granularity() == sistrip::APV ) {
00458         channel = SiStripFecKey::lldChan( title.channel() );
00459       } else if ( title.granularity() == sistrip::UNKNOWN_GRAN || 
00460                   title.granularity() == sistrip::UNDEFINED_GRAN ) {
00461         std::stringstream ss;
00462         ss << "[CommissioningHistograms::" << __func__ << "]"
00463            << " Unexpected granularity for histogram title: " 
00464            << std::endl << title 
00465            << " found in path " 
00466            << std::endl << path;
00467         edm::LogError(mlDqmClient_) << ss.str();
00468       } else {
00469         channel = title.channel();
00470       }
00471 
00472       // Build key 
00473       uint32_t key = sistrip::invalid32_;
00474 
00475       if ( view == sistrip::CONTROL_VIEW ) { 
00476 
00477         // for all runs except cabling
00478         SiStripFecKey temp( path.key() ); 
00479         key = SiStripFecKey( temp.fecCrate(),
00480                              temp.fecSlot(),
00481                              temp.fecRing(),
00482                              temp.ccuAddr(),
00483                              temp.ccuChan(),
00484                              channel ).key();
00485         mapping_[title.keyValue()] = key;
00486 
00487       } else if ( view == sistrip::READOUT_VIEW ) { 
00488 
00489         // for cabling run
00490         key = SiStripFedKey( path.key() ).key();
00491         uint32_t temp = SiStripFecKey( sistrip::invalid_,
00492                                        sistrip::invalid_,
00493                                        sistrip::invalid_,
00494                                        sistrip::invalid_,
00495                                        sistrip::invalid_,
00496                                        channel ).key(); // just record lld channel
00497         mapping_[title.keyValue()] = temp;
00498 
00499       } else { key = SiStripKey( path.key() ).key(); }
00500       
00501       // Find CME in histos map
00502       Histo* histo = 0;
00503       HistosMap::iterator ihistos = histos_.find( key );
00504       if ( ihistos != histos_.end() ) { 
00505         Histos::iterator ihis = ihistos->second.begin();
00506         while ( !histo && ihis < ihistos->second.end() ) {
00507           if ( (*ime)->getName() == (*ihis)->title_ ) { histo = *ihis; }
00508           ihis++;
00509         }
00510       }
00511 
00512       // Create CollateME if it doesn't exist
00513       if ( !histo ) {
00514 
00515         histos_[key].push_back( new Histo() );
00516         histo = histos_[key].back();
00517         histo->title_ = (*ime)->getName();
00518 
00519         // If histogram present in client directory, add to map
00520         if ( source_dir.find(sistrip::collate_) != std::string::npos ) { 
00521           histo->me_ = bei_->get( client_dir +"/"+(*ime)->getName() ); 
00522           if ( !histo->me_ ) { 
00523             edm::LogError(mlDqmClient_)
00524               << "[CommissioningHistograms::" << __func__ << "]"
00525               << " NULL pointer to MonitorElement!";
00526           }
00527         }
00528 
00529       }
00530 
00531     }
00532     
00533   }
00534   
00535   //printHistosMap();
00536   
00537   edm::LogVerbatim(mlDqmClient_)
00538     << "[CommissioningHistograms::" << __func__ << "]"
00539     << " Found histograms for " << histos_.size()
00540     << " structures in cached histogram map!";
00541   
00542 }
00543 
00544 // -----------------------------------------------------------------------------
00546 void CommissioningHistograms::createCollations( const std::vector<std::string>& contents ) {
00547 
00548 #ifndef USING_NEW_COLLATE_METHODS
00549 
00550   LogTrace(mlDqmClient_)
00551     << "[CommissioningHistograms::" << __func__ << "]"
00552     << " Creating collated histograms...";
00553 
00554   // Check pointer
00555   if ( !mui_ ) {
00556     edm::LogError(mlDqmClient_)
00557       << "[CommissioningHistograms::" << __func__ << "]"
00558       << " NULL pointer to DQMOldReceiver!";
00559     return;
00560   }
00561   
00562   // Check list of histograms
00563   if ( contents.empty() ) { return; }
00564   
00565   // Iterate through list of histograms
00566   std::vector<std::string>::const_iterator idir;
00567   for ( idir = contents.begin(); idir != contents.end(); idir++ ) {
00568     
00569     // Ignore directories on client side
00570     //if ( idir->find(sistrip::collate_) != std::string::npos ) { continue; }
00571     
00572     // Extract source directory path 
00573     std::string source_dir = idir->substr( 0, idir->find(":") );
00574 
00575     // Extract view and create key
00576     sistrip::View view = SiStripEnumsAndStrings::view( source_dir );
00577     SiStripKey path;
00578     if ( view == sistrip::CONTROL_VIEW ) { path = SiStripFecKey( source_dir ); }
00579     else if ( view == sistrip::READOUT_VIEW ) { path = SiStripFedKey( source_dir ); }
00580     else { path = SiStripKey(); }
00581     
00582     // Check path is valid
00583     if ( path.granularity() == sistrip::FEC_SYSTEM ||
00584          path.granularity() == sistrip::FED_SYSTEM || 
00585          path.granularity() == sistrip::UNKNOWN_GRAN ||
00586          path.granularity() == sistrip::UNDEFINED_GRAN ) { 
00587       continue; 
00588     }
00589     
00590     // Generate corresponding client path (removing trailing "/")
00591     std::string client_dir(sistrip::undefinedView_);
00592     if ( view == sistrip::CONTROL_VIEW ) { client_dir = SiStripFecKey( path.key() ).path(); }
00593     else if ( view == sistrip::READOUT_VIEW ) { client_dir = SiStripFedKey( path.key() ).path(); }
00594     else { client_dir = SiStripKey( path.key() ).path(); }
00595     std::string slash = client_dir.substr( client_dir.size()-1, 1 ); 
00596     if ( slash == sistrip::dir_ ) { client_dir = client_dir.substr( 0, client_dir.size()-1 ); }
00597     client_dir = sistrip::collate_ + sistrip::dir_ + client_dir;
00598 
00599     // Retrieve MonitorElements from pwd directory
00600     bei_->setCurrentFolder( source_dir );
00601     std::vector<std::string> me_list = bei_->getMEs();
00602 
00603     // Iterate through MonitorElements and create CMEs
00604     std::vector<std::string>::iterator ime = me_list.begin(); 
00605     for ( ; ime != me_list.end(); ime++ ) {
00606       
00607       // Retrieve histogram title
00608       SiStripHistoTitle title( *ime );
00609 
00610       // Check histogram type
00611       //if ( title.histoType() != sistrip::EXPERT_HISTO ) { continue; }
00612       
00613       // Check granularity
00614       uint16_t channel = sistrip::invalid_;
00615       if ( title.granularity() == sistrip::APV ) {
00616         channel = SiStripFecKey::lldChan( title.channel() );
00617       } else if ( title.granularity() == sistrip::UNKNOWN_GRAN || 
00618                   title.granularity() == sistrip::UNDEFINED_GRAN ) {
00619         edm::LogError(mlDqmClient_)
00620           << "[CommissioningHistograms::" << __func__ << "]"
00621           << " Unexpected granularity for histogram title: "
00622           << title << " found in path " << path;
00623       } else {
00624         channel = title.channel();
00625       }
00626       
00627       // Build key 
00628       uint32_t key = sistrip::invalid32_;
00629 
00630       if ( view == sistrip::CONTROL_VIEW ) { 
00631 
00632         // for all runs except cabling
00633         SiStripFecKey temp( path.key() ); 
00634         key = SiStripFecKey( temp.fecCrate(),
00635                              temp.fecSlot(),
00636                              temp.fecRing(),
00637                              temp.ccuAddr(),
00638                              temp.ccuChan(),
00639                              channel ).key();
00640         mapping_[title.keyValue()] = key;
00641 
00642       } else if ( view == sistrip::READOUT_VIEW ) { 
00643 
00644         // for cabling run
00645         key = SiStripFedKey( path.key() ).key();
00646         uint32_t temp = SiStripFecKey( sistrip::invalid_,
00647                                        sistrip::invalid_,
00648                                        sistrip::invalid_,
00649                                        sistrip::invalid_,
00650                                        sistrip::invalid_,
00651                                        channel ).key(); // just record lld channel
00652         mapping_[title.keyValue()] = temp;
00653 
00654       } else { key = SiStripKey( path.key() ).key(); }
00655       
00656       // Find CME in histos map
00657       Histo* histo = 0;
00658       HistosMap::iterator ihistos = histos_.find( key );
00659       if ( ihistos != histos_.end() ) { 
00660         Histos::iterator ihis = ihistos->second.begin();
00661         while ( !histo && ihis < ihistos->second.end() ) {
00662           if ( (*ime) == (*ihis)->title_ ) { histo = *ihis; }
00663           ihis++;
00664         }
00665       }
00666       
00667       // Create CollateME if it doesn't exist
00668       if ( !histo ) {
00669 
00670         // Retrieve ME pointer
00671         MonitorElement* me = bei_->get( bei_->pwd()+"/"+(*ime) );
00672         
00673         // Check if profile or 1D
00674         TProfile* prof = ExtractTObject<TProfile>().extract( me );
00675         TH1F* his = ExtractTObject<TH1F>().extract( me );
00676 
00677         // Create CollateME and extract pointer to ME
00678         if ( prof || his ) { 
00679           histos_[key].push_back( new Histo() );
00680           histo = histos_[key].back();
00681           histo->title_ = *ime;
00682           if ( prof ) {
00683             prof->SetErrorOption("s"); //@@ necessary?
00684             histo->cme_ = mui_->collateProf( (*ime), (*ime), client_dir ); 
00685           } else if ( his ) {
00686             histo->cme_ = mui_->collate1D( (*ime), (*ime), client_dir ); 
00687           }
00688           if ( histo->cme_ ) { 
00689             mui_->add( histo->cme_, bei_->pwd()+"/"+(*ime) );
00690             histo->me_ = histo->cme_->getMonitorElement(); 
00691           }
00692         }
00693         
00694       }
00695 
00696       // Add to CollateME if found in histos map
00697       HistosMap::iterator jhistos = histos_.find( key );
00698       if ( jhistos != histos_.end() ) { 
00699         Histos::iterator ihis = jhistos->second.begin();
00700         while ( ihis < jhistos->second.end() ) {
00701           if ( (*ime) == (*ihis)->title_ ) { 
00702             if ( (*ihis)->cme_ ) {
00703               mui_->add( (*ihis)->cme_, bei_->pwd()+"/"+(*ime) );
00704             }
00705             break; 
00706           }
00707           ihis++;
00708         }
00709       }
00710       
00711     }
00712   }
00713   
00714   //printHistosMap();
00715 
00716   edm::LogVerbatim(mlDqmClient_)
00717     << "[CommissioningHistograms::" << __func__ << "]"
00718     << " Found histograms for " << histos_.size()
00719     << " structures in cached histogram map!";
00720   
00721 #endif
00722 
00723 }
00724 
00725 // -----------------------------------------------------------------------------
00727 void CommissioningHistograms::histoAnalysis( bool debug ) {
00728   LogTrace(mlDqmClient_)
00729     << "[CommissioningHistograms::" << __func__ << "]"
00730     << " (Derived) implementation to come...";
00731 }
00732 
00733 // -----------------------------------------------------------------------------
00735 void CommissioningHistograms::printAnalyses() {
00736   Analyses::iterator ianal = data().begin();
00737   Analyses::iterator janal = data().end();
00738   for ( ; ianal != janal; ++ianal ) { 
00739     if ( ianal->second ) { 
00740       std::stringstream ss;
00741       ianal->second->print( ss ); 
00742       if ( ianal->second->isValid() ) { LogTrace(mlDqmClient_) << ss.str(); 
00743       } else { edm::LogWarning(mlDqmClient_) << ss.str(); }
00744     }
00745   }
00746 }
00747 
00748 // -----------------------------------------------------------------------------
00750 void CommissioningHistograms::printSummary() {
00751 
00752   std::stringstream good;
00753   std::stringstream bad;
00754   
00755   Analyses::iterator ianal = data().begin();
00756   Analyses::iterator janal = data().end();
00757   for ( ; ianal != janal; ++ianal ) { 
00758     if ( ianal->second ) { 
00759       if ( ianal->second->isValid() ) { ianal->second->summary( good ); }
00760       else { ianal->second->summary( bad ); }
00761     }
00762   }
00763 
00764   if ( good.str().empty() ) { good << "None found!"; }
00765   LogTrace(mlDqmClient_) 
00766     << "[CommissioningHistograms::" << __func__ << "]"
00767     << " Printing summary of good analyses:" << "\n"
00768     << good.str();
00769   
00770   if ( bad.str().empty() ) { return; } //@@ bad << "None found!"; }
00771   LogTrace(mlDqmClient_) 
00772     << "[CommissioningHistograms::" << __func__ << "]"
00773     << " Printing summary of bad analyses:" << "\n"
00774     << bad.str();
00775   
00776 }
00777 
00778 // -----------------------------------------------------------------------------
00780 void CommissioningHistograms::printHistosMap() {
00781   LogTrace(mlDqmClient_)
00782     << "[CommissioningHistograms::" << __func__ << "]"
00783     << " Printing histogram map, which has "
00784     << histos_.size() << " entries...";
00785   HistosMap::const_iterator ihistos = histos_.begin();
00786   for ( ; ihistos != histos_.end(); ihistos++ ) {
00787     std::stringstream ss;
00788     ss << " Found " << ihistos->second.size()
00789        << " histogram(s) for key: " << std::endl
00790        << SiStripFedKey(ihistos->first) << std::endl;
00791     Histos::const_iterator ihisto = ihistos->second.begin();
00792     for ( ; ihisto != ihistos->second.end(); ihisto++ ) {
00793       if ( *ihisto ) { (*ihisto)->print(ss); }
00794       else { ss << " NULL pointer to Histo object!"; }
00795     }
00796     LogTrace(mlDqmClient_) << ss.str();
00797   }
00798 }
00799 
00800 // -----------------------------------------------------------------------------
00802 void CommissioningHistograms::clearHistosMap() {
00803   LogTrace(mlDqmClient_)
00804     << "[CommissioningHistograms::" << __func__ << "]"
00805     << " Clearing histogram map...";
00806   HistosMap::iterator ihistos = histos_.begin();
00807   for ( ; ihistos != histos_.end(); ihistos++ ) {
00808     Histos::iterator ihisto = ihistos->second.begin();
00809     for ( ; ihisto != ihistos->second.end(); ihisto++ ) {
00810       if ( *ihisto ) { delete *ihisto; }
00811     }
00812     ihistos->second.clear();
00813   }
00814   histos_.clear();
00815 }
00816 
00817 // -----------------------------------------------------------------------------
00819 void CommissioningHistograms::createSummaryHisto( const sistrip::Monitorable& mon, 
00820                                                   const sistrip::Presentation& pres, 
00821                                                   const std::string& dir,
00822                                                   const sistrip::Granularity& gran ) {
00823   LogTrace(mlDqmClient_)
00824     << "[CommissioningHistograms::" << __func__ << "]";
00825   
00826   // Check view 
00827   sistrip::View view = SiStripEnumsAndStrings::view(dir);
00828   if ( view == sistrip::UNKNOWN_VIEW ) { return; }
00829   
00830   // Analyze histograms
00831   if ( data().empty() ) { histoAnalysis( false ); }
00832 
00833   // Check
00834   if ( data().empty() ) { 
00835     edm::LogError(mlDqmClient_)
00836       << "[CommissioningHistograms::" << __func__ << "]"
00837       << " No analyses generated!";
00838     return;
00839   }
00840   
00841   // Extract data to be histogrammed
00842   uint32_t xbins = factory()->init( mon, pres, view, dir, gran, data() );
00843   
00844   // Only create histograms if entries are found!
00845   if ( !xbins ) { return; }
00846   
00847   // Create summary histogram (if it doesn't already exist)
00848   TH1* summary = 0;
00849   if ( pres != sistrip::HISTO_1D ) { summary = histogram( mon, pres, view, dir, xbins ); }
00850   else { summary = histogram( mon, pres, view, dir, sistrip::FED_ADC_RANGE, 0., sistrip::FED_ADC_RANGE*1. ); }
00851   
00852   // Fill histogram with data
00853   factory()->fill( *summary );
00854   
00855 }
00856 
00857 // -----------------------------------------------------------------------------
00859 void CommissioningHistograms::remove( std::string pattern ) {
00860   
00861   if ( !mui_ ) { 
00862     edm::LogError(mlDqmClient_)
00863       << "[CommissioningHistograms::" << __func__ << "]"
00864       << " NULL pointer to DQMOldReceiver!"; 
00865     return;
00866   }
00867 
00868   if ( !mui_->getBEInterface() ) { 
00869     edm::LogError(mlDqmClient_)
00870       << "[CommissioningHistograms::" << __func__ << "]"
00871       << " NULL pointer to DQMStore!"; 
00872     return;
00873   }
00874   
00875   mui_->getBEInterface()->setVerbose(0);
00876 
00877   LogTrace(mlDqmClient_)
00878     << "[CommissioningHistograms::" << __func__ << "]"
00879     << " Removing histograms...";
00880   
00881   if ( !pattern.empty() ) {
00882     
00883     if ( mui_->getBEInterface()->dirExists(pattern) ) {
00884       mui_->getBEInterface()->rmdir(pattern); 
00885     }
00886     
00887     LogTrace(mlDqmClient_)
00888       << "[CommissioningHistograms::" << __func__ << "]"
00889       << " Removing directories (and MonitorElements"
00890       << " therein) that match the pattern \""
00891       << pattern << "\"";
00892     
00893   } else {
00894     
00895     mui_->getBEInterface()->cd();
00896     mui_->getBEInterface()->removeContents(); 
00897     
00898     if( mui_->getBEInterface()->dirExists("Collector") ) {
00899       mui_->getBEInterface()->rmdir("Collector");
00900     }
00901     if( mui_->getBEInterface()->dirExists("EvF") ) {
00902       mui_->getBEInterface()->rmdir("EvF");
00903     }
00904     if( mui_->getBEInterface()->dirExists("SiStrip") ) {
00905       mui_->getBEInterface()->rmdir("SiStrip");
00906     }
00907 
00908     LogTrace(mlDqmClient_)
00909       << "[CommissioningHistograms::" << __func__ << "]"
00910       << " Removing \"DQM source\" directories (and MonitorElements therein)";
00911     
00912   }
00913 
00914   LogTrace(mlDqmClient_)
00915     << "[CommissioningHistograms::" << __func__ << "]"
00916     << " Removed histograms!";
00917 
00918   mui_->getBEInterface()->setVerbose(1);
00919 
00920 }
00921 
00922 // -----------------------------------------------------------------------------
00924 void CommissioningHistograms::save( std::string& path,
00925                                     uint32_t run_number ) {
00926   
00927   if ( !mui_ ) { 
00928     edm::LogError(mlDqmClient_)
00929       << "[CommissioningHistograms::" << __func__ << "]"
00930       << " NULL pointer to DQMOldReceiver!"; 
00931     return;
00932   }
00933 
00934   // Construct path and filename
00935   std::stringstream ss; 
00936 
00937   if ( !path.empty() ) { 
00938 
00939     ss << path; 
00940     if ( ss.str().find(".root") == std::string::npos ) { ss << ".root"; }
00941 
00942   } else {
00943 
00944     // Retrieve SCRATCH directory
00945     std::string scratch = "SCRATCH";
00946     std::string dir = "";
00947     if ( getenv(scratch.c_str()) != NULL ) { 
00948       dir = getenv(scratch.c_str()); 
00949     }
00950     
00951     // Add directory path 
00952     if ( !dir.empty() ) { ss << dir << "/"; }
00953     else { ss << "/tmp/"; }
00954     
00955     // Add filename with run number and ".root" extension
00956     ss << sistrip::dqmClientFileName_ << "_" 
00957        << std::setfill('0') << std::setw(8) << run_number
00958        << ".root";
00959     
00960   }
00961   
00962   // Save file with appropriate filename
00963   LogTrace(mlDqmClient_)
00964     << "[CommissioningHistograms::" << __func__ << "]"
00965     << " Saving histograms to root file"
00966     << " (This may take some time!)";
00967   path = ss.str();
00968   bei_->save( path, sistrip::collate_ ); 
00969   edm::LogVerbatim(mlDqmClient_)
00970     << "[CommissioningHistograms::" << __func__ << "]"
00971     << " Saved histograms to root file \""
00972     << ss.str() << "\"!";
00973   
00974 }
00975 
00976 // -----------------------------------------------------------------------------
00977 // 
00978 TH1* CommissioningHistograms::histogram( const sistrip::Monitorable& mon, 
00979                                          const sistrip::Presentation& pres, 
00980                                          const sistrip::View& view,
00981                                          const std::string& directory,
00982                                          const uint32_t& xbins, 
00983                                          const float& xlow,
00984                                          const float& xhigh ) {
00985   
00986   // Remember pwd 
00987   std::string pwd = bei_->pwd();
00988   bei_->setCurrentFolder( sistrip::collate_ + sistrip::dir_ + directory );
00989   
00990   // Construct histogram name 
00991   std::string name = SummaryGenerator::name( task_, mon, pres, view, directory );
00992   
00993   // Check if summary plot already exists and remove
00994   MonitorElement* me = bei_->get( bei_->pwd() + "/" + name );
00995   if ( me ) { 
00996     mui_->getBEInterface()->removeElement( name );
00997     me = 0;
00998   } 
00999   
01000   // Create summary plot
01001   float high = static_cast<float>( xbins );
01002   if ( pres == sistrip::HISTO_1D ) { 
01003     if ( xlow < 1. * sistrip::valid_ && 
01004          xhigh < 1. * sistrip::valid_ ) { 
01005       me = mui_->getBEInterface()->book1D( name, name, xbins, xlow, xhigh ); 
01006     } else {
01007       me = mui_->getBEInterface()->book1D( name, name, xbins, 0., high ); 
01008     }
01009   } else if ( pres == sistrip::HISTO_2D_SUM ) { 
01010     me = mui_->getBEInterface()->book1D( name, name, 
01011                                          xbins, 0., high ); 
01012   } else if ( pres == sistrip::HISTO_2D_SCATTER ) { 
01013     me = mui_->getBEInterface()->book2D( name, name, xbins, 0., high, 
01014                                          sistrip::FED_ADC_RANGE+1, 
01015                                          0., 
01016                                          sistrip::FED_ADC_RANGE*1. ); 
01017   } else if ( pres == sistrip::PROFILE_1D ) { 
01018     me = mui_->getBEInterface()->bookProfile( name, name, xbins, 0., high, 
01019                                               sistrip::FED_ADC_RANGE+1, 
01020                                               0., 
01021                                               sistrip::FED_ADC_RANGE*1. ); 
01022   } else { 
01023     me = 0; 
01024     edm::LogWarning(mlDqmClient_)
01025       << "[CommissioningHistograms::" << __func__ << "]"
01026       << " Unexpected presentation \"" 
01027       << SiStripEnumsAndStrings::presentation( pres )
01028       << "\" Unable to create summary plot!";
01029   }
01030   
01031   // Check pointer
01032   if ( me ) { 
01033     LogTrace(mlDqmClient_)
01034       << "[CommissioningHistograms::" << __func__ << "]"
01035       << " Created summary plot with name \"" << me->getName()
01036       << "\" in directory \""
01037       << bei_->pwd() << "\"!"; 
01038   } else {
01039     edm::LogWarning(mlDqmClient_)
01040       << "[CommissioningHistograms::" << __func__ << "]"
01041       << " NULL pointer to MonitorElement!"
01042       << " Unable to create summary plot!";
01043   }
01044   
01045   // Extract root object
01046   TH1* summary = ExtractTObject<TH1>().extract( me ); 
01047   if ( !summary ) {
01048     edm::LogWarning(mlDqmClient_)
01049       << "[CommissioningHistograms::" << __func__ << "]"
01050       << " Unable to extract root object!"
01051       << " Returning NULL pointer!"; 
01052   }
01053   
01054   // Return to pwd
01055   bei_->setCurrentFolder( pwd );
01056   
01057   return summary;
01058   
01059 }
01060 

Generated on Tue Jun 9 17:33:28 2009 for CMSSW by  doxygen 1.5.4