Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-27 23:38:18

0001 // system includes
0002 #include <iostream>
0003 #include <iomanip>
0004 #include <sstream>
0005 #include <string>
0006 #include <vector>
0007 
0008 // user includes
0009 #include "DataFormats/SiStripCommon/interface/Constants.h"
0010 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0011 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
0012 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0013 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 
0018 /**
0019    @class testSiStripHistoTitle 
0020    @author R.Bainbridge
0021    @brief Simple class that tests SiStripHistoTitle.
0022 */
0023 class testSiStripHistoTitle : public edm::one::EDAnalyzer<> {
0024 public:
0025   testSiStripHistoTitle(const edm::ParameterSet&);
0026   ~testSiStripHistoTitle();
0027 
0028   void beginJob();
0029   void analyze(const edm::Event&, const edm::EventSetup&);
0030 };
0031 
0032 using namespace sistrip;
0033 
0034 // -----------------------------------------------------------------------------
0035 //
0036 testSiStripHistoTitle::testSiStripHistoTitle(const edm::ParameterSet& pset) {
0037   LogTrace(mlDqmCommon_) << "[testSiStripHistoTitle::" << __func__ << "]"
0038                          << " Constructing object...";
0039 }
0040 
0041 // -----------------------------------------------------------------------------
0042 //
0043 testSiStripHistoTitle::~testSiStripHistoTitle() {
0044   LogTrace(mlDqmCommon_) << "[testSiStripHistoTitle::" << __func__ << "]"
0045                          << " Destructing object...";
0046 }
0047 
0048 // -----------------------------------------------------------------------------
0049 //
0050 void testSiStripHistoTitle::beginJob() {
0051   LogTrace(mlDqmCommon_) << "[SiStripHistoTitle::" << __func__ << "]"
0052                          << " Checking HistoTitle...";
0053 
0054   // Build vectors containing HistoType, RunType, KeyType, Granularity
0055 
0056   std::vector<sistrip::HistoType> histo_types;
0057   {
0058     bool first = true;
0059     for (uint32_t cntr = 0; cntr <= sistrip::invalid_; cntr++) {
0060       sistrip::HistoType in = static_cast<sistrip::HistoType>(cntr);
0061       std::string str = SiStripEnumsAndStrings::histoType(in);
0062       sistrip::HistoType out = SiStripEnumsAndStrings::histoType(str);
0063       if (out != sistrip::UNKNOWN_HISTO_TYPE || (out == sistrip::UNKNOWN_HISTO_TYPE && first)) {
0064         first = false;
0065         if (out != sistrip::UNKNOWN_HISTO_TYPE) {
0066           histo_types.push_back(in);
0067         }
0068       }
0069     }
0070   }
0071 
0072   std::vector<sistrip::RunType> run_types;
0073   {
0074     bool first = true;
0075     for (uint32_t cntr = 0; cntr <= sistrip::invalid_; cntr++) {
0076       sistrip::RunType in = static_cast<sistrip::RunType>(cntr);
0077       std::string str = SiStripEnumsAndStrings::runType(in);
0078       sistrip::RunType out = SiStripEnumsAndStrings::runType(str);
0079       if (out != sistrip::UNKNOWN_RUN_TYPE || (out == sistrip::UNKNOWN_RUN_TYPE && first)) {
0080         first = false;
0081         if (out != sistrip::UNKNOWN_RUN_TYPE) {
0082           run_types.push_back(in);
0083         }
0084       }
0085     }
0086   }
0087 
0088   std::vector<sistrip::KeyType> key_types;
0089   {
0090     bool first = true;
0091     for (uint32_t cntr = 0; cntr <= sistrip::invalid_; cntr++) {
0092       sistrip::KeyType in = static_cast<sistrip::KeyType>(cntr);
0093       std::string str = SiStripEnumsAndStrings::keyType(in);
0094       sistrip::KeyType out = SiStripEnumsAndStrings::keyType(str);
0095       if (out != sistrip::UNKNOWN_KEY || (out == sistrip::UNKNOWN_KEY && first)) {
0096         first = false;
0097         if (out != sistrip::UNKNOWN_KEY) {
0098           key_types.push_back(in);
0099         }
0100       }
0101     }
0102   }
0103 
0104   std::vector<sistrip::Granularity> grans;
0105   {
0106     bool first = true;
0107     for (uint32_t cntr = 0; cntr <= sistrip::invalid_; cntr++) {
0108       sistrip::Granularity in = static_cast<sistrip::Granularity>(cntr);
0109       std::string str = SiStripEnumsAndStrings::granularity(in);
0110       sistrip::Granularity out = SiStripEnumsAndStrings::granularity(str);
0111       if (out != sistrip::UNKNOWN_GRAN || (out == sistrip::UNKNOWN_GRAN && first)) {
0112         first = false;
0113         if (out != sistrip::UNKNOWN_GRAN) {
0114           grans.push_back(in);
0115         }
0116       }
0117     }
0118   }
0119 
0120   // Test SiStripHistoTitle class
0121 
0122   std::vector<sistrip::HistoType>::const_iterator ihisto = histo_types.begin();
0123   for (; ihisto != histo_types.end(); ihisto++) {
0124     std::vector<sistrip::RunType>::const_iterator irun = run_types.begin();
0125     for (; irun != run_types.end(); irun++) {
0126       std::vector<sistrip::KeyType>::const_iterator ikey = key_types.begin();
0127       for (; ikey != key_types.end(); ikey++) {
0128         if (*ikey != sistrip::FED_KEY) {
0129           continue;
0130         }
0131 
0132         // FED ids
0133         for (uint16_t ifed = 0; ifed <= sistrip::CMS_FED_ID_MAX + 1; ifed++) {
0134           if (ifed > 1 && ifed != sistrip::FED_ID_MIN + 1 && ifed < sistrip::CMS_FED_ID_MAX - 1) {
0135             continue;
0136           }
0137 
0138           // FE units
0139           for (uint16_t ife = 0; ife <= sistrip::FEUNITS_PER_FED + 1; ife++) {
0140             if (ife > 1 && ife < sistrip::FEUNITS_PER_FED) {
0141               continue;
0142             }
0143 
0144             // FE channels
0145             for (uint16_t ichan = 0; ichan <= sistrip::FEDCH_PER_FEUNIT + 1; ichan++) {
0146               if (ichan > 1 && ichan < sistrip::FEDCH_PER_FEUNIT) {
0147                 continue;
0148               }
0149 
0150               // APVs
0151               for (uint16_t iapv = 0; iapv <= sistrip::APVS_PER_FEDCH + 1; iapv++) {
0152                 if (iapv > 1 && iapv < sistrip::APVS_PER_FEDCH) {
0153                   continue;
0154                 }
0155 
0156                 SiStripFedKey key(ifed, ife, ichan, iapv);
0157 
0158                 for (uint16_t iextra = 0; iextra < 2; iextra++) {
0159                   std::string extra = "";
0160                   if (iextra) {
0161                     extra = "SomeInfo";
0162                   }
0163 
0164                   // Generate title objects
0165 
0166                   SiStripHistoTitle in1(*ihisto, *irun, *ikey, key.key(), key.granularity(), key.channel(), extra);
0167 
0168                   SiStripHistoTitle in2(*ihisto, *irun, key, extra);
0169 
0170                   SiStripHistoTitle out1 = SiStripHistoTitle(in1.title());
0171                   SiStripHistoTitle out2 = SiStripHistoTitle(in2.title());
0172 
0173                   // Debug info
0174 
0175                   std::stringstream ss;
0176 
0177                   ss << std::endl
0178                      << "[testSiStripHistoTitle::" << __func__ << "]"
0179                      << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl
0180                      << std::endl;
0181 
0182                   ss << "[testSiStripHistoTitle::" << __func__ << "]"
0183                      << " HistoType/RunType/KeyType: " << *ihisto << "/" << *irun << "/" << *ikey
0184                      << " HistoType: " << SiStripEnumsAndStrings::histoType(*ihisto)
0185                      << " RunType: " << SiStripEnumsAndStrings::runType(*irun)
0186                      << " KeyType: " << SiStripEnumsAndStrings::keyType(*ikey) << std::endl;
0187 
0188                   ss << "[testSiStripHistoTitle::" << __func__ << "]"
0189                      << " FedId/FeUnit/FeChan/APV: " << ifed << "/" << ife << "/" << ichan << "/" << iapv << std::endl;
0190 
0191                   ss << "[testSiStripHistoTitle::" << __func__ << "]"
0192                      << " Gran/Channel: " << SiStripEnumsAndStrings::granularity(key.granularity()) << "/"
0193                      << key.channel() << " ExtraInfo: ";
0194                   if (extra == "") {
0195                     ss << "(none)" << std::endl;
0196                   } else {
0197                     ss << extra << std::endl;
0198                   }
0199 
0200                   ss << key << std::endl;
0201 
0202                   ss << "IN1:  " << in1 << std::endl;
0203                   ss << "IN2:  " << in2 << std::endl;
0204                   ss << "OUT1: " << out1 << std::endl;
0205                   ss << "OUT2: " << out2 << std::endl;
0206 
0207                   LogTrace(mlDqmCommon_) << ss.str();
0208                 }
0209               }
0210             }
0211           }
0212         }
0213       }
0214     }
0215   }
0216 }
0217 
0218 // -----------------------------------------------------------------------------
0219 //
0220 void testSiStripHistoTitle::analyze(const edm::Event& event, const edm::EventSetup& setup) {
0221   LogTrace(mlDqmCommon_) << "[SiStripHistoTitle::" << __func__ << "]"
0222                          << " Analyzing run/event " << event.id().run() << "/" << event.id().event();
0223 }
0224 
0225 #include "FWCore/Framework/interface/MakerMacros.h"
0226 DEFINE_FWK_MODULE(testSiStripHistoTitle);