Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:13:26

0001 // Include files
0002 
0003 #include <cmath>
0004 #include <algorithm>
0005 // local
0006 #include "L1Trigger/RPCTechnicalTrigger/interface/TTUEmulator.h"
0007 #include "L1Trigger/RPCTechnicalTrigger/interface/TTUBasicConfig.h"
0008 #include "L1Trigger/RPCTechnicalTrigger/interface/RBCLinkBoardGLSignal.h"
0009 #include "L1Trigger/RPCTechnicalTrigger/interface/TTUGlobalSignal.h"
0010 
0011 //-----------------------------------------------------------------------------
0012 // Implementation file for class : TTUEmulator
0013 //
0014 // 2008-10-15 : Andres Osorio
0015 //-----------------------------------------------------------------------------
0016 
0017 namespace {
0018   constexpr std::array<int, 6> wheelIds = {{1, 2, 0, 0, -1, -2}};
0019 }
0020 
0021 //=============================================================================
0022 // Standard constructor, initializes variables
0023 //=============================================================================
0024 TTUEmulator::TTUEmulator(int id, int mxw) : m_maxWheels{mxw}, m_id{id}, m_mode{1}, m_line{1}, m_debug{false} {
0025   for (int k = 0; k < m_maxWheels; ++k)
0026     m_Wheels[k].setProperties(wheelIds[(id * 2) + (k - 2)]);
0027 }
0028 
0029 TTUEmulator::TTUEmulator(int id, const char* rbclogic_type, const char* ttulogic_type, int mxw)
0030     : m_maxWheels{mxw},
0031       m_id{id},
0032       m_mode{1},
0033       m_line{1},
0034       m_ttuconf{std::make_unique<TTUBasicConfig>(ttulogic_type)},
0035       m_debug{false} {
0036   for (int k = 0; k < m_maxWheels; ++k)
0037     m_Wheels[k].setProperties(wheelIds[(id * 2) + (k - 2)], rbclogic_type);
0038 }
0039 
0040 TTUEmulator::TTUEmulator(int id, const char* f_name, const char* rbclogic_type, const char* ttulogic_type, int mxw)
0041     : m_maxWheels{mxw},
0042       m_id{id},
0043       m_mode{1},
0044       m_line{1},
0045       m_ttuconf{std::make_unique<TTUBasicConfig>(ttulogic_type)},
0046       m_debug{false} {
0047   for (int k = 0; k < m_maxWheels; ++k)
0048     m_Wheels[k].setProperties(wheelIds[(id * 2) + (k - 2)], f_name, rbclogic_type);
0049 }
0050 
0051 //=============================================================================
0052 void TTUEmulator::setSpecifications(const TTUBoardSpecs* ttuspecs, const RBCBoardSpecs* rbcspecs) {
0053   m_ttuconf = std::make_unique<TTUBasicConfig>(ttuspecs);
0054 
0055   for (int k = 0; k < m_maxWheels; ++k)
0056     m_Wheels[k].setSpecifications(rbcspecs);
0057 
0058   std::vector<TTUBoardSpecs::TTUBoardConfig>::const_iterator itr;
0059   itr = m_ttuconf->m_ttuboardspecs->m_boardspecs.begin();
0060 
0061   m_mode = (*itr).m_triggerMode;
0062 }
0063 
0064 bool TTUEmulator::initialise() {
0065   bool status(false);
0066   for (int k = 0; k < m_maxWheels; ++k)
0067     status = m_Wheels[k].initialise();
0068 
0069   status = m_ttuconf->initialise(m_line, m_id);
0070 
0071   if (!status) {
0072     if (m_debug)
0073       std::cout << "TTUEmulator> Problem initialising the Configuration \n";
0074     return false;
0075   };
0076 
0077   return status;
0078 }
0079 
0080 void TTUEmulator::SetLineId(int line) { m_line = line; }
0081 
0082 void TTUEmulator::emulate() {
0083   //... only for testing
0084   for (int k = 0; k < m_maxWheels; ++k)
0085     m_Wheels[k].emulate();
0086 }
0087 
0088 void TTUEmulator::processTtu(RPCInputSignal* signal) {
0089   //.
0090   int bx(0);
0091   bool trg(false);
0092 
0093   if (m_debug)
0094     std::cout << "TTUEmulator::processTtu starts" << '\n';
0095 
0096   m_trigger.reset();
0097   m_triggerBx.clear();
0098 
0099   std::vector<int> bxVec;
0100   std::vector<int>::iterator bxItr;
0101   std::map<int, RBCInput*>* linkboardin;
0102   std::map<int, RBCInput*>::iterator inItr;
0103 
0104   linkboardin = dynamic_cast<RBCLinkBoardGLSignal*>(signal)->m_linkboardin;
0105 
0106   for (inItr = (*linkboardin).begin(); inItr != (*linkboardin).end(); ++inItr) {
0107     if ((*inItr).first < 0)
0108       bx = (int)ceil((*inItr).first / 1000000.0);
0109     else
0110       bx = (int)floor((*inItr).first / 1000000.0);
0111     bxVec.push_back(bx);
0112   }
0113 
0114   bxItr = unique(bxVec.begin(), bxVec.end());
0115   bxVec.resize(bxItr - bxVec.begin());
0116 
0117   m_triggerBxVec.reserve(m_triggerBxVec.size() + bxVec.size());
0118   for (bxItr = bxVec.begin(); bxItr != bxVec.end(); ++bxItr) {
0119     for (int k = 0; k < m_maxWheels; ++k) {
0120       if (m_Wheels[k].process((*bxItr), (*linkboardin))) {
0121         m_Wheels[k].createWheelMap();
0122 
0123         m_Wheels[k].retrieveWheelMap((m_ttuin[k]));
0124 
0125         //.. execute selected logic at Ttu level
0126         m_ttuconf->ttulogic()->run((m_ttuin[k]));
0127 
0128         //... and produce a Wheel level trigger
0129         trg = m_ttuconf->ttulogic()->isTriggered();
0130 
0131         m_trigger.set(k, trg);
0132 
0133         if (m_debug)
0134           std::cout << "TTUEmulator::processTtu ttuid: " << m_id << " bx: " << (*bxItr)
0135                     << " wheel: " << m_Wheels[k].getid() << " response: " << trg << std::endl;
0136       }
0137     }
0138 
0139     auto& triggerResponse = m_triggerBxVec.emplace_back();
0140 
0141     triggerResponse.setTriggerBits((*bxItr), m_trigger);
0142     m_triggerBx[(*bxItr)] = m_trigger;
0143   }
0144 
0145   if (m_debug)
0146     std::cout << "TTUEmulator::processTtu> size of trigger map " << m_triggerBx.size() << std::endl;
0147 
0148   if (m_debug)
0149     std::cout << "TTUEmulator::processTtu> done with this TTU: " << m_id << std::endl;
0150 
0151   bxVec.clear();
0152 
0153   if (m_debug)
0154     std::cout << "TTUEmulator::processTtu ends" << '\n';
0155 }
0156 
0157 void TTUEmulator::processTtu(RPCInputSignal* signal, int wedgeId) {
0158   //.
0159   int bx(0);
0160   bool trg(false);
0161 
0162   if (m_debug)
0163     std::cout << "TTUEmulator::processTtu( Pointing ) starts " << '\n';
0164 
0165   m_trigger.reset();
0166   m_triggerBx.clear();
0167 
0168   std::vector<int> bxVec;
0169   std::vector<int>::iterator bxItr;
0170   std::map<int, RBCInput*>* linkboardin;
0171   std::map<int, RBCInput*>::iterator inItr;
0172 
0173   linkboardin = dynamic_cast<RBCLinkBoardGLSignal*>(signal)->m_linkboardin;
0174 
0175   for (inItr = (*linkboardin).begin(); inItr != (*linkboardin).end(); ++inItr) {
0176     if ((*inItr).first < 0)
0177       bx = (int)ceil((*inItr).first / 1000000.0);
0178     else
0179       bx = (int)floor((*inItr).first / 1000000.0);
0180     bxVec.push_back(bx);
0181   }
0182 
0183   bxItr = unique(bxVec.begin(), bxVec.end());
0184   bxVec.resize(bxItr - bxVec.begin());
0185 
0186   m_triggerBxVec.reserve(m_triggerBxVec.size() + bxVec.size());
0187 
0188   for (bxItr = bxVec.begin(); bxItr != bxVec.end(); ++bxItr) {
0189     for (int k = 0; k < m_maxWheels; ++k) {
0190       if (m_Wheels[k].process(
0191               (*bxItr), (*linkboardin))) {  // <- this process uses the default RBC emulation but need a different logic
0192 
0193         m_Wheels[k].createWheelMap();
0194 
0195         m_Wheels[k].retrieveWheelMap((m_ttuin[k]));
0196 
0197         //.. execute selected logic at Ttu level
0198         m_ttuconf->ttulogic()->run((m_ttuin[k]), wedgeId);
0199 
0200         //... and produce a Wheel-Wedge level trigger
0201         trg = m_ttuconf->ttulogic()->isTriggered();
0202 
0203         m_trigger.set(k, trg);
0204 
0205         if (m_debug)
0206           std::cout << "TTUEmulator::processTtu( Pointing ) ttuid: " << m_id << " bx: " << (*bxItr)
0207                     << " wheel: " << m_Wheels[k].getid() << " response: " << trg << std::endl;
0208       }
0209     }
0210 
0211     auto& triggerResponse = m_triggerBxVec.emplace_back();
0212     triggerResponse.setTriggerBits((*bxItr), wedgeId, m_trigger);
0213     m_triggerBx[(*bxItr)] = m_trigger;
0214   }
0215 
0216   if (m_debug)
0217     std::cout << "TTUEmulator::processTtu (Pointing) > size of trigger map " << m_triggerBx.size() << std::endl;
0218 
0219   if (m_debug)
0220     std::cout << "TTUEmulator::processTtu (Pointing) > done with this TTU: " << m_id << std::endl;
0221 
0222   bxVec.clear();
0223 
0224   if (m_debug)
0225     std::cout << "TTUEmulator::processTtu( Pointing ) end" << '\n';
0226 }
0227 
0228 void TTUEmulator::clearTriggerResponse() { m_triggerBxVec.clear(); }
0229 
0230 //.................................................................
0231 
0232 void TTUEmulator::printinfo() const {
0233   std::cout << "TTUEmulator: " << m_id << '\n';
0234   for (int k = 0; k < m_maxWheels; ++k)
0235     m_Wheels[k].printinfo();
0236 }