![]() |
![]() |
00001 #include "EventFilter/RPCRawToDigi/interface/EventRecords.h" 00002 #include "DataFormats/RPCDigi/interface/ErrorRCDM.h" 00003 #include "DataFormats/RPCDigi/interface/ErrorRDDM.h" 00004 #include "DataFormats/RPCDigi/interface/ErrorRDM.h" 00005 #include "DataFormats/RPCDigi/interface/ErrorSDDM.h" 00006 00007 00008 using namespace rpcrawtodigi; 00009 using std::vector; 00010 00011 int EventRecords::dataToTriggerDelay() const 00012 { 00013 static const int nOrbits = 3564; 00014 if (!complete()) return nOrbits; 00015 int diff = recordBX().bx() - triggerBx() + 3; 00016 if (diff > nOrbits/2) diff -= nOrbits; 00017 if (diff < -nOrbits/2) diff += nOrbits; 00018 return diff; 00019 } 00020 00021 00022 void EventRecords::add(const DataRecord & record) 00023 { 00024 00025 if (record.type() == DataRecord::StartOfBXData) { 00026 theRecordBX = RecordBX(record); 00027 theValidBX = true; 00028 theValidLN = false; 00029 theValidCD = false; 00030 theErrors.clear(); 00031 } 00032 else if (record.type() == DataRecord::StartOfTbLinkInputNumberData) { 00033 theRecordSLD = RecordSLD(record); 00034 theValidLN = true; 00035 theValidCD = false; 00036 } 00037 else if (record.type() == DataRecord::ChamberData) { 00038 theRecordCD = RecordCD(record); 00039 theValidCD = true; 00040 } 00041 else { 00042 // theValidBX = false; 00043 // theValidLN = false; 00044 theValidCD = false; 00045 if ( record.type() > DataRecord::Empty) theErrors.push_back(record); 00046 } 00047 } 00048 00049 bool EventRecords::samePartition(const EventRecords & r) const 00050 { 00051 if (this->recordBX().data() != r.recordBX().data() ) return false; 00052 if (this->recordSLD().data() != r.recordSLD().data() ) return false; 00053 typedef DataRecord::Data Record; 00054 Record mask = 0xFF << 8; 00055 Record lb1 = this->recordCD().data() & mask; 00056 Record lb2 = r.recordCD().data() & mask; 00057 if (lb1 != lb2) return false; 00058 return true; 00059 } 00060 00061 vector<EventRecords> EventRecords::mergeRecords(const vector<EventRecords> & data) 00062 { 00063 std::vector<EventRecords> result; 00064 typedef vector<EventRecords>::const_iterator ICR; 00065 typedef vector<EventRecords>::iterator IR; 00066 for (ICR id= data.begin(), idEnd = data.end(); id != idEnd; ++id) { 00067 bool merged = false; 00068 for (IR ir = result.begin(), irEnd = result.end(); ir != irEnd; ++ir) { 00069 EventRecords & event = *ir; 00070 if (id->samePartition( event)) { 00071 DataRecord::Data lbd = event.recordCD().data(); 00072 lbd |= id->recordCD().data(); 00073 event.add( RecordCD(lbd) ); 00074 merged = true; 00075 } 00076 } 00077 if (!merged) result.push_back(*id); 00078 } 00079 return result; 00080 00081 } 00082 00083 std::string EventRecords::print(const DataRecord::DataRecordType& type) const 00084 { 00085 std::ostringstream str; 00086 str <<" ==>"; 00087 if (type == DataRecord::StartOfBXData && theValidBX) str << theRecordBX.print(); 00088 if (type == DataRecord::StartOfTbLinkInputNumberData&& theValidLN) str << theRecordSLD.print(); 00089 if (type == DataRecord::ChamberData && theValidCD) str << theRecordCD.print(); 00090 if (type == DataRecord::Empty) str <<" EPMTY"; 00091 for (vector<DataRecord>::const_iterator ie=theErrors.begin(); ie < theErrors.end(); ++ie) { 00092 if (type == DataRecord::RDDM) str << ErrorRDDM(*ie).print(); 00093 if (type == DataRecord::SDDM) str << ErrorSDDM(*ie).print(); 00094 if (type == DataRecord::RCDM) str << ErrorRCDM(*ie).print(); 00095 if (type == DataRecord::RDM) str << ErrorRDM(*ie).print(); 00096 } 00097 return str.str(); 00098 }