Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:14

0001 
0002 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
0003 #include "DataFormats/SiStripCommon/interface/SiStripKey.h"
0004 #include "DataFormats/SiStripCommon/interface/Constants.h"
0005 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0006 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0007 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
0008 #include <iostream>
0009 #include <iomanip>
0010 
0011 // -----------------------------------------------------------------------------
0012 //
0013 SiStripHistoTitle::SiStripHistoTitle(const sistrip::HistoType& histo_type,
0014                                      const sistrip::RunType& run_type,
0015                                      const SiStripKey& key_object,
0016                                      const std::string& extra_info)
0017     : title_(""),
0018       histoType_(histo_type),
0019       runType_(run_type),
0020       keyType_(sistrip::UNKNOWN_KEY),
0021       keyValue_(sistrip::invalid32_),
0022       granularity_(sistrip::UNKNOWN_GRAN),
0023       channel_(sistrip::invalid_),
0024       extraInfo_(extra_info) {
0025   if (&dynamic_cast<const SiStripFedKey&>(key_object)) {
0026     keyType_ = sistrip::FED_KEY;
0027   } else if (&dynamic_cast<const SiStripFecKey&>(key_object)) {
0028     keyType_ = sistrip::FEC_KEY;
0029   } else {
0030     keyType_ = sistrip::UNKNOWN_KEY;
0031   }
0032   keyValue_ = key_object.key();
0033   granularity_ = key_object.granularity();
0034   channel_ = key_object.channel();
0035   setTitle();
0036 }
0037 
0038 // -----------------------------------------------------------------------------
0039 //
0040 SiStripHistoTitle::SiStripHistoTitle(const sistrip::HistoType& histo_type,
0041                                      const sistrip::RunType& run_type,
0042                                      const sistrip::KeyType& key_type,
0043                                      const uint32_t& key_value,
0044                                      const sistrip::Granularity& gran,
0045                                      const uint16_t& channel,
0046                                      const std::string& extra_info)
0047     : title_(""),
0048       histoType_(histo_type),
0049       runType_(run_type),
0050       keyType_(key_type),
0051       keyValue_(key_value),
0052       granularity_(gran),
0053       channel_(channel),
0054       extraInfo_(extra_info) {
0055   setTitle();
0056 }
0057 
0058 // -----------------------------------------------------------------------------
0059 //
0060 SiStripHistoTitle::SiStripHistoTitle(const std::string& histo_title)
0061     : title_(histo_title),
0062       histoType_(sistrip::UNDEFINED_HISTO_TYPE),
0063       runType_(sistrip::UNDEFINED_RUN_TYPE),
0064       keyType_(sistrip::UNDEFINED_KEY),
0065       keyValue_(sistrip::invalid32_),
0066       granularity_(sistrip::UNDEFINED_GRAN),
0067       channel_(sistrip::invalid_),
0068       extraInfo_("") {
0069   extractTitle();
0070 }
0071 
0072 // -----------------------------------------------------------------------------
0073 //
0074 void SiStripHistoTitle::setTitle() {
0075   std::stringstream title;
0076 
0077   // Append HistoType, RunType, KeyType and KeyValue
0078   title << SiStripEnumsAndStrings::histoType(histoType_) << sistrip::sep_ << SiStripEnumsAndStrings::runType(runType_)
0079         << sistrip::sep_ << SiStripEnumsAndStrings::keyType(keyType_) << sistrip::hex_ << std::setfill('0')
0080         << std::setw(8) << std::hex << keyValue_ << std::dec << sistrip::sep_;
0081 
0082   // Append Granularity and channel number
0083   title << SiStripEnumsAndStrings::granularity(granularity_);
0084   if (channel_) {
0085     title << channel_;
0086   }
0087 
0088   // Append extra info
0089   if (!extraInfo_.empty()) {
0090     title << sistrip::sep_ << extraInfo_;
0091   }
0092 
0093   title_ = title.str();
0094 }
0095 
0096 // -----------------------------------------------------------------------------
0097 //
0098 void SiStripHistoTitle::extractTitle() {
0099   std::string::size_type length = title_.length();
0100   std::string::size_type position = 0;
0101   std::string::size_type pos = 0;
0102   std::string::size_type siz = 0;
0103 
0104   // Extract HistoType
0105   siz = title_.find(sistrip::sep_, position) - position;
0106   histoType_ = SiStripEnumsAndStrings::histoType(title_.substr(position, siz));
0107   std::string histo_type = SiStripEnumsAndStrings::histoType(histoType_);
0108   position += title_.substr(position).find(histo_type) + histo_type.size() + (sizeof(sistrip::sep_) - 1);
0109   if (histoType_ == sistrip::UNKNOWN_HISTO_TYPE) {
0110     position = 0;
0111   } else if (position >= length) {
0112     return;
0113   }
0114 
0115   // Extract RunType
0116   siz = title_.find(sistrip::sep_, position) - position;
0117   runType_ = SiStripEnumsAndStrings::runType(title_.substr(position, siz));
0118   std::string run_type = SiStripEnumsAndStrings::runType(runType_);
0119   position += title_.substr(position).find(run_type) + run_type.size() + (sizeof(sistrip::sep_) - 1);
0120   if (position >= length) {
0121     return;
0122   }
0123 
0124   // Extract KeyType
0125   siz = title_.find(sistrip::sep_, position) - position;
0126   keyType_ = SiStripEnumsAndStrings::keyType(title_.substr(position, siz));
0127   std::string key_type = SiStripEnumsAndStrings::keyType(keyType_);
0128   position += title_.substr(position).find(key_type) + key_type.size() + (sizeof(sistrip::hex_) - 1);
0129   if (position >= length) {
0130     return;
0131   }
0132 
0133   // Extract KeyValue
0134   siz = 8;
0135   std::stringstream key;
0136   key << title_.substr(position, siz);
0137   key >> std::hex >> keyValue_;
0138   position += siz + (sizeof(sistrip::sep_) - 1);
0139   if (position >= length) {
0140     return;
0141   }
0142 
0143   // Extract Granularity
0144   pos = title_.find(sistrip::sep_, position);
0145   if (pos == std::string::npos || pos < position) {
0146     siz = std::string::npos - position;
0147   } else {
0148     siz = pos - position;
0149   }
0150   granularity_ = SiStripEnumsAndStrings::granularity(title_.substr(position, siz));
0151   std::string gran = SiStripEnumsAndStrings::granularity(granularity_);
0152   position += title_.substr(position).find(gran) + gran.size();
0153   if (position > length) {
0154     return;
0155   }
0156 
0157   // Extract Channel
0158   pos = title_.find(sistrip::sep_, position);
0159   if (pos == std::string::npos || pos < position) {
0160     siz = std::string::npos - position;
0161   } else {
0162     siz = pos - position;
0163   }
0164   if (position == length || !siz) {
0165     if (granularity_ != sistrip::UNDEFINED_GRAN) {
0166       channel_ = 0;
0167     } else if (granularity_ == sistrip::UNKNOWN_GRAN) {
0168       channel_ = sistrip::invalid_;
0169     }
0170   } else {
0171     std::stringstream chan;
0172     chan << title_.substr(position, siz);
0173     chan >> std::dec >> channel_;
0174   }
0175   position += siz + (sizeof(sistrip::sep_) - 1);
0176   if (position >= length) {
0177     return;
0178   }
0179 
0180   // Extract ExtraInfo
0181   extraInfo_ = title_.substr(position, std::string::npos - position);
0182 }
0183 
0184 // -----------------------------------------------------------------------------
0185 //
0186 std::ostream& operator<<(std::ostream& os, const SiStripHistoTitle& title) {
0187   std::stringstream ss;
0188   ss << "[SiStripHistoTitle::print]" << std::endl
0189      << " Title          : " << title.title() << std::endl
0190      << " HistoType      : " << SiStripEnumsAndStrings::histoType(title.histoType()) << std::endl
0191      << " RunType        : " << SiStripEnumsAndStrings::runType(title.runType()) << std::endl
0192      << " KeyType        : " << SiStripEnumsAndStrings::keyType(title.keyType()) << std::endl
0193      << " KeyValue (hex) : " << std::hex << std::setfill('0') << std::setw(8) << title.keyValue() << std::dec
0194      << std::endl
0195      << " Granularity    : " << SiStripEnumsAndStrings::granularity(title.granularity()) << std::endl
0196      << " Channel        : " << title.channel() << std::endl
0197      << " ExtraInfo      : ";
0198   if (!title.extraInfo().empty()) {
0199     ss << "\"" << title.extraInfo() << "\"";
0200   } else {
0201     ss << "(none)";
0202   }
0203   os << ss.str();
0204   return os;
0205 }