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