CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 //=============================================================================
19 // Standard constructor, initializes variables
20 //=============================================================================
21 TTUEmulator::TTUEmulator( int id, int mxw )
22 {
23 
24  m_id = id;
25  m_maxWheels = mxw;
26 
27  int tmp[6] = {1, 2, 0, 0, -1, -2};
28  m_wheelIds = new int[6];
29  for( int k=0; k < 6; ++k) m_wheelIds[k]=tmp[k];
30 
31  m_Wheels = new RPCWheel[2];
32  for( int k=0; k < m_maxWheels; ++k )
33  m_Wheels[k].setProperties( m_wheelIds[(id*2)+(k-2)] );
34 
35  m_ttuin = new TTUInput[2];
36 
37  m_trigger.reset();
38 
39  m_mode = 1;
40 
41  m_debug = false;
42 
43  m_line = 1;
44 
45 }
46 
47 
48 TTUEmulator::TTUEmulator( int id, const char * rbclogic_type, const char * ttulogic_type, int mxw )
49 {
50 
51  m_id = id;
52  m_maxWheels = mxw;
53 
54  int tmp[6] = {1, 2, 0, 0, -1, -2};
55  m_wheelIds = new int[6];
56  for( int k=0; k < 6; ++k) m_wheelIds[k]=tmp[k];
57 
58  m_Wheels = new RPCWheel[2];
59  for( int k=0; k < m_maxWheels; ++k )
60  m_Wheels[k].setProperties( m_wheelIds[(id*2)+(k-2)], rbclogic_type );
61 
62  m_ttuin = new TTUInput[2];
63 
64  m_ttuconf = dynamic_cast<TTUConfiguration*> (new TTUBasicConfig (ttulogic_type));
65 
66  m_trigger.reset();
67 
68  m_mode = 1;
69 
70  m_debug = false;
71 
72  m_line = 1;
73 
74 }
75 
76 TTUEmulator::TTUEmulator( int id, const char * f_name, const char * rbclogic_type,
77  const char * ttulogic_type, int mxw )
78 {
79 
80  m_id = id;
81  m_maxWheels = mxw;
82 
83  int tmp[6] = {1, 2, 0, 0, -1, -2};
84  m_wheelIds = new int[6];
85  for( int k=0; k < 6; ++k) m_wheelIds[k]=tmp[k];
86 
87  m_Wheels = new RPCWheel[2];
88  for( int k=0; k < m_maxWheels; ++k )
89  m_Wheels[k].setProperties( m_wheelIds[(id*2)+(k-2)], f_name, rbclogic_type );
90 
91  m_ttuin = new TTUInput[2];
92 
93  m_ttuconf = dynamic_cast<TTUConfiguration*> (new TTUBasicConfig (ttulogic_type));
94 
95  m_trigger.reset();
96 
97  m_mode = 1;
98 
99  m_debug = false;
100 
101  m_line = 1;
102 
103 }
104 
105 //=============================================================================
106 // Destructor
107 //=============================================================================
109 
110  if ( m_wheelIds ) delete[] m_wheelIds;
111  if ( m_Wheels ) delete[] m_Wheels;
112  if ( m_ttuin ) delete[] m_ttuin;
113  if ( m_ttuconf ) delete m_ttuconf;
114 
115 }
116 
117 //=============================================================================
118 void TTUEmulator::setSpecifications( const TTUBoardSpecs * ttuspecs, const RBCBoardSpecs * rbcspecs)
119 {
120 
121  m_ttuconf = dynamic_cast<TTUConfiguration*> (new TTUBasicConfig (ttuspecs));
122 
123  for( int k=0; k < m_maxWheels; ++k)
124  m_Wheels[k].setSpecifications( rbcspecs );
125 
126  std::vector<TTUBoardSpecs::TTUBoardConfig>::const_iterator itr;
127  itr = m_ttuconf->m_ttuboardspecs->m_boardspecs.begin();
128 
129  m_mode = (*itr).m_triggerMode;
130 
131 }
132 
134 {
135  bool status(false);
136  for( int k=0; k < m_maxWheels; ++k)
137  status = m_Wheels[k].initialise( );
138 
139  status = m_ttuconf->initialise( m_line , m_id );
140 
141  if ( !status ) {
142  if( m_debug ) std::cout << "TTUEmulator> Problem initialising the Configuration \n";
143  return 0; };
144 
145  return status;
146 
147 }
148 
150 {
151  m_line = line;
152 }
153 
155 {
156  //... only for testing
157  for( int k=0; k < m_maxWheels; ++k )
158  m_Wheels[k].emulate();
159 
160 }
161 
163 {
164 
165  //.
166  int bx(0);
167  bool trg(false);
168 
169  if( m_debug ) std::cout << "TTUEmulator::processTtu starts" << '\n';
170 
171  m_trigger.reset();
172  m_triggerBx.clear();
173 
174  std::vector<int> bxVec;
175  std::vector<int>::iterator bxItr;
176  std::map<int,RBCInput*> * linkboardin;
177  std::map<int,RBCInput*>::iterator inItr;
178 
179  linkboardin = dynamic_cast<RBCLinkBoardGLSignal*>( signal )->m_linkboardin;
180 
181  for( inItr = (*linkboardin).begin(); inItr != (*linkboardin).end(); ++inItr)
182  {
183 
184  if ( (*inItr).first < 0 ) bx = (int) ceil( (*inItr).first / 1000000.0 );
185  else bx = (int) floor( (*inItr).first / 1000000.0 );
186  bxVec.push_back(bx);
187 
188  }
189 
190  bxItr = unique (bxVec.begin(), bxVec.end());
191  bxVec.resize(bxItr - bxVec.begin());
192 
193  for ( bxItr = bxVec.begin(); bxItr != bxVec.end(); ++bxItr) {
194 
195  TriggerResponse * triggerResponse = new TriggerResponse();
196 
197  for( int k=0; k < m_maxWheels; ++k )
198  {
199 
200  if ( m_Wheels[k].process( (*bxItr) , (*linkboardin) ) ) {
201 
203 
205 
206  //.. execute selected logic at Ttu level
207  m_ttuconf->m_ttulogic->run( (m_ttuin[k]) );
208 
209  //... and produce a Wheel level trigger
210  trg = m_ttuconf->m_ttulogic->isTriggered();
211 
212  m_trigger.set(k,trg);
213 
214  if( m_debug ) std::cout << "TTUEmulator::processTtu ttuid: " << m_id
215  << " bx: " << (*bxItr)
216  << " wheel: " << m_Wheels[k].getid()
217  << " response: " << trg << std::endl;
218 
219  }
220 
221 
222  }
223 
224 
225  triggerResponse->setTriggerBits( (*bxItr) , m_trigger );
226  m_triggerBxVec.push_back( triggerResponse );
227  m_triggerBx[ (*bxItr) ] = m_trigger;
228 
229  }
230 
231 
232  if( m_debug ) std::cout << "TTUEmulator::processTtu> size of trigger map "
233  << m_triggerBx.size() << std::endl;
234 
235 
236  if( m_debug ) std::cout << "TTUEmulator::processTtu> done with this TTU: " << m_id << std::endl;
237 
238  bxVec.clear();
239 
240  if( m_debug ) std::cout << "TTUEmulator::processTtu ends" << '\n';
241 
242 }
243 
244 void TTUEmulator::processTtu( RPCInputSignal * signal , int wedgeId )
245 {
246 
247  //.
248  int bx(0);
249  bool trg(false);
250 
251  if( m_debug ) std::cout << "TTUEmulator::processTtu( Pointing ) starts " << '\n';
252 
253  m_trigger.reset();
254  m_triggerBx.clear();
255 
256  std::vector<int> bxVec;
257  std::vector<int>::iterator bxItr;
258  std::map<int,RBCInput*> * linkboardin;
259  std::map<int,RBCInput*>::iterator inItr;
260 
261  linkboardin = dynamic_cast<RBCLinkBoardGLSignal*>( signal )->m_linkboardin;
262 
263  for( inItr = (*linkboardin).begin(); inItr != (*linkboardin).end(); ++inItr)
264  {
265 
266  if ( (*inItr).first < 0 ) bx = (int) ceil( (*inItr).first / 1000000.0 );
267  else bx = (int) floor( (*inItr).first / 1000000.0 );
268  bxVec.push_back(bx);
269 
270  }
271 
272  bxItr = unique (bxVec.begin(), bxVec.end());
273  bxVec.resize(bxItr - bxVec.begin());
274 
275  for ( bxItr = bxVec.begin(); bxItr != bxVec.end(); ++bxItr) {
276 
277  TriggerResponse * triggerResponse = new TriggerResponse();
278 
279  for( int k=0; k < m_maxWheels; ++k )
280  {
281 
282  if ( m_Wheels[k].process( (*bxItr) , (*linkboardin) ) ) { // <- this process uses the default RBC emulation but need a different logic
283 
285 
287 
288  //.. execute selected logic at Ttu level
289  m_ttuconf->m_ttulogic->run( (m_ttuin[k]) , wedgeId );
290 
291  //... and produce a Wheel-Wedge level trigger
292  trg = m_ttuconf->m_ttulogic->isTriggered();
293 
294  m_trigger.set(k,trg);
295 
296  if( m_debug ) std::cout << "TTUEmulator::processTtu( Pointing ) ttuid: " << m_id
297  << " bx: " << (*bxItr)
298  << " wheel: " << m_Wheels[k].getid()
299  << " response: " << trg << std::endl;
300 
301  }
302 
303 
304  }
305 
306  triggerResponse->setTriggerBits( (*bxItr) , wedgeId, m_trigger );
307  m_triggerBxVec.push_back( triggerResponse );
308  m_triggerBx[ (*bxItr) ] = m_trigger;
309 
310  }
311 
312  if( m_debug ) std::cout << "TTUEmulator::processTtu (Pointing) > size of trigger map "
313  << m_triggerBx.size() << std::endl;
314 
315  if( m_debug ) std::cout << "TTUEmulator::processTtu (Pointing) > done with this TTU: " << m_id << std::endl;
316 
317  bxVec.clear();
318 
319  if( m_debug ) std::cout << "TTUEmulator::processTtu( Pointing ) end" << '\n';
320 
321 }
322 
323 
325 {
326 
327  std::vector<TriggerResponse*>::iterator itr;
328  for ( itr = m_triggerBxVec.begin(); itr != m_triggerBxVec.end(); ++itr)
329  if ( (*itr) ) delete (*itr);
330  m_triggerBxVec.clear();
331 
332 }
333 
334 //.................................................................
335 
337 {
338 
339  std::cout << "TTUEmulator: " << m_id << '\n';
340  for( int k=0; k < m_maxWheels; ++k )
341  m_Wheels[k].printinfo();
342 
343 }
344 
std::bitset< 2 > m_trigger
Definition: TTUEmulator.h:83
TTUConfiguration * m_ttuconf
Definition: TTUEmulator.h:129
bool isTriggered()
Definition: TTULogicUnit.h:40
const TTUBoardSpecs * m_ttuboardspecs
int getid()
Definition: RPCWheel.h:50
std::vector< TriggerResponse * > m_triggerBxVec
Definition: TTUEmulator.h:112
int m_maxWheels
Definition: TTUEmulator.h:80
void clearTriggerResponse()
Definition: TTUEmulator.cc:324
int * m_wheelIds
Definition: TTUEmulator.h:123
void run(const TTUInput &)
Definition: TTULogicUnit.cc:78
void emulate()
Definition: TTUEmulator.cc:154
void createWheelMap()
Definition: RPCWheel.cc:233
bool initialise()
Definition: TTUEmulator.cc:133
std::vector< TTUBoardConfig > m_boardspecs
Definition: TTUBoardSpecs.h:47
void SetLineId(int)
Definition: TTUEmulator.cc:149
void retrieveWheelMap(TTUInput &)
Definition: RPCWheel.cc:266
void printinfo()
Definition: TTUEmulator.cc:336
void setTriggerBits(int bx, const std::bitset< 2 > &inbits)
Definition: TTUEmulator.h:93
void processTtu(RPCInputSignal *)
Definition: TTUEmulator.cc:162
RPCWheel * m_Wheels
Definition: TTUEmulator.h:82
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
virtual bool initialise(int, int)=0
TTULogicUnit * m_ttulogic
tuple cout
Definition: gather_cfg.py:121
std::map< int, std::bitset< 2 > > m_triggerBx
Definition: TTUEmulator.h:84
tuple status
Definition: ntuplemaker.py:245
tuple process
Definition: LaserDQM_cfg.py:3
TTUInput * m_ttuin
Definition: TTUEmulator.h:127
virtual ~TTUEmulator()
Destructor.
Definition: TTUEmulator.cc:108
int line()
Definition: TTUEmulator.h:72
void setSpecifications(const TTUBoardSpecs *, const RBCBoardSpecs *)
Definition: TTUEmulator.cc:118
TTUEmulator()
Standard constructor.
Definition: TTUEmulator.h:40