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