CMS 3D CMS Logo

DTDDUUnpacker.cc

Go to the documentation of this file.
00001 
00009 #include <DataFormats/FEDRawData/interface/FEDHeader.h>
00010 #include <DataFormats/FEDRawData/interface/FEDTrailer.h>
00011 
00012 #include <EventFilter/DTRawToDigi/interface/DTDDUWords.h>
00013 #include <EventFilter/DTRawToDigi/interface/DTControlData.h>
00014 
00015 #include <EventFilter/DTRawToDigi/interface/DTDataMonitorInterface.h>
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017 
00018 #include <EventFilter/DTRawToDigi/plugins/DTDDUUnpacker.h>
00019 #include <EventFilter/DTRawToDigi/plugins/DTROS25Unpacker.h>
00020 
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 
00023 #include <iostream>
00024 
00025 using namespace std;
00026 using namespace edm;
00027 
00028 DTDDUUnpacker::DTDDUUnpacker(const edm::ParameterSet& ps) : dduPSet(ps) { 
00029   
00030   // the ROS unpacker
00031   ros25Unpacker = new DTROS25Unpacker(dduPSet.getParameter<edm::ParameterSet>("rosParameters"));
00032   
00033   // parameters
00034   localDAQ = dduPSet.getUntrackedParameter<bool>("localDAQ",false);
00035   performDataIntegrityMonitor = dduPSet.getUntrackedParameter<bool>("performDataIntegrityMonitor",false);
00036   debug = dduPSet.getUntrackedParameter<bool>("debug",false);
00037 
00038   // enable DQM
00039   if(performDataIntegrityMonitor) dataMonitor = edm::Service<DTDataMonitorInterface>().operator->(); 
00040 }
00041 
00042 
00043 DTDDUUnpacker::~DTDDUUnpacker() {
00044   delete ros25Unpacker;
00045 }
00046 
00047 
00048 void DTDDUUnpacker::interpretRawData(const unsigned int* index32, int datasize,
00049                                      int dduID,
00050                                      edm::ESHandle<DTReadOutMapping>& mapping, 
00051                                      std::auto_ptr<DTDigiCollection>& detectorProduct,
00052                                      std::auto_ptr<DTLocalTriggerCollection>& triggerProduct,
00053                                      uint16_t rosList) {
00054 
00055   // Definitions
00056   const int wordSize_32 = 4;
00057   const int wordSize_64 = 8;
00058 
00059   int numberOf32Words = datasize/wordSize_32;
00060 
00061   const unsigned char* index8 = reinterpret_cast<const unsigned char*>(index32);
00062 
00063 
00065   /*  D D U   d a t a */
00067 
00068   // DDU header
00069   FEDHeader dduHeader(index8);
00070   if (dduHeader.check()) {
00071     if(debug) cout << "[DTDDUUnpacker] FED Header. BXID: "<<dduHeader.bxID()
00072                    << " L1ID: "<<dduHeader.lvl1ID() <<endl;
00073   } else {
00074     LogWarning("DTRawToDigi|DTDDUUnpacker") << "[DTDDUUnpacker] WARNING!, this is not a DDU Header, FED ID: "
00075                                             << dduID << endl;
00076     if(performDataIntegrityMonitor) dataMonitor->fedFatal(dduID);
00077   }
00078 
00079   // DDU trailer
00080   // [BITS] stop before FED trailer := 8 bytes
00081   FEDTrailer dduTrailer(index8 + datasize - 1*wordSize_64); 
00082 
00083   if (dduTrailer.check()) {
00084     if(debug) cout << "[DTDDUUnpacker] FED Trailer. Lenght of the DT event: "
00085                    << dduTrailer.lenght() << endl;
00086   } else {
00087     LogWarning("DTRawToDigi|DTDDUUnpacker") << "[DTDDUUnpacker] WARNING!, this is not a DDU Trailer, FED ID: "
00088                                             << dduID << endl;
00089     if(performDataIntegrityMonitor) dataMonitor->fedFatal(dduID);
00090   }
00091 
00092   // Control DDU data
00093   DTDDUData controlData(dduHeader,dduTrailer);
00094 
00095   // Check Status Words 
00096   vector<DTDDUFirstStatusWord> rosStatusWords;
00097   // [BITS] 3 words of 8 bytes + "rosId" bytes
00098   // In the case we are reading from DMA, the status word are swapped as the ROS data
00099   if (localDAQ) {
00100     // DDU channels from 1 to 4
00101     for (int rosId = 0; rosId < 4; rosId++ ) {
00102       int wordIndex8 = numberOf32Words*wordSize_32 - 3*wordSize_64 + wordSize_32 + rosId; 
00103       controlData.addROSStatusWord(DTDDUFirstStatusWord(index8[wordIndex8]));
00104     }
00105     // DDU channels from 5 to 8
00106     for (int rosId = 0; rosId < 4; rosId++ ) {
00107       int wordIndex8 = numberOf32Words*wordSize_32 - 3*wordSize_64 + rosId; 
00108       controlData.addROSStatusWord(DTDDUFirstStatusWord(index8[wordIndex8]));
00109     }
00110     // DDU channels from 9 to 12
00111     for (int rosId = 0; rosId < 4; rosId++ ) {
00112       int wordIndex8 = numberOf32Words*wordSize_32 - 2*wordSize_64 + wordSize_32 + rosId; 
00113       controlData.addROSStatusWord(DTDDUFirstStatusWord(index8[wordIndex8]));
00114     }
00115   }
00116   else {
00117     for (int rosId = 0; rosId < 12; rosId++ ) {
00118       int wordIndex8 = numberOf32Words*wordSize_32 - 3*wordSize_64 + rosId; 
00119       controlData.addROSStatusWord(DTDDUFirstStatusWord(index8[wordIndex8]));
00120     }
00121   }
00122 
00123   int theROSList;
00124   // [BITS] 2 words of 8 bytes + 4 bytes (half 64 bit word)
00125   // In the case we are reading from DMA, the status word are swapped as the ROS data
00126   if (localDAQ) {
00127     DTDDUSecondStatusWord dduStatusWord(index32[numberOf32Words - 2*wordSize_64/wordSize_32]);
00128     controlData.addDDUStatusWord(dduStatusWord);
00129     theROSList =  dduStatusWord.rosList();
00130   }
00131   else {
00132     DTDDUSecondStatusWord dduStatusWord(index32[numberOf32Words - 2*wordSize_64/wordSize_32 + 1]);
00133     controlData.addDDUStatusWord(dduStatusWord);
00134     theROSList =  dduStatusWord.rosList();
00135   }
00136 
00137 
00139   /*  R O S   d a t a */
00141 
00142   // Set the index to start looping on ROS data
00143   // [BITS] one 8 bytes word
00144   index32 += (wordSize_64)/wordSize_32; 
00145 
00146   // Set the datasize to look only at ROS data 
00147   // [BITS] header, trailer, 2 status words
00148   datasize -= 4*wordSize_64; 
00149 
00150   // unpacking the ROS payload
00151   ros25Unpacker->interpretRawData(index32, datasize, dduID, mapping, detectorProduct, triggerProduct, theROSList);
00152 
00153   // Perform DQM if requested
00154   if (performDataIntegrityMonitor) 
00155     dataMonitor->processFED(controlData, ros25Unpacker->getROSsControlData(),dduID);  
00156   
00157 }

Generated on Tue Jun 9 17:34:29 2009 for CMSSW by  doxygen 1.5.4