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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
/**
 * \class L1GtTriggerMenuLiteProducer
 * 
 * 
 * Description: L1GtTriggerMenuLite producer.
 *
 * Implementation:
 *    Read the L1 trigger menu, the trigger masks and the prescale factor sets
 *    from event setup and save a lite version (top level menu, trigger masks
 *    for physics partition and prescale factor set) in Run Data.
 *   
 * \author: Vasile Mihai Ghete - HEPHY Vienna 
 * 
 *
 */

// this class header
#include "EventFilter/L1GlobalTriggerRawToDigi/interface/L1GtTriggerMenuLiteProducer.h"

// system include files
#include <iostream>

// user include files
#include "DataFormats/L1GlobalTrigger/interface/L1GtTriggerMenuLite.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Run.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/MessageLogger/interface/MessageDrop.h"

// constructor(s)
L1GtTriggerMenuLiteProducer::L1GtTriggerMenuLiteProducer(const edm::ParameterSet& parSet)
    : m_l1GtStableParCacheID(0ULL),
      m_numberPhysTriggers(0),

      m_numberTechnicalTriggers(0),

      m_l1GtMenuCacheID(0ULL),

      m_l1GtTmAlgoCacheID(0ULL),
      m_l1GtTmTechCacheID(0ULL),

      m_l1GtPfAlgoCacheID(0ULL),
      m_l1GtPfTechCacheID(0ULL),

      m_l1GtStableParamToken(esConsumes<L1GtStableParameters, L1GtStableParametersRcd, edm::Transition::BeginRun>()),
      m_l1GtPfAlgoToken(esConsumes<L1GtPrescaleFactors, L1GtPrescaleFactorsAlgoTrigRcd, edm::Transition::BeginRun>()),
      m_l1GtPfTechToken(esConsumes<L1GtPrescaleFactors, L1GtPrescaleFactorsTechTrigRcd, edm::Transition::BeginRun>()),
      m_l1GtTmAlgoToken(esConsumes<L1GtTriggerMask, L1GtTriggerMaskAlgoTrigRcd, edm::Transition::BeginRun>()),
      m_l1GtTmTechToken(esConsumes<L1GtTriggerMask, L1GtTriggerMaskTechTrigRcd, edm::Transition::BeginRun>()),
      m_l1GtMenuToken(esConsumes<L1GtTriggerMenu, L1GtTriggerMenuRcd, edm::Transition::BeginRun>()),
      m_physicsDaqPartition(0) {
  // EDM product in Run Data
  produces<L1GtTriggerMenuLite, edm::Transition::BeginRun>();
}

// destructor
L1GtTriggerMenuLiteProducer::~L1GtTriggerMenuLiteProducer() {
  // empty
}

void L1GtTriggerMenuLiteProducer::retrieveL1EventSetup(const edm::EventSetup& evSetup) {
  // get / update the stable parameters from the EventSetup
  // local cache & check on cacheIdentifier

  unsigned long long l1GtStableParCacheID = evSetup.get<L1GtStableParametersRcd>().cacheIdentifier();

  if (m_l1GtStableParCacheID != l1GtStableParCacheID) {
    edm::ESHandle<L1GtStableParameters> l1GtStablePar = evSetup.getHandle(m_l1GtStableParamToken);
    m_l1GtStablePar = l1GtStablePar.product();

    // number of physics triggers
    m_numberPhysTriggers = m_l1GtStablePar->gtNumberPhysTriggers();

    // number of technical triggers
    m_numberTechnicalTriggers = m_l1GtStablePar->gtNumberTechnicalTriggers();

    //
    m_l1GtStableParCacheID = l1GtStableParCacheID;
  }

  // get / update the prescale factors from the EventSetup
  // local cache & check on cacheIdentifier

  unsigned long long l1GtPfAlgoCacheID = evSetup.get<L1GtPrescaleFactorsAlgoTrigRcd>().cacheIdentifier();

  if (m_l1GtPfAlgoCacheID != l1GtPfAlgoCacheID) {
    edm::ESHandle<L1GtPrescaleFactors> l1GtPfAlgo = evSetup.getHandle(m_l1GtPfAlgoToken);
    m_l1GtPfAlgo = l1GtPfAlgo.product();

    m_prescaleFactorsAlgoTrig = &(m_l1GtPfAlgo->gtPrescaleFactors());

    m_l1GtPfAlgoCacheID = l1GtPfAlgoCacheID;
  }

  unsigned long long l1GtPfTechCacheID = evSetup.get<L1GtPrescaleFactorsTechTrigRcd>().cacheIdentifier();

  if (m_l1GtPfTechCacheID != l1GtPfTechCacheID) {
    edm::ESHandle<L1GtPrescaleFactors> l1GtPfTech = evSetup.getHandle(m_l1GtPfTechToken);
    m_l1GtPfTech = l1GtPfTech.product();

    m_prescaleFactorsTechTrig = &(m_l1GtPfTech->gtPrescaleFactors());

    m_l1GtPfTechCacheID = l1GtPfTechCacheID;
  }

  // get / update the trigger mask from the EventSetup
  // local cache & check on cacheIdentifier

  unsigned long long l1GtTmAlgoCacheID = evSetup.get<L1GtTriggerMaskAlgoTrigRcd>().cacheIdentifier();

  if (m_l1GtTmAlgoCacheID != l1GtTmAlgoCacheID) {
    edm::ESHandle<L1GtTriggerMask> l1GtTmAlgo = evSetup.getHandle(m_l1GtTmAlgoToken);
    m_l1GtTmAlgo = l1GtTmAlgo.product();

    m_triggerMaskAlgoTrig = &(m_l1GtTmAlgo->gtTriggerMask());

    m_l1GtTmAlgoCacheID = l1GtTmAlgoCacheID;
  }

  unsigned long long l1GtTmTechCacheID = evSetup.get<L1GtTriggerMaskTechTrigRcd>().cacheIdentifier();

  if (m_l1GtTmTechCacheID != l1GtTmTechCacheID) {
    edm::ESHandle<L1GtTriggerMask> l1GtTmTech = evSetup.getHandle(m_l1GtTmTechToken);
    m_l1GtTmTech = l1GtTmTech.product();

    m_triggerMaskTechTrig = &(m_l1GtTmTech->gtTriggerMask());

    m_l1GtTmTechCacheID = l1GtTmTechCacheID;
  }

  // get / update the trigger menu from the EventSetup
  // local cache & check on cacheIdentifier

  unsigned long long l1GtMenuCacheID = evSetup.get<L1GtTriggerMenuRcd>().cacheIdentifier();

  if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
    edm::ESHandle<L1GtTriggerMenu> l1GtMenu = evSetup.getHandle(m_l1GtMenuToken);
    m_l1GtMenu = l1GtMenu.product();

    m_algorithmMap = &(m_l1GtMenu->gtAlgorithmMap());
    m_algorithmAliasMap = &(m_l1GtMenu->gtAlgorithmAliasMap());

    m_technicalTriggerMap = &(m_l1GtMenu->gtTechnicalTriggerMap());

    m_l1GtMenuCacheID = l1GtMenuCacheID;
  }
}

