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