Go to the documentation of this file.00001
00010 #include "EventFilter/RPCRawToDigi/interface/RPCRecordFormatter.h"
00011
00012 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00013 #include "DataFormats/RPCDigi/interface/RPCDigi.h"
00014
00015 #include "CondFormats/RPCObjects/interface/RPCReadOutMapping.h"
00016 #include "CondFormats/RPCObjects/interface/LinkBoardElectronicIndex.h"
00017
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 #include "FWCore/Utilities/interface/Exception.h"
00020
00021 #include "DataFormats/RPCDigi/interface/ReadoutError.h"
00022
00023
00024
00025 #include <bitset>
00026 #include <sstream>
00027
00028 using namespace std;
00029 using namespace edm;
00030 using namespace rpcrawtodigi;
00031
00032
00033 RPCRecordFormatter::RPCRecordFormatter(int fedId, const RPCReadOutMapping *r)
00034 : currentFED(fedId), readoutMapping(r)
00035 { }
00036
00037 RPCRecordFormatter::~RPCRecordFormatter()
00038 { }
00039
00040
00041 std::vector<EventRecords> RPCRecordFormatter::recordPack(
00042 uint32_t rawDetId, const RPCDigi & digi, int trigger_BX) const
00043 {
00044 std::vector<EventRecords> result;
00045
00046 LogTrace("") << " DIGI; det: " << rawDetId<<", strip: "<<digi.strip()<<", bx: "<<digi.bx();
00047 int stripInDU = digi.strip();
00048
00049
00050 typedef std::vector< std::pair< LinkBoardElectronicIndex, LinkBoardPackedStrip> > RawDataFrames;
00051 RPCReadOutMapping::StripInDetUnit duFrame(rawDetId, stripInDU);
00052 RawDataFrames rawDataFrames = readoutMapping->rawDataFrame(duFrame);
00053
00054 for (RawDataFrames::const_iterator ir = rawDataFrames.begin(); ir != rawDataFrames.end(); ir++) {
00055
00056 const LinkBoardElectronicIndex & eleIndex = (*ir).first;
00057 const LinkBoardPackedStrip & lbPackedStrip = (*ir).second;
00058
00059 if (eleIndex.dccId == currentFED) {
00060
00061 LogTrace("pack:")
00062 <<" dccId= "<<eleIndex.dccId
00063 <<" dccInputChannelNum= "<<eleIndex.dccInputChannelNum
00064 <<" tbLinkInputNum= "<<eleIndex.tbLinkInputNum
00065 <<" lbNumInLink="<<eleIndex.lbNumInLink;
00066
00067
00068 int current_BX = trigger_BX+digi.bx();
00069 RecordBX bxr(current_BX);
00070
00071
00072 int tbLinkInputNumber = eleIndex.tbLinkInputNum;
00073 int rmb = eleIndex.dccInputChannelNum;
00074 RecordSLD lbr( tbLinkInputNumber, rmb);
00075
00076
00077 int lbInLink = eleIndex.lbNumInLink;
00078 int eod = 0;
00079 int halfP = 0;
00080 int packedStrip = lbPackedStrip.packedStrip();
00081 int partitionNumber = packedStrip/8;
00082 RecordCD cdr(lbInLink, partitionNumber, eod, halfP, vector<int>(1,packedStrip) );
00083
00084 result.push_back( EventRecords(trigger_BX, bxr, lbr, cdr) );
00085 }
00086 }
00087 return result;
00088 }
00089
00090 int RPCRecordFormatter::recordUnpack(
00091 const EventRecords & event,
00092 RPCDigiCollection * prod, RPCRawDataCounts * counter, RPCRawSynchro::ProdItem * synchro)
00093 {
00094
00095 static bool debug = edm::MessageDrop::instance()->debugEnabled;
00096 ReadoutError error;
00097 int currentRMB = event.recordSLD().rmb();
00098 int currentTbLinkInputNumber = event.recordSLD().tbLinkInputNumber();
00099
00100 LinkBoardElectronicIndex eleIndex;
00101 eleIndex.dccId = currentFED;
00102 eleIndex.dccInputChannelNum = currentRMB;
00103 eleIndex.tbLinkInputNum = currentTbLinkInputNumber;
00104 eleIndex.lbNumInLink = event.recordCD().lbInLink();
00105
00106
00107 if( event.recordCD().eod() ) {
00108 if(counter) counter->addReadoutError(currentFED, ReadoutError(eleIndex,ReadoutError::EOD));
00109 }
00110
00111 if(readoutMapping == 0) return error.type();
00112 const LinkBoardSpec* linkBoard = readoutMapping->location(eleIndex);
00113 if (!linkBoard) {
00114 if (debug) LogDebug("")<<" ** PROBLEM ** Invalid Linkboard location, skip CD event, "
00115 << "dccId: "<<eleIndex.dccId
00116 << "dccInputChannelNum: " <<eleIndex.dccInputChannelNum
00117 << " tbLinkInputNum: "<<eleIndex.tbLinkInputNum
00118 << " lbNumInLink: "<<eleIndex.lbNumInLink;
00119 error = ReadoutError(eleIndex,ReadoutError::InvalidLB);
00120 if(counter) counter->addReadoutError(currentFED,error );
00121 return error.type();
00122 }
00123
00124
00125 std::vector<int> packStrips = event.recordCD().packedStrips();
00126 if (packStrips.size() ==0) {
00127 error = ReadoutError(eleIndex,ReadoutError::EmptyPackedStrips);
00128 if(counter) counter->addReadoutError(currentFED, error);
00129 return error.type();
00130 }
00131
00132 for(std::vector<int>::iterator is = packStrips.begin(); is != packStrips.end(); ++is) {
00133
00134 RPCReadOutMapping::StripInDetUnit duFrame =
00135 readoutMapping->detUnitFrame(*linkBoard, LinkBoardPackedStrip(*is) );
00136
00137 uint32_t rawDetId = duFrame.first;
00138 int geomStrip = duFrame.second;
00139 if (!rawDetId) {
00140 if (debug) LogTrace("") << " ** PROBLEM ** no rawDetId, skip at least part of CD data";
00141 error = ReadoutError(eleIndex,ReadoutError::InvalidDetId);
00142 if (counter) counter->addReadoutError(currentFED, error);
00143 continue;
00144 }
00145 if (geomStrip==0) {
00146 if(debug) LogTrace("") <<" ** PROBLEM ** no strip found";
00147 error = ReadoutError(eleIndex,ReadoutError::InvalidStrip);
00148 if (counter) counter->addReadoutError(currentFED, error);
00149 continue;
00150 }
00151
00152
00153 RPCDigi digi(geomStrip,event.dataToTriggerDelay()-3);
00154
00156 if (debug) {
00157
00158 LogTrace("")<<" DIGI; det: "<<rawDetId<<", strip: "<<digi.strip()<<", bx: "<<digi.bx();
00159 }
00160 if (prod) prod->insertDigi(RPCDetId(rawDetId),digi);
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 }
00171
00172 if(synchro) synchro->push_back( make_pair(eleIndex,event.dataToTriggerDelay() ));
00173
00174 return error.type();
00175 }