Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:59

0001 #include "EventFilter/RPCRawToDigi/interface/EventRecords.h"
0002 #include "DataFormats/RPCDigi/interface/ErrorRCDM.h"
0003 #include "DataFormats/RPCDigi/interface/ErrorRDDM.h"
0004 #include "DataFormats/RPCDigi/interface/ErrorRDM.h"
0005 #include "DataFormats/RPCDigi/interface/ErrorSDDM.h"
0006 
0007 using namespace rpcrawtodigi;
0008 using std::vector;
0009 
0010 int EventRecords::dataToTriggerDelay() const {
0011   static const int nOrbits = 3564;
0012   if (!complete())
0013     return nOrbits;
0014   int diff = recordBX().bx() - triggerBx() + 3;
0015   if (diff > nOrbits / 2)
0016     diff -= nOrbits;
0017   if (diff < -nOrbits / 2)
0018     diff += nOrbits;
0019   return diff;
0020 }
0021 
0022 void EventRecords::add(const DataRecord& record) {
0023   if (record.type() == DataRecord::StartOfBXData) {
0024     theRecordBX = RecordBX(record);
0025     theValidBX = true;
0026     theValidLN = false;
0027     theValidCD = false;
0028     theErrors.clear();
0029   } else if (record.type() == DataRecord::StartOfTbLinkInputNumberData) {
0030     theRecordSLD = RecordSLD(record);
0031     theValidLN = true;
0032     theValidCD = false;
0033   } else if (record.type() == DataRecord::ChamberData) {
0034     theRecordCD = RecordCD(record);
0035     theValidCD = true;
0036   } else {
0037     //    theValidBX = false;
0038     //    theValidLN = false;
0039     theValidCD = false;
0040     if (record.type() > DataRecord::Empty)
0041       theErrors.push_back(record);
0042   }
0043 }
0044 
0045 bool EventRecords::samePartition(const EventRecords& r) const {
0046   if (this->recordBX().data() != r.recordBX().data())
0047     return false;
0048   if (this->recordSLD().data() != r.recordSLD().data())
0049     return false;
0050   typedef DataRecord::Data Record;
0051   Record mask = 0xFF << 8;
0052   Record lb1 = this->recordCD().data() & mask;
0053   Record lb2 = r.recordCD().data() & mask;
0054   if (lb1 != lb2)
0055     return false;
0056   return true;
0057 }
0058 
0059 vector<EventRecords> EventRecords::mergeRecords(const vector<EventRecords>& data) {
0060   std::vector<EventRecords> result;
0061   typedef vector<EventRecords>::const_iterator ICR;
0062   typedef vector<EventRecords>::iterator IR;
0063   for (ICR id = data.begin(), idEnd = data.end(); id != idEnd; ++id) {
0064     bool merged = false;
0065     for (IR ir = result.begin(), irEnd = result.end(); ir != irEnd; ++ir) {
0066       EventRecords& event = *ir;
0067       if (id->samePartition(event)) {
0068         DataRecord::Data lbd = event.recordCD().data();
0069         lbd |= id->recordCD().data();
0070         event.add(RecordCD(lbd));
0071         merged = true;
0072       }
0073     }
0074     if (!merged)
0075       result.push_back(*id);
0076   }
0077   return result;
0078 }
0079 
0080 std::string EventRecords::print(const DataRecord::DataRecordType& type) const {
0081   std::ostringstream str;
0082   str << " ==>";
0083   if (type == DataRecord::StartOfBXData && theValidBX)
0084     str << theRecordBX.print();
0085   if (type == DataRecord::StartOfTbLinkInputNumberData && theValidLN)
0086     str << theRecordSLD.print();
0087   if (type == DataRecord::ChamberData && theValidCD)
0088     str << theRecordCD.print();
0089   if (type == DataRecord::Empty)
0090     str << " EPMTY";
0091   for (vector<DataRecord>::const_iterator ie = theErrors.begin(); ie < theErrors.end(); ++ie) {
0092     if (type == DataRecord::RDDM)
0093       str << ErrorRDDM(*ie).print();
0094     if (type == DataRecord::SDDM)
0095       str << ErrorSDDM(*ie).print();
0096     if (type == DataRecord::RCDM)
0097       str << ErrorRCDM(*ie).print();
0098     if (type == DataRecord::RDM)
0099       str << ErrorRDM(*ie).print();
0100   }
0101   return str.str();
0102 }