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