CMS 3D CMS Logo

TTUEmulator.cc
Go to the documentation of this file.
1 // Include files
2 
3 #include <cmath>
4 #include <algorithm>
5 // local
10 
11 //-----------------------------------------------------------------------------
12 // Implementation file for class : TTUEmulator
13 //
14 // 2008-10-15 : Andres Osorio
15 //-----------------------------------------------------------------------------
16 
17 namespace {
18  constexpr std::array<int, 6> wheelIds = {{1, 2, 0, 0, -1, -2}};
19 }
20 
21 //=============================================================================
22 // Standard constructor, initializes variables
23 //=============================================================================
24 TTUEmulator::TTUEmulator(int id, int mxw) : m_maxWheels{mxw}, m_id{id}, m_mode{1}, m_line{1}, m_debug{false} {
25  for (int k = 0; k < m_maxWheels; ++k)
26  m_Wheels[k].setProperties(wheelIds[(id * 2) + (k - 2)]);
27 }
28 
29 TTUEmulator::TTUEmulator(int id, const char* rbclogic_type, const char* ttulogic_type, int mxw)
30  : m_maxWheels{mxw},
31  m_id{id},
32  m_mode{1},
33  m_line{1},
34  m_ttuconf{std::make_unique<TTUBasicConfig>(ttulogic_type)},
35  m_debug{false} {
36  for (int k = 0; k < m_maxWheels; ++k)
37  m_Wheels[k].setProperties(wheelIds[(id * 2) + (k - 2)], rbclogic_type);
38 }
39 
40 TTUEmulator::TTUEmulator(int id, const char* f_name, const char* rbclogic_type, const char* ttulogic_type, int mxw)
41  : m_maxWheels{mxw},
42  m_id{id},
43  m_mode{1},
44  m_line{1},
45  m_ttuconf{std::make_unique<TTUBasicConfig>(ttulogic_type)},
46  m_debug{false} {
47  for (int k = 0; k < m_maxWheels; ++k)
48  m_Wheels[k].setProperties(wheelIds[(id * 2) + (k - 2)], f_name, rbclogic_type);
49 }
50 
51 //=============================================================================
52 void TTUEmulator::setSpecifications(const TTUBoardSpecs* ttuspecs, const RBCBoardSpecs* rbcspecs) {
53  m_ttuconf = std::make_unique<TTUBasicConfig>(ttuspecs);
54 
55  for (int k = 0; k < m_maxWheels; ++k)
56  m_Wheels[k].setSpecifications(rbcspecs);
57 
58  std::vector<TTUBoardSpecs::TTUBoardConfig>::const_iterator itr;
59  itr = m_ttuconf->m_ttuboardspecs->m_boardspecs.begin();
60 
61  m_mode = (*itr).m_triggerMode;
62 }
63 
65  bool status(false);
66  for (int k = 0; k < m_maxWheels; ++k)
68 
69  status = m_ttuconf->initialise(m_line, m_id);
70 
71  if (!status) {
72  if (m_debug)
73  std::cout << "TTUEmulator> Problem initialising the Configuration \n";
74  return false;
75  };
76 
77  return status;
78 }
79 
81 
83  //... only for testing
84  for (int k = 0; k < m_maxWheels; ++k)
85  m_Wheels[k].emulate();
86 }
87 
89  //.
90  int bx(0);
91  bool trg(false);
92 
93  if (m_debug)
94  std::cout << "TTUEmulator::processTtu starts" << '\n';
95 
96  m_trigger.reset();
97  m_triggerBx.clear();
98 
99  std::vector<int> bxVec;
100  std::vector<int>::iterator bxItr;
101  std::map<int, RBCInput*>* linkboardin;
102  std::map<int, RBCInput*>::iterator inItr;
103 
104  linkboardin = dynamic_cast<RBCLinkBoardGLSignal*>(signal)->m_linkboardin;
105 
106  for (inItr = (*linkboardin).begin(); inItr != (*linkboardin).end(); ++inItr) {
107  if ((*inItr).first < 0)
108  bx = (int)ceil((*inItr).first / 1000000.0);
109  else
110  bx = (int)floor((*inItr).first / 1000000.0);
111  bxVec.push_back(bx);
112  }
113 
114  bxItr = unique(bxVec.begin(), bxVec.end());
115  bxVec.resize(bxItr - bxVec.begin());
116 
117  m_triggerBxVec.reserve(m_triggerBxVec.size() + bxVec.size());
118  for (bxItr = bxVec.begin(); bxItr != bxVec.end(); ++bxItr) {
119  for (int k = 0; k < m_maxWheels; ++k) {
120  if (m_Wheels[k].process((*bxItr), (*linkboardin))) {
121  m_Wheels[k].createWheelMap();
122 
123  m_Wheels[k].retrieveWheelMap((m_ttuin[k]));
124 
125  //.. execute selected logic at Ttu level
126  m_ttuconf->ttulogic()->run((m_ttuin[k]));
127 
128  //... and produce a Wheel level trigger
129  trg = m_ttuconf->ttulogic()->isTriggered();
130 
131  m_trigger.set(k, trg);
132 
133  if (m_debug)
134  std::cout << "TTUEmulator::processTtu ttuid: " << m_id << " bx: " << (*bxItr)
135  << " wheel: " << m_Wheels[k].getid() << " response: " << trg << std::endl;
136  }
137  }
138 
139  auto& triggerResponse = m_triggerBxVec.emplace_back();
140 
141  triggerResponse.setTriggerBits((*bxItr), m_trigger);
142  m_triggerBx[(*bxItr)] = m_trigger;
143  }
144 
145  if (m_debug)
146  std::cout << "TTUEmulator::processTtu> size of trigger map " << m_triggerBx.size() << std::endl;
147 
148  if (m_debug)
149  std::cout << "TTUEmulator::processTtu> done with this TTU: " << m_id << std::endl;
150 
151  bxVec.clear();
152 
153  if (m_debug)
154  std::cout << "TTUEmulator::processTtu ends" << '\n';
155 }
156 
157 void TTUEmulator::processTtu(RPCInputSignal* signal, int wedgeId) {
158  //.
159  int bx(0);
160  bool trg(false);
161 
162  if (m_debug)
163  std::cout << "TTUEmulator::processTtu( Pointing ) starts " << '\n';
164 
165  m_trigger.reset();
166  m_triggerBx.clear();
167 
168  std::vector<int> bxVec;
169  std::vector<int>::iterator bxItr;
170  std::map<int, RBCInput*>* linkboardin;
171  std::map<int, RBCInput*>::iterator inItr;
172 
173  linkboardin = dynamic_cast<RBCLinkBoardGLSignal*>(signal)->m_linkboardin;
174 
175  for (inItr = (*linkboardin).begin(); inItr != (*linkboardin).end(); ++inItr) {
176  if ((*inItr).first < 0)
177  bx = (int)ceil((*inItr).first / 1000000.0);
178  else
179  bx = (int)floor((*inItr).first / 1000000.0);
180  bxVec.push_back(bx);
181  }
182 
183  bxItr = unique(bxVec.begin(), bxVec.end());
184  bxVec.resize(bxItr - bxVec.begin());
185 
186  m_triggerBxVec.reserve(m_triggerBxVec.size() + bxVec.size());
187 
188  for (bxItr = bxVec.begin(); bxItr != bxVec.end(); ++bxItr) {
189  for (int k = 0; k < m_maxWheels; ++k) {
190  if (m_Wheels[k].process(
191  (*bxItr), (*linkboardin))) { // <- this process uses the default RBC emulation but need a different logic
192 
193  m_Wheels[k].createWheelMap();
194 
195  m_Wheels[k].retrieveWheelMap((m_ttuin[k]));
196 
197  //.. execute selected logic at Ttu level
198  m_ttuconf->ttulogic()->run((m_ttuin[k]), wedgeId);
199 
200  //... and produce a Wheel-Wedge level trigger
201  trg = m_ttuconf->ttulogic()->isTriggered();
202 
203  m_trigger.set(k, trg);
204 
205  if (m_debug)
206  std::cout << "TTUEmulator::processTtu( Pointing ) ttuid: " << m_id << " bx: " << (*bxItr)
207  << " wheel: " << m_Wheels[k].getid() << " response: " << trg << std::endl;
208  }
209  }
210 
211  auto& triggerResponse = m_triggerBxVec.emplace_back();
212  triggerResponse.setTriggerBits((*bxItr), wedgeId, m_trigger);
213  m_triggerBx[(*bxItr)] = m_trigger;
214  }
215 
216  if (m_debug)
217  std::cout << "TTUEmulator::processTtu (Pointing) > size of trigger map " << m_triggerBx.size() << std::endl;
218 
219  if (m_debug)
220  std::cout << "TTUEmulator::processTtu (Pointing) > done with this TTU: " << m_id << std::endl;
221 
222  bxVec.clear();
223 
224  if (m_debug)
225  std::cout << "TTUEmulator::processTtu( Pointing ) end" << '\n';
226 }
227 
229 
230 //.................................................................
231 
233  std::cout << "TTUEmulator: " << m_id << '\n';
234  for (int k = 0; k < m_maxWheels; ++k)
235  m_Wheels[k].printinfo();
236 }
constexpr int32_t ceil(float num)
std::bitset< 2 > m_trigger
Definition: TTUEmulator.h:77
int line() const
Definition: TTUEmulator.h:68
std::array< RPCWheel, 2 > m_Wheels
Definition: TTUEmulator.h:76
std::vector< TriggerResponse > m_triggerBxVec
Definition: TTUEmulator.h:105
void printinfo() const
Definition: TTUEmulator.cc:232
int m_maxWheels
Definition: TTUEmulator.h:74
void clearTriggerResponse()
Definition: TTUEmulator.cc:228
std::unique_ptr< TTUConfiguration > m_ttuconf
Definition: TTUEmulator.h:120
def unique(seq, keepstr=True)
Definition: tier0.py:24
void emulate()
Definition: TTUEmulator.cc:82
bool initialise()
Definition: TTUEmulator.cc:64
void SetLineId(int)
Definition: TTUEmulator.cc:80
void processTtu(RPCInputSignal *)
Definition: TTUEmulator.cc:88
std::map< int, std::bitset< 2 > > m_triggerBx
Definition: TTUEmulator.h:78
std::array< TTUInput, 2 > m_ttuin
Definition: TTUEmulator.h:118
void setSpecifications(const TTUBoardSpecs *, const RBCBoardSpecs *)
Definition: TTUEmulator.cc:52
TTUEmulator()
Standard constructor.
Definition: TTUEmulator.h:42