// member functions

void L1GtTriggerMenuLiteProducer::beginJob() {
  // empty
}

void L1GtTriggerMenuLiteProducer::beginRunProduce(edm::Run& iRun, const edm::EventSetup& evSetup) {
  //

  retrieveL1EventSetup(evSetup);

  // produce the L1GtTriggerMenuLite
  std::unique_ptr<L1GtTriggerMenuLite> gtTriggerMenuLite(new L1GtTriggerMenuLite());

  // lite L1 trigger menu

  gtTriggerMenuLite->setGtTriggerMenuInterface(m_l1GtMenu->gtTriggerMenuInterface());
  gtTriggerMenuLite->setGtTriggerMenuName(m_l1GtMenu->gtTriggerMenuName());
  gtTriggerMenuLite->setGtTriggerMenuImplementation(m_l1GtMenu->gtTriggerMenuImplementation());

  gtTriggerMenuLite->setGtScaleDbKey(m_l1GtMenu->gtScaleDbKey());

  //
  L1GtTriggerMenuLite::L1TriggerMap algMap;
  for (CItAlgo itAlgo = m_algorithmMap->begin(); itAlgo != m_algorithmMap->end(); itAlgo++) {
    unsigned int bitNumber = (itAlgo->second).algoBitNumber();
    algMap[bitNumber] = itAlgo->first;
  }

  gtTriggerMenuLite->setGtAlgorithmMap(algMap);

  //
  L1GtTriggerMenuLite::L1TriggerMap algAliasMap;
  for (CItAlgo itAlgo = m_algorithmAliasMap->begin(); itAlgo != m_algorithmAliasMap->end(); itAlgo++) {
    unsigned int bitNumber = (itAlgo->second).algoBitNumber();
    algAliasMap[bitNumber] = itAlgo->first;
  }

  gtTriggerMenuLite->setGtAlgorithmAliasMap(algAliasMap);

  //
  L1GtTriggerMenuLite::L1TriggerMap techMap;
  for (CItAlgo itAlgo = m_technicalTriggerMap->begin(); itAlgo != m_technicalTriggerMap->end(); itAlgo++) {
    unsigned int bitNumber = (itAlgo->second).algoBitNumber();
    techMap[bitNumber] = itAlgo->first;
  }

  gtTriggerMenuLite->setGtTechnicalTriggerMap(techMap);

  // trigger masks
  std::vector<unsigned int> triggerMaskAlgoTrig(m_numberPhysTriggers, 0);
  int iBit = -1;

  for (std::vector<unsigned int>::const_iterator itBit = m_triggerMaskAlgoTrig->begin();
       itBit != m_triggerMaskAlgoTrig->end();
       itBit++) {
    iBit++;
    triggerMaskAlgoTrig[iBit] = (*itBit) & (1 << m_physicsDaqPartition);
  }
  gtTriggerMenuLite->setGtTriggerMaskAlgoTrig(triggerMaskAlgoTrig);

  //
  std::vector<unsigned int> triggerMaskTechTrig(m_numberTechnicalTriggers, 0);
  iBit = -1;

  for (std::vector<unsigned int>::const_iterator itBit = m_triggerMaskTechTrig->begin();
       itBit != m_triggerMaskTechTrig->end();
       itBit++) {
    iBit++;
    triggerMaskTechTrig[iBit] = (*itBit) & (1 << m_physicsDaqPartition);
  }
  gtTriggerMenuLite->setGtTriggerMaskTechTrig(triggerMaskTechTrig);

  //
  gtTriggerMenuLite->setGtPrescaleFactorsAlgoTrig(*m_prescaleFactorsAlgoTrig);
  gtTriggerMenuLite->setGtPrescaleFactorsTechTrig(*m_prescaleFactorsTechTrig);

  // print menu, trigger masks and prescale factors
  if (edm::isDebugEnabled()) {
    LogDebug("L1GtTriggerMenuLiteProducer") << *gtTriggerMenuLite;
  }

  // put records into event
  iRun.put(std::move(gtTriggerMenuLite));
}

void L1GtTriggerMenuLiteProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSetup) {}

//
void L1GtTriggerMenuLiteProducer::endJob() {
  // empty now
}

// static class members

//define this as a plug-in
DEFINE_FWK_MODULE(L1GtTriggerMenuLiteProducer);