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
#include "DQM/SiStripCommissioningSummary/interface/SummaryGeneratorReadoutView.h"
#include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
#include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
#include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>

using namespace sistrip;

// -----------------------------------------------------------------------------
//
SummaryGeneratorReadoutView::SummaryGeneratorReadoutView() : SummaryGenerator("SummaryGeneratorReadoutView") { ; }

// -----------------------------------------------------------------------------
//
void SummaryGeneratorReadoutView::fill(const std::string& top_level_dir,
                                       const sistrip::Granularity& granularity,
                                       const uint32_t& device_key,
                                       const float& value,
                                       const float& error) {
  // Check granularity is recognised
  std::string gran = SiStripEnumsAndStrings::granularity(granularity);

  if (granularity != sistrip::UNDEFINED_GRAN && granularity != sistrip::FE_DRIVER && granularity != sistrip::FE_UNIT &&
      granularity != sistrip::FE_CHAN && granularity != sistrip::APV) {
    std::string temp = SiStripEnumsAndStrings::granularity(sistrip::FE_CHAN);
    edm::LogWarning(mlSummaryPlots_) << "[SummaryGeneratorReadoutView::" << __func__ << "]"
                                     << " Unexpected granularity requested: " << gran;
    return;
  }

  // Create key representing "top level" directory
  SiStripFedKey top(top_level_dir);

  // Path and std::string for "present working directory" as defined by device key
  SiStripFedKey path(device_key);
  const std::string& pwd = path.path();

  // Check path is "within" top-level directory structure
  if (top.isValid() && path.isValid() && (path.fedId() == top.fedId() || !top.fedId()) &&
      (path.feUnit() == top.feUnit() || !top.feUnit()) && (path.feChan() == top.feChan() || !top.feChan())) {
    // Extract path and std::string corresponding to "top-level down to granularity"
    std::string sub_dir = pwd;
    size_t pos = pwd.find(gran);
    if (pos != std::string::npos) {
      sub_dir = pwd.substr(0, pwd.find(sistrip::dir_, pos));
    } else if (granularity == sistrip::UNKNOWN_GRAN) {
      sub_dir = pwd;
    }

    SiStripFedKey sub_path(sub_dir);

    //     LogTrace(mlTest_)
    //       << "TEST "
    //       << "sub_path " << sub_path;

    // Construct bin label
    std::stringstream bin;
    if (sub_path.fedId() && sub_path.fedId() != sistrip::invalid_) {
      bin << std::setw(3) << std::setfill('0') << sub_path.fedId();
    }
    if (sub_path.feUnit() && sub_path.feUnit() != sistrip::invalid_) {
      bin << sistrip::dir_ << std::setw(1) << std::setfill('0') << sub_path.feUnit();
    }
    if (sub_path.feChan() && sub_path.feChan() != sistrip::invalid_) {
      bin << sistrip::dir_ << std::setw(2) << std::setfill('0') << sub_path.feChan();
    }
    if (sub_path.fedApv() && sub_path.fedApv() != sistrip::invalid_) {
      bin << sistrip::dir_ << std::setw(1) << std::setfill('0') << sub_path.fedApv();
    }
    //     if ( granularity == sistrip::APV &&
    // 	 path.fedApv() != sistrip::invalid_ ) { bin << sistrip::dot_ << path.fedApv(); }

    // Store "value" in appropriate std::vector within std::map (key is bin label)
    map_[bin.str()].push_back(Data(value, error));
    entries_ += value;
    //     LogTrace(mlTest_)
    //       << "TEST "
    //       << " filling " << bin.str()
    //       << " " << value
    //       << " " << error;

  } else {
    //     std::stringstream ss;
    //     ss << "[SummaryGeneratorReadoutView::" << __func__ << "]"
    //        << " Path for 'pwd' is not within top-level directory!" << std::endl
    //        << "Top-level: " << top << std::endl
    //        << "Path: " << path << std::endl;
    //     edm::LogWarning(mlSummaryPlots_) << ss.str();
  }
}