CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTROS25Unpacker.cc
Go to the documentation of this file.
1 
10 
14 
18 
20 
21 // Mapping
23 
24 #include <iostream>
25 #include <math.h>
26 
27 using namespace std;
28 using namespace edm;
29 
30 
31 
32 
34 
35 
36  localDAQ = ps.getUntrackedParameter<bool>("localDAQ",false);
37  readingDDU = ps.getUntrackedParameter<bool>("readingDDU",true);
38 
39  readDDUIDfromDDU = ps.getUntrackedParameter<bool>("readDDUIDfromDDU",true);
40  hardcodedDDUID = ps.getUntrackedParameter<int>("dduID",770);
41 
42  writeSC = ps.getUntrackedParameter<bool>("writeSC",false);
43  performDataIntegrityMonitor = ps.getUntrackedParameter<bool>("performDataIntegrityMonitor",false);
44  debug = ps.getUntrackedParameter<bool>("debug",false);
45 
46  // enable DQM if Service is available
47  if(performDataIntegrityMonitor) {
50  } else {
51  LogWarning("DTRawToDigi|DTROS25Unpacker") <<
52  "[DTROS25Unpacker] WARNING! Data Integrity Monitoring requested but no DTDataMonitorInterface Service available" << endl;
53  performDataIntegrityMonitor = false;
54  }
55  }
56 
57 }
58 
59 
61 
62 
63 void DTROS25Unpacker::interpretRawData(const unsigned int* index, int datasize,
64  int dduIDfromDDU,
66  std::auto_ptr<DTDigiCollection>& detectorProduct,
67  std::auto_ptr<DTLocalTriggerCollection>& triggerProduct,
68  uint16_t rosList) {
69 
70 
71  int dduID;
72  if (readDDUIDfromDDU) dduID = dduIDfromDDU;
73  else dduID = hardcodedDDUID;
74 
75  const int wordLength = 4;
76  int numberOfWords = datasize / wordLength;
77 
78  int rosID = 0;
79  DTROS25Data controlData(rosID);
80  controlDataFromAllROS.clear();
81 
82  int wordCounter = 0;
83  uint32_t word = index[swap(wordCounter)];
84 
85  map<uint32_t,int> hitOrder;
86 
87 
88  /******************************************************
89  / The the loop is performed with "do-while" statements
90  / because the ORDER of the words in the event data
91  / is assumed to be fixed. Eventual changes into the
92  / structure should be considered as data corruption
93  *******************************************************/
94 
95  // Loop on ROSs
96  while (wordCounter < numberOfWords) {
97 
98  controlData.clean();
99 
100  rosID++; // to be mapped;
101 
102  if ( readingDDU ) {
103  // matching the ROS number with the enabled DDU channel
104  if ( rosID <= 12 && !((rosList & int(pow(2., (rosID-1) )) ) >> (rosID-1) ) ) continue;
105  if (debug) cout<<"[DTROS25Unpacker]: ros list: "<<rosList <<" ROS ID "<<rosID<<endl;
106  }
107 
108  // FRC prepare info for DTLocalTrigger: wheel and sector corresponding to this ROS
109 
110  int SCwheel=-3;
111  int SCsector=0;
112  int dum1, dum2, dum3, dum4;
113 
114  if (writeSC && ! mapping->readOutToGeometry(dduID, rosID, 1, 1, 1,
115  SCwheel, dum1, SCsector, dum2, dum3, dum4) ) {
116  if (debug) cout <<" found SCwheel: "<<SCwheel<<" and SCsector: "<<SCsector<<endl;
117  }
118  else {
119  if (writeSC && debug) cout <<" WARNING failed to find WHEEL and SECTOR for ROS "<<rosID<<" !"<<endl;
120  }
121 
122 
123  // ROS Header;
125  DTROSHeaderWord rosHeaderWord(word);
126 
127  if (debug) cout<<"[DTROS25Unpacker]: ROSHeader "<<rosHeaderWord.TTCEventCounter()<<endl;
128 
129  // container for words to be sent to DQM
130  controlData.setROSId(rosID);
131  controlData.addROSHeader(rosHeaderWord);
132 
133 
134  // Loop on ROBs
135  do {
136  wordCounter++; word = index[swap(wordCounter)];
137 
138  // Eventual ROS Error: occurs when some errors are found in a ROB
139  if (DTROSWordType(word).type() == DTROSWordType::ROSError) {
140  DTROSErrorWord dtROSErrorWord(word);
141  controlData.addROSError(dtROSErrorWord);
142  if (debug) cout<<"[DTROS25Unpacker]: ROSError, Error type "<<dtROSErrorWord.errorType()
143  <<" robID "<<dtROSErrorWord.robID()<<endl;
144  }
145 
146  // Eventual ROS Debugging;
147  else if (DTROSWordType(word).type() == DTROSWordType::ROSDebug) {
148  DTROSDebugWord rosDebugWord(word);
149  controlData.addROSDebug(rosDebugWord);
150  if (debug) cout<<"[DTROS25Unpacker]: ROSDebug, type "<<rosDebugWord.debugType()
151  <<" message "<<rosDebugWord.debugMessage()<<endl;
152  }
153 
154  // Check ROB header
155  else if (DTROSWordType(word).type() == DTROSWordType::GroupHeader) {
156 
157  DTROBHeaderWord robHeaderWord(word);
158  int eventID = robHeaderWord.eventID(); // from the TDCs
159  int bunchID = robHeaderWord.bunchID(); // from the TDCs
160  int robID = robHeaderWord.robID(); // to be mapped
161 
162  DTROBHeader robHeader(robID,robHeaderWord); // IJ
163  controlData.addROBHeader(robHeader); // IJ
164 
165  if (debug) cout<<"[DTROS25Unpacker] ROB: ID "<<robID
166  <<" Event ID "<<eventID
167  <<" BXID "<<bunchID<<endl;
168 
169  // Loop on TDCs data (headers and trailers are not there)
170  do {
171  wordCounter++; word = index[swap(wordCounter)];
172 
173  // Eventual TDC Error
174  if ( DTROSWordType(word).type() == DTROSWordType::TDCError) {
175  DTTDCErrorWord dtTDCErrorWord(word);
176  DTTDCError tdcError(robID,dtTDCErrorWord);
177  controlData.addTDCError(tdcError);
178 
179  DTTDCErrorNotifier dtTDCError(dtTDCErrorWord);
180  if (debug) dtTDCError.print();
181  }
182 
183  // Eventual TDC Debug
184  else if ( DTROSWordType(word).type() == DTROSWordType::TDCDebug) {
185  if (debug) cout<<"TDC Debugging"<<endl;
186  }
187 
188  // The TDC information
189  else if (DTROSWordType(word).type() == DTROSWordType::TDCMeasurement) {
190 
191  DTTDCMeasurementWord tdcMeasurementWord(word);
192  DTTDCData tdcData(robID,tdcMeasurementWord);
193  controlData.addTDCData(tdcData);
194 
195  int tdcID = tdcMeasurementWord.tdcID();
196  int tdcChannel = tdcMeasurementWord.tdcChannel();
197 
198  if (debug) cout<<"[DTROS25Unpacker] TDC: ID "<<tdcID
199  <<" Channel "<< tdcChannel
200  <<" Time "<<tdcMeasurementWord.tdcTime()<<endl;
201 
202  DTROChainCoding channelIndex(dduID, rosID, robID, tdcID, tdcChannel);
203 
204  hitOrder[channelIndex.getCode()]++;
205 
206  if (debug) {
207  cout<<"[DTROS25Unpacker] ROAddress: DDU "<< dduID
208  <<", ROS "<< rosID
209  <<", ROB "<< robID
210  <<", TDC "<< tdcID
211  <<", Channel "<< tdcChannel<<endl;
212  }
213 
214  // FRC if not already done for this ROS, find wheel and sector for SC data
215  if (writeSC && (SCsector < 1 || SCwheel < -2) ) {
216 
217  if (debug) cout <<" second try to find SCwheel and SCsector "<<endl;
218  if ( ! mapping->readOutToGeometry(dduID, rosID, robID, tdcID, tdcChannel,
219  SCwheel, dum1, SCsector, dum2, dum3, dum4) ) {
220  if (debug) cout<<" ROS "<<rosID<<" SC wheel "<<SCwheel<<" SC sector "<<SCsector<<endl;
221  }
222  else {
223  if (debug) cout<<" WARNING !! ROS "<<rosID<<" failed again to map for SC!! "<<endl;
224  }
225  }
226 
227 
228  // Map the RO channel to the DetId and wire
229  DTWireId detId;
230  // if ( ! mapping->readOutToGeometry(dduID, rosID, robID, tdcID, tdcChannel, detId)) {
231  int wheelId, stationId, sectorId, slId,layerId, cellId;
232  if ( ! mapping->readOutToGeometry(dduID, rosID, robID, tdcID, tdcChannel,
233  wheelId, stationId, sectorId, slId, layerId, cellId)) {
234 
235  // skip the digi if the detId is invalid
236  if (sectorId==0 || stationId == 0) continue;
237  else detId = DTWireId(wheelId, stationId, sectorId, slId, layerId, cellId);
238 
239  if (debug) cout<<"[DTROS25Unpacker] "<<detId<<endl;
240  int wire = detId.wire();
241 
242  // Produce the digi
243  DTDigi digi( wire, tdcMeasurementWord.tdcTime(), hitOrder[channelIndex.getCode()]-1);
244 
245  // Commit to the event
246  detectorProduct->insertDigi(detId.layerId(),digi);
247  }
248  else {
249  LogWarning ("DTRawToDigi|DTROS25Unpacker") <<"Unable to map the RO channel: DDU "<<dduID
250  <<" ROS "<<rosID<<" ROB "<<robID<<" TDC "<<tdcID<<" TDC ch. "<<tdcChannel;
251  if (debug) cout<<"[DTROS25Unpacker] ***ERROR*** Missing wire: DDU "<<dduID
252  <<" ROS "<<rosID<<" ROB "<<robID<<" TDC "<<tdcID<<" TDC ch. "<<tdcChannel<<endl;
253  }
254 
255  } // TDC information
256 
257  } while ( DTROSWordType(word).type() != DTROSWordType::GroupTrailer &&
258  DTROSWordType(word).type() != DTROSWordType::ROSError); // loop on TDC's?
259 
260  // Check ROB Trailer (condition already verified)
262  DTROBTrailerWord robTrailerWord(word);
263  controlData.addROBTrailer(robTrailerWord);
264  if (debug) cout<<"[DTROS25Unpacker]: ROBTrailer, robID "<<robTrailerWord.robID()
265  <<" eventID "<<robTrailerWord.eventID()
266  <<" wordCount "<<robTrailerWord.wordCount()<<endl;
267  }
268  } // ROB header
269 
270  // Check the eventual Sector Collector Header
271  else if (DTROSWordType(word).type() == DTROSWordType::SCHeader) {
272  DTLocalTriggerHeaderWord scHeaderWord(word);
273  if (debug) cout<<"[DTROS25Unpacker]: SC header eventID " << scHeaderWord.eventID()<<endl;
274 
275  // RT added : first word following SCHeader is a SC private header
276  wordCounter++; word = index[swap(wordCounter)];
277 
278  if(DTROSWordType(word).type() == DTROSWordType::SCData) {
279  DTLocalTriggerSectorCollectorHeaderWord scPrivateHeaderWord(word);
280 
281  if(performDataIntegrityMonitor) {
282  controlData.addSCPrivHeader(scPrivateHeaderWord);
283  }
284 
285  int numofscword = scPrivateHeaderWord.NumberOf16bitWords();
286  int leftword = numofscword;
287 
288  if(debug) cout<<" SC PrivateHeader (number of words + subheader = "
289  << scPrivateHeaderWord.NumberOf16bitWords() << ")" <<endl;
290 
291  // if no SC data -> no loop ;
292  // otherwise subtract 1 word (subheader) and countdown for bx assignment
293  if(numofscword > 0){
294 
295  int bx_received = (numofscword - 1) / 2;
296  if(debug) cout<<" SC number of bx read-out: " << bx_received << endl;
297 
298  wordCounter++; word = index[swap(wordCounter)];
299  if (DTROSWordType(word).type() == DTROSWordType::SCData) {
300  //second word following SCHeader is a SC private SUB-header
301  leftword--;
302 
303  DTLocalTriggerSectorCollectorSubHeaderWord scPrivateSubHeaderWord(word);
304  // read the event BX in the SC header (will be stored in SC digis)
305  int scEventBX = scPrivateSubHeaderWord.LocalBunchCounter();
306  if(debug) cout <<" SC trigger delay = "
307  << scPrivateSubHeaderWord.TriggerDelay() << endl
308  <<" SC bunch counter = "
309  << scEventBX << endl;
310 
311  controlData.addSCPrivSubHeader(scPrivateSubHeaderWord);
312 
313  // actual loop on SC time slots
314  int stationGroup=0;
315  do {
316  wordCounter++; word = index[swap(wordCounter)];
317  int SCstation=0;
318 
319  if (DTROSWordType(word).type() == DTROSWordType::SCData) {
320  leftword--;
321  //RT: bx are sent from SC in reverse order starting from the one
322  //which stopped the spy buffer
323  int bx_counter = int(round( (leftword + 1)/ 2.));
324 
325  if(debug){
326  if(bx_counter < 0 || leftword < 0)
327  cout<<"[DTROS25Unpacker]: SC data more than expected; negative bx counter reached! "<<endl;
328  }
329 
330  DTLocalTriggerDataWord scDataWord(word);
331 
332  // DTSectorCollectorData scData(scDataWord, int(round(bx_counter/2.))); M.Z.
333  DTSectorCollectorData scData(scDataWord,bx_counter);
334  controlData.addSCData(scData);
335 
336  if (debug) {
337  //cout<<"[DTROS25Unpacker]: SCData bits "<<scDataWord.SCData()<<endl;
338  //cout << " word in esadecimale: " << hex << word << dec << endl;
339  if (scDataWord.hasTrigger(0))
340  cout<<" at BX "<< bx_counter //round(bx_counter/2.)
341  <<" lower part has trigger! with track quality "
342  << scDataWord.trackQuality(0)<<endl;
343  if (scDataWord.hasTrigger(1))
344  cout<<" at BX "<< bx_counter //round(bx_counter/2.)
345  <<" upper part has trigger! with track quality "
346  << scDataWord.trackQuality(1)<<endl;
347  }
348 
349  if (writeSC && SCwheel >= -2 && SCsector >=1 ) {
350 
351  // FRC: start constructing persistent SC objects:
352  // first identify the station (data come in 2 triggers per word: MB1+MB2, MB3+MB4)
353  if ( scDataWord.hasTrigger(0) || (scDataWord.getBits(0) & 0x30) ) {
354  if ( stationGroup%2 == 0) SCstation = 1;
355  else SCstation = 3;
356 
357  // construct localtrigger for first station of this "group" ...
358  DTLocalTrigger localtrigger(scEventBX, bx_counter,(scDataWord.SCData()) & 0xFF);
359  // ... and commit it to the event
360  DTChamberId chamberId (SCwheel,SCstation,SCsector);
361  triggerProduct->insertDigi(chamberId,localtrigger);
362  if (debug) {
363  cout<<"Add SC digi to the collection, for chamber: " << chamberId
364  <<endl;
365  localtrigger.print(); }
366  }
367  if ( scDataWord.hasTrigger(1) || (scDataWord.getBits(1) & 0x30) ) {
368  if ( stationGroup%2 == 0) SCstation = 2;
369  else SCstation = 4;
370 
371  // construct localtrigger for second station of this "group" ...
372  DTLocalTrigger localtrigger(scEventBX, bx_counter,(scDataWord.SCData()) >> 8);
373  // ... and commit it to the event
374  DTChamberId chamberId (SCwheel,SCstation,SCsector);
375  triggerProduct->insertDigi(chamberId,localtrigger);
376  if(debug) {
377  cout<<"Add SC digi to the collection, for chamber: " << chamberId
378  <<endl;
379  localtrigger.print();
380  }
381  }
382 
383  stationGroup++;
384  } // if writeSC
385  } // if SC data
386  } while ( DTROSWordType(word).type() != DTROSWordType::SCTrailer );
387 
388  } // end SC subheader
389  } // end if SC send more than only its own header!
390  } // end if first data following SCheader is not SCData
391 
393  DTLocalTriggerTrailerWord scTrailerWord(word);
394  // add infos for data integrity monitoring
395  controlData.addSCHeader(scHeaderWord);
396  controlData.addSCTrailer(scTrailerWord);
397 
398  if (debug) cout<<" SC Trailer, # of words: "
399  << scTrailerWord.wordCount() <<endl;
400  }
401  }
402 
403  } while ( DTROSWordType(word).type() != DTROSWordType::ROSTrailer ); // loop on ROBS
404 
405  // check ROS Trailer (condition already verified)
407  DTROSTrailerWord rosTrailerWord(word);
408  controlData.addROSTrailer(rosTrailerWord);
409  if (debug) cout<<"[DTROS25Unpacker]: ROSTrailer "<<rosTrailerWord.EventWordCount()<<endl;
410  }
411 
412  // Perform dqm if requested:
413  // DQM IS PERFORMED FOR EACH ROS SEPARATELY
414  if (performDataIntegrityMonitor) {
415  dataMonitor->processROS25(controlData, dduID, rosID);
416  // fill the vector with ROS's control data
417  controlDataFromAllROS.push_back(controlData);
418  }
419 
420  }
421 
422  else if (index[swap(wordCounter)] == 0) {
423  // in the case of odd number of words of a given ROS the header of
424  // the next one is postponed by 4 bytes word set to 0.
425  // rosID needs to be step back by 1 unit
426  if (debug) cout<<"[DTROS25Unpacker]: odd number of ROS words"<<endl;
427  rosID--;
428  } // if ROS header
429 
430  else {
431  cout<<"[DTROS25Unpacker]: ERROR! First word is not a ROS Header"<<endl;
432  }
433 
434  // (needed if there are more than 1 ROS)
435  wordCounter++; word = index[swap(wordCounter)];
436 
437  } // loop on ROS!
438 
439 }
440 
441 
443 
444  int result=n;
445 
446  if ( !localDAQ ) {
447  if (n%2==0) result = (n+1);
448  if (n%2==1) result = (n-1);
449  }
450 
451  return result;
452 }
453 
type
Definition: HCALResponse.h:22
int trackQuality(int first) const
Definition: DTDDUWords.h:843
int EventWordCount() const
Definition: DTDDUWords.h:276
T getUntrackedParameter(std::string const &, T const &) const
void addSCData(const DTSectorCollectorData &scData)
Definition: DTControlData.h:48
void clean()
Definition: DTControlData.h:72
int SCData() const
Definition: DTDDUWords.h:835
int hasTrigger(int first) const
Definition: DTDDUWords.h:842
std::pair< int, DTROBHeaderWord > DTROBHeader
Definition: DTControlData.h:20
void addROBHeader(const DTROBHeader &robHeader)
Definition: DTControlData.h:43
int robID() const
Definition: DTDDUWords.h:325
int getBits(int first) const
Definition: DTDDUWords.h:837
void addSCPrivHeader(const DTLocalTriggerSectorCollectorHeaderWord &scPrivHeader)
Definition: DTControlData.h:50
void addSCTrailer(const DTLocalTriggerTrailerWord &scTrailer)
Definition: DTControlData.h:52
int tdcChannel() const
Definition: DTDDUWords.h:644
int wordCount() const
Definition: DTDDUWords.h:482
virtual void interpretRawData(const unsigned int *index, int datasize, int dduID, edm::ESHandle< DTReadOutMapping > &mapping, std::auto_ptr< DTDigiCollection > &product, std::auto_ptr< DTLocalTriggerCollection > &product2, uint16_t rosList=0)
int TTCEventCounter() const
Definition: DTDDUWords.h:227
DTROS25Unpacker(const edm::ParameterSet &ps)
Constructor.
std::pair< int, DTTDCErrorWord > DTTDCError
Definition: DTControlData.h:22
uint32_t getCode() const
Getters ///////////////////////.
void print()
Print out the error information &gt;&gt;&gt; FIXME: to be implemented.
int tdcTime() const
Definition: DTDDUWords.h:645
void addTDCError(const DTTDCError &tdcError)
Definition: DTControlData.h:47
void addSCPrivSubHeader(const DTLocalTriggerSectorCollectorSubHeaderWord &scPrivSubHeader)
Definition: DTControlData.h:51
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
tuple result
Definition: query.py:137
std::pair< DTLocalTriggerDataWord, int > DTSectorCollectorData
Definition: DTControlData.h:23
void setROSId(const int &ID)
Setters ///////////////////////.
Definition: DTControlData.h:37
bool isAvailable() const
Definition: Service.h:47
virtual ~DTROS25Unpacker()
Destructor.
int debugMessage() const
Definition: DTDDUWords.h:372
Definition: DTDigi.h:19
int tdcID() const
&lt;== OBSOLETE!!
Definition: DTDDUWords.h:643
int wire() const
Return the wire number.
Definition: DTWireId.h:58
int robID() const
Definition: DTDDUWords.h:431
enum wordTypes type()
DDU word type getter.
Definition: DTDDUWords.h:133
void print() const
Print content of trigger.
int errorType() const
Definition: DTDDUWords.h:324
void addROBTrailer(const DTROBTrailerWord &word)
Definition: DTControlData.h:44
void addROSHeader(const DTROSHeaderWord &word)
Definition: DTControlData.h:39
int debugType() const
Definition: DTDDUWords.h:371
void addROSError(const DTROSErrorWord &word)
Definition: DTControlData.h:41
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:64
int robID() const
Definition: DTDDUWords.h:480
void addROSTrailer(const DTROSTrailerWord &word)
Definition: DTControlData.h:40
std::pair< int, DTTDCMeasurementWord > DTTDCData
Definition: DTControlData.h:21
tuple cout
Definition: gather_cfg.py:121
void addSCHeader(const DTLocalTriggerHeaderWord &scHeader)
Definition: DTControlData.h:49
#define debug
Definition: MEtoEDMFormat.h:34
void addROSDebug(const DTROSDebugWord &word)
Definition: DTControlData.h:42
int bunchID() const
Definition: DTDDUWords.h:433
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void addTDCData(const DTTDCData &tdcData)
Definition: DTControlData.h:46
int eventID() const
Definition: DTDDUWords.h:432
int eventID() const
Definition: DTDDUWords.h:481