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
00031 ros25Unpacker = new DTROS25Unpacker(dduPSet.getParameter<edm::ParameterSet>("rosParameters"));
00032
00033
00034 localDAQ = dduPSet.getUntrackedParameter<bool>("localDAQ",false);
00035 performDataIntegrityMonitor = dduPSet.getUntrackedParameter<bool>("performDataIntegrityMonitor",false);
00036 debug = dduPSet.getUntrackedParameter<bool>("debug",false);
00037
00038
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
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
00067
00068
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
00080
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
00093 DTDDUData controlData(dduHeader,dduTrailer);
00094
00095
00096 vector<DTDDUFirstStatusWord> rosStatusWords;
00097
00098
00099 if (localDAQ) {
00100
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
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
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
00125
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
00141
00142
00143
00144 index32 += (wordSize_64)/wordSize_32;
00145
00146
00147
00148 datasize -= 4*wordSize_64;
00149
00150
00151 ros25Unpacker->interpretRawData(index32, datasize, dduID, mapping, detectorProduct, triggerProduct, theROSList);
00152
00153
00154 if (performDataIntegrityMonitor)
00155 dataMonitor->processFED(controlData, ros25Unpacker->getROSsControlData(),dduID);
00156
00157 }