testSiStripKey

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
// system includes
#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <time.h>

// user includes
#include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
#include "DataFormats/SiStripCommon/interface/SiStripDetKey.h"
#include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
#include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
#include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

/**
   @class testSiStripKey 
   @author R.Bainbridge
   @brief Simple class that tests SiStripKey.
*/
class testSiStripKey : public edm::one::EDAnalyzer<> {
public:
  testSiStripKey(const edm::ParameterSet&);
  ~testSiStripKey();

  void beginJob();
  void analyze(const edm::Event&, const edm::EventSetup&);

private:
  sistrip::KeyType keyType_;
  uint32_t key_;
  std::string path_;
};

using namespace sistrip;

// -----------------------------------------------------------------------------
//
testSiStripKey::testSiStripKey(const edm::ParameterSet& pset)
    : keyType_(sistrip::UNKNOWN_KEY), key_(0), path_(pset.getUntrackedParameter<std::string>("Path", "")) {
  LogTrace(mlDqmCommon_) << "[testSiStripKey::" << __func__ << "]"
                         << " Constructing object...";

  // extract key type
  std::string key_type = pset.getUntrackedParameter<std::string>("KeyType", "");
  keyType_ = SiStripEnumsAndStrings::keyType(key_type);

  // extract key without hex prefix
  std::stringstream key;
  std::string tmp = pset.getUntrackedParameter<std::string>("Key", "0x0");
  if (tmp.find(sistrip::hex_) != std::string::npos) {
    key << std::string(tmp, (sizeof(sistrip::hex_) - 1), tmp.size());
  } else {
    key << tmp;
  }
  key >> std::hex >> key_;
}

// -----------------------------------------------------------------------------
//
testSiStripKey::~testSiStripKey() {
  LogTrace(mlDqmCommon_) << "[testSiStripKey::" << __func__ << "]"
                         << " Destructing object...";
}

// -----------------------------------------------------------------------------
//
void testSiStripKey::beginJob() {
  edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                 << " Tests the generation of keys...";

  if (keyType_ == sistrip::FED_KEY) {
    SiStripFedKey from_key(key_);
    edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                   << " FED key object built from 32-bit key: " << std::endl
                                   << from_key;

    SiStripFedKey from_path(path_);
    edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                   << " FED key object built from directory string: " << std::endl
                                   << from_path;

  } else if (keyType_ == sistrip::FEC_KEY) {
    SiStripFecKey from_key(key_);
    edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                   << " FEC key object built from 32-bit key: " << std::endl
                                   << from_key;

    SiStripFecKey from_path(path_);
    edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                   << " FEC key object built from directory string: " << std::endl
                                   << from_path;

  } else if (keyType_ == sistrip::DET_KEY) {
    SiStripDetKey from_key(key_);
    edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                   << " DET key object built from 32-bit key: " << std::endl
                                   << from_key;

    SiStripDetKey from_path(path_);
    edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                   << " DET key object built from directory string: " << std::endl
                                   << from_path;

  } else {
    // warning
    edm::LogWarning(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                  << " KeyType is of type: " << SiStripEnumsAndStrings::keyType(keyType_);

    // fed
    {
      SiStripFedKey from_key(key_);
      edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                     << " FED key object built from 32-bit key: " << std::endl
                                     << from_key;

      SiStripFedKey from_path(path_);
      edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                     << " FED key object built from directory string: " << std::endl
                                     << from_path;
    }

    // fec
    {
      SiStripFecKey from_key(key_);
      edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                     << " FEC key object built from 32-bit key: " << std::endl
                                     << from_key;

      SiStripFecKey from_path(path_);
      edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                     << " FEC key object built from directory string: " << std::endl
                                     << from_path;
    }

    // det
    {
      SiStripDetKey from_key(key_);
      edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                     << " DET key object built from 32-bit key: " << std::endl
                                     << from_key;

      SiStripDetKey from_path(path_);
      edm::LogVerbatim(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                                     << " DET key object built from directory string: " << std::endl
                                     << from_path;
    }
  }
}

// -----------------------------------------------------------------------------
//
void testSiStripKey::analyze(const edm::Event& event, const edm::EventSetup& setup) {
  LogTrace(mlDqmCommon_) << "[SiStripKey::" << __func__ << "]"
                         << " Analyzing run/event " << event.id().run() << "/" << event.id().event();
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(testSiStripKey);