CMS 3D CMS Logo

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