File indexing completed on 2025-08-06 08:18:37
0001 #include "LL1Outv1.h"
0002 #include "TriggerDefs.h"
0003
0004 #include <cstdint>
0005 #include <iostream>
0006
0007 LL1Outv1::LL1Outv1()
0008 : m_trigger_key(TriggerDefs::getTriggerKey(TriggerDefs::GetTriggerId(m_trigger_type)))
0009 , m_trigger_bits(new std::vector<unsigned int>())
0010 {
0011 }
0012
0013 LL1Outv1::LL1Outv1(const std::string& triggertype, const std::string& ll1type)
0014 : m_trigger_key(TriggerDefs::getTriggerKey(TriggerDefs::GetTriggerId(triggertype)))
0015 , m_triggerid(TriggerDefs::GetTriggerId(triggertype))
0016 , m_ll1_type(ll1type)
0017 , m_trigger_type(triggertype)
0018 , m_trigger_bits(new std::vector<unsigned int>())
0019 {
0020 int ntriggerwords = 0;
0021 if (m_triggerid == TriggerDefs::TriggerId::jetTId || m_triggerid == TriggerDefs::TriggerId::photonTId)
0022 {
0023 ntriggerwords = 384;
0024 }
0025 else if (m_triggerid == TriggerDefs::TriggerId::pairTId)
0026 {
0027 ntriggerwords = 0;
0028 }
0029 else if (m_triggerid == TriggerDefs::TriggerId::mbdTId)
0030 {
0031 ntriggerwords = 8;
0032 }
0033
0034 for (int channel = 0; channel < ntriggerwords; channel++)
0035 {
0036 std::vector<unsigned int>* sum = new std::vector<unsigned int>();
0037 if (m_triggerid == TriggerDefs::TriggerId::jetTId || m_triggerid == TriggerDefs::TriggerId::photonTId)
0038 {
0039 LL1Outv1::add_word(((unsigned int) (channel % 32) & 0xffffU) + (((unsigned int) (channel / 32) & 0xffffU) << 16U), sum);
0040 }
0041 if (m_triggerid == TriggerDefs::TriggerId::mbdTId)
0042 {
0043 LL1Outv1::add_word(channel, sum);
0044 }
0045 }
0046 }
0047
0048 LL1Outv1::~LL1Outv1()
0049 {
0050
0051
0052
0053 m_trigger_bits->clear();
0054 m_triggered_sums.clear();
0055 m_triggered_primitives.clear();
0056 for (auto& word : m_trigger_words)
0057 {
0058 word.second->clear();
0059 }
0060 }
0061
0062
0063 void LL1Outv1::Reset()
0064 {
0065 m_trigger_bits->clear();
0066 m_triggered_sums.clear();
0067 m_triggered_primitives.clear();
0068 for (auto& word : m_trigger_words)
0069 {
0070 word.second->clear();
0071 }
0072 }
0073
0074 LL1Outv1::ConstRange LL1Outv1::getTriggerWords() const
0075 {
0076 return make_pair(m_trigger_words.begin(), m_trigger_words.end());
0077 }
0078
0079 LL1Outv1::Range LL1Outv1::getTriggerWords()
0080 {
0081 return make_pair(m_trigger_words.begin(), m_trigger_words.end());
0082 }
0083
0084
0085 void LL1Outv1::identify(std::ostream& out) const
0086 {
0087 out << __FILE__ << __FUNCTION__ << " LL1Out: Triggertype = " << m_trigger_type << " LL1 type = " << m_ll1_type << std::endl;
0088 out << __FILE__ << __FUNCTION__ << " Event number: " << m_event_number << " Clock: " << m_clock_number << std::endl;
0089 out << __FILE__ << __FUNCTION__ << " Trigger bits " << m_trigger_bits->size() << " : ";
0090 for (unsigned int trigger_bit : *m_trigger_bits)
0091 {
0092 std::cout << " " << trigger_bit;
0093 }
0094 out << " " << std::endl;
0095 out << __FILE__ << __FUNCTION__ << " Trigger words " << std::endl;
0096
0097 for (auto trigger_word : m_trigger_words)
0098 {
0099 for (unsigned int& j : *trigger_word.second)
0100 {
0101 std::cout << " " << j;
0102 }
0103
0104 std::cout << " " << std::endl;
0105 }
0106 }
0107
0108 int LL1Outv1::isValid() const
0109 {
0110 return 0;
0111 }
0112
0113 bool LL1Outv1::passesTrigger()
0114 {
0115 for (unsigned int& trigger_bit : *m_trigger_bits)
0116 {
0117 if (trigger_bit)
0118 {
0119 return true;
0120 }
0121 }
0122 return false;
0123 }
0124
0125 bool LL1Outv1::passesThreshold(int ith)
0126 {
0127 if (!ith)
0128 {
0129 return passesTrigger();
0130 }
0131
0132 for (unsigned int& trigger_bit : *m_trigger_bits)
0133 {
0134 if (((trigger_bit >> (uint16_t) (ith - 1)) & 0x1U) == 0x1U)
0135 {
0136 return true;
0137 }
0138 }
0139 return false;
0140 }
0141
0142 void LL1Outv1::addTriggeredSum(TriggerDefs::TriggerSumKey sk, unsigned short bit)
0143 {
0144 unsigned int sumk = sk;
0145 m_triggered_sums.emplace_back(sumk, bit);
0146
0147 return;
0148 }
0149 void LL1Outv1::addTriggeredPrimitive(TriggerDefs::TriggerPrimKey pk)
0150 {
0151 unsigned int primk = pk;
0152 if (m_triggered_primitives.empty())
0153 {
0154 m_triggered_primitives.push_back(primk);
0155 }
0156
0157 return;
0158 }
0159
0160 std::vector<std::pair<TriggerDefs::TriggerSumKey, unsigned short>> LL1Outv1::getTriggeredSums()
0161 {
0162 return m_triggered_sums;
0163 }
0164 std::vector<TriggerDefs::TriggerSumKey> LL1Outv1::getTriggeredSumKeys(int ith)
0165 {
0166 std::vector<TriggerDefs::TriggerSumKey> bitSums = {};
0167
0168 if (!ith)
0169 {
0170 ith = 1;
0171 }
0172 for (auto& key_bit : m_triggered_sums)
0173 {
0174 unsigned short trigger_bit = key_bit.second;
0175
0176
0177 if (((trigger_bit >> (uint16_t) (ith - 1)) & 0x1U) == 0x1U)
0178 {
0179 bitSums.push_back(key_bit.first);
0180 }
0181 }
0182 return bitSums;
0183 }