CMS 3D CMS Logo

SiStripHistoTitle.cc

Go to the documentation of this file.
00001 // Last commit: $Id: SiStripHistoTitle.cc,v 1.6 2007/07/31 15:20:25 ratnik Exp $
00002 
00003 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripKey.h"
00005 #include "DataFormats/SiStripCommon/interface/Constants.h" 
00006 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00007 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00008 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00009 #include <iostream>
00010 #include <iomanip>
00011 
00012 // -----------------------------------------------------------------------------
00013 //
00014 SiStripHistoTitle::SiStripHistoTitle( const sistrip::HistoType& histo_type, 
00015                                       const sistrip::RunType&   run_type, 
00016                                       const SiStripKey&         key_object,
00017                                       const std::string&        extra_info ) 
00018   : title_(""),
00019     histoType_(histo_type),
00020     runType_(run_type),
00021     keyType_(sistrip::UNKNOWN_KEY),
00022     keyValue_(sistrip::invalid32_),
00023     granularity_(sistrip::UNKNOWN_GRAN),
00024     channel_(sistrip::invalid_),
00025     extraInfo_(extra_info)
00026 {
00027   SiStripKey& temp = const_cast<SiStripKey&>(key_object);
00028   if ( &dynamic_cast<SiStripFedKey&>(temp) ) {
00029     keyType_ = sistrip::FED_KEY;
00030   } else if ( &dynamic_cast<SiStripFecKey&>(temp) ) {
00031     keyType_ = sistrip::FEC_KEY;
00032   } else {
00033     keyType_ = sistrip::UNKNOWN_KEY;
00034   }
00035   if ( &key_object ) {
00036     keyValue_ = key_object.key();
00037     granularity_ = key_object.granularity();
00038     channel_ = key_object.channel();
00039   }
00040   setTitle();
00041 }
00042 
00043 // -----------------------------------------------------------------------------
00044 //
00045 SiStripHistoTitle::SiStripHistoTitle( const sistrip::HistoType&   histo_type, 
00046                                       const sistrip::RunType&     run_type, 
00047                                       const sistrip::KeyType&     key_type,
00048                                       const uint32_t&             key_value,
00049                                       const sistrip::Granularity& gran,
00050                                       const uint16_t&             channel,
00051                                       const std::string&          extra_info ) 
00052   : title_(""),
00053     histoType_(histo_type),
00054     runType_(run_type),
00055     keyType_(key_type),
00056     keyValue_(key_value),
00057     granularity_(gran),
00058     channel_(channel),
00059     extraInfo_(extra_info)
00060 {
00061   setTitle();
00062 }
00063 
00064 // -----------------------------------------------------------------------------
00065 //
00066 SiStripHistoTitle::SiStripHistoTitle( const std::string& histo_title ) 
00067   : title_(histo_title),
00068     histoType_(sistrip::UNDEFINED_HISTO_TYPE),
00069     runType_(sistrip::UNDEFINED_RUN_TYPE),
00070     keyType_(sistrip::UNDEFINED_KEY),
00071     keyValue_(sistrip::invalid32_),
00072     granularity_(sistrip::UNDEFINED_GRAN),
00073     channel_(sistrip::invalid_),
00074     extraInfo_("")
00075 {
00076   extractTitle();
00077 }
00078 
00079 // -----------------------------------------------------------------------------
00080 //
00081 void SiStripHistoTitle::setTitle() {
00082 
00083   std::stringstream title;
00084 
00085   // Append HistoType, RunType, KeyType and KeyValue
00086   title << SiStripEnumsAndStrings::histoType( histoType_ )
00087         << sistrip::sep_
00088         << SiStripEnumsAndStrings::runType( runType_ )
00089         << sistrip::sep_
00090         << SiStripEnumsAndStrings::keyType( keyType_ )
00091         << sistrip::hex_ 
00092         << std::setfill('0') << std::setw(8) << std::hex << keyValue_ << std::dec
00093         << sistrip::sep_;
00094   
00095   // Append Granularity and channel number
00096   title << SiStripEnumsAndStrings::granularity( granularity_ );
00097   if ( channel_ ) { title << channel_; }
00098   
00099   // Append extra info
00100   if ( extraInfo_ != "" ) { 
00101     title << sistrip::sep_ << extraInfo_; 
00102   }
00103   
00104   title_ = title.str();
00105 
00106 }
00107 
00108 // -----------------------------------------------------------------------------
00109 // 
00110 void SiStripHistoTitle::extractTitle() {
00111   
00112   std::string::size_type length = title_.length();
00113   std::string::size_type position = 0;
00114   std::string::size_type pos = 0;
00115   std::string::size_type siz = 0;
00116   
00117   // Extract HistoType
00118   siz = title_.find(sistrip::sep_,position) - position;
00119   histoType_ = SiStripEnumsAndStrings::histoType( title_.substr(position,siz) );
00120   std::string histo_type = SiStripEnumsAndStrings::histoType( histoType_ );
00121   position += title_.substr(position).find( histo_type ) + histo_type.size() + sistrip::sep_.size();
00122   if ( histoType_ == sistrip::UNKNOWN_HISTO_TYPE ) { position = 0; }
00123   else if ( position >= length ) { return; }
00124   
00125   // Extract RunType
00126   siz = title_.find(sistrip::sep_,position) - position;
00127   runType_ = SiStripEnumsAndStrings::runType( title_.substr(position,siz) );
00128   std::string run_type = SiStripEnumsAndStrings::runType( runType_ );
00129   position += title_.substr(position).find( run_type ) + run_type.size() + sistrip::sep_.size();
00130   if ( position >= length ) { return; }
00131   
00132   // Extract KeyType
00133   siz = title_.find(sistrip::sep_,position) - position;
00134   keyType_ = SiStripEnumsAndStrings::keyType( title_.substr(position,siz) );
00135   std::string key_type = SiStripEnumsAndStrings::keyType( keyType_ );
00136   position += title_.substr(position).find( key_type ) + key_type.size() + sistrip::hex_.size();
00137   if ( position >= length ) { return; }
00138   
00139   // Extract KeyValue
00140   siz = 8;
00141   std::stringstream key; 
00142   key << title_.substr(position,siz);
00143   key >> std::hex >> keyValue_;
00144   position += siz + sistrip::sep_.size();
00145   if ( position >= length ) { return; }
00146   
00147   // Extract Granularity
00148   pos = title_.find(sistrip::sep_,position);
00149   if ( pos == std::string::npos || pos < position ) { siz = std::string::npos - position; }
00150   else { siz = pos - position; }
00151   granularity_ = SiStripEnumsAndStrings::granularity( title_.substr(position,siz) );
00152   std::string gran = SiStripEnumsAndStrings::granularity( granularity_ );
00153   position += title_.substr(position).find( gran ) + gran.size();
00154   if ( position > length ) { return; }
00155 
00156   // Extract Channel 
00157   pos = title_.find(sistrip::sep_,position);
00158   if ( pos == std::string::npos || pos < position ) { siz = std::string::npos - position; }
00159   else { siz = pos - position; }
00160   if ( position == length || !siz ) {
00161     if ( granularity_ != sistrip::UNDEFINED_GRAN ) { channel_ = 0; }
00162     else if ( granularity_ == sistrip::UNKNOWN_GRAN ) { channel_ = sistrip::invalid_; }
00163   } else {
00164     std::stringstream chan; 
00165     chan << title_.substr(position,siz);
00166     chan >> std::dec >> channel_;
00167   }
00168   position += siz + sistrip::sep_.size();
00169   if ( position >= length ) { return; }
00170   
00171   // Extract ExtraInfo
00172   extraInfo_ = title_.substr( position, std::string::npos - position ); 
00173   
00174 }
00175 
00176 // -----------------------------------------------------------------------------
00177 //
00178 std::ostream& operator<< ( std::ostream& os, const SiStripHistoTitle& title ) {
00179   std::stringstream ss;
00180   ss << "[SiStripHistoTitle::print]" << std::endl
00181      << " Title          : " << title.title() << std::endl
00182      << " HistoType      : " << SiStripEnumsAndStrings::histoType( title.histoType() ) << std::endl
00183      << " RunType        : " << SiStripEnumsAndStrings::runType( title.runType() ) << std::endl
00184      << " KeyType        : " << SiStripEnumsAndStrings::keyType( title.keyType() ) << std::endl
00185      << " KeyValue (hex) : " << std::hex << std::setfill('0') << std::setw(8) << title.keyValue() << std::dec << std::endl
00186      << " Granularity    : " << SiStripEnumsAndStrings::granularity( title.granularity() ) << std::endl
00187      << " Channel        : " << title.channel() << std::endl
00188      << " ExtraInfo      : ";
00189   if ( title.extraInfo() != "" ) { ss << "\"" << title.extraInfo() << "\""; }
00190   else { ss << "(none)"; }
00191   os << ss.str();
00192   return os;
00193 }
00194 

Generated on Tue Jun 9 17:31:45 2009 for CMSSW by  doxygen 1.5.4