File indexing completed on 2023-03-17 10:59:42
0001
0002
0003 #include "EventFilter/EcalRawToDigi/src/MatacqDataFormatter.h"
0004 #include "EventFilter/EcalRawToDigi/interface/MatacqRawEvent.h"
0005 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0006 #include "DataFormats/EcalDigi/interface/EcalMatacqDigi.h"
0007 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0008
0009 #include <algorithm>
0010 #include <iomanip>
0011 #include <iostream>
0012 #include <vector>
0013
0014 using namespace std;
0015
0016
0017
0018 void MatacqDataFormatter::interpretRawData(const FEDRawData& data, EcalMatacqDigiCollection& matacqDigiCollection) {
0019 #if MATACQ_DEBUG
0020 cout << "****************************************************************\n";
0021 cout << "********************** MATACQ decoder **************************\n";
0022 cout << "****************************************************************\n";
0023 cout << "FEDRawData: \n";
0024 char oldPad = cout.fill('0');
0025 for (int i = 0; i < max(100, (int)data.size()); ++i) {
0026 cout << hex << setw(2) << (int)(data.data()[i]) << ((i + 1) % 8 ? " " : "\n");
0027 }
0028 cout.fill(oldPad);
0029 cout << "======================================================================\n";
0030 #endif
0031 interpretRawData(MatacqRawEvent(data.data(), data.size()), matacqDigiCollection);
0032 }
0033
0034 void MatacqDataFormatter::interpretRawData(const MatacqRawEvent& matacq,
0035 EcalMatacqDigiCollection& matacqDigiCollection) {
0036 #if MATACQ_DEBUG
0037 printData(cout, matacq);
0038 #endif
0039
0040 const double ns = 1.e-9;
0041 const double ps = 1.e-12;
0042 double ts = ns / matacq.getFreqGHz();
0043 double tTrig = matacq.getTTrigPs() < .5 * numeric_limits<int>::max() ? ps * matacq.getTTrigPs() : 999.;
0044 int version = matacq.getMatacqDataFormatVersion();
0045
0046 vector<int16_t> samples;
0047
0048
0049
0050 const vector<MatacqRawEvent::ChannelData>& chData = matacq.getChannelData();
0051 for (unsigned iCh = 0; iCh < chData.size(); ++iCh) {
0052
0053 samples.resize(chData[iCh].nSamples);
0054 copy(chData[iCh].samples, chData[iCh].samples + chData[iCh].nSamples, samples.begin());
0055 int chId = chData[iCh].chId;
0056 vector<int16_t> empty;
0057 EcalMatacqDigi matacqDigi(empty, chId, ts, version, tTrig);
0058 #if (defined(ECAL_MATACQ_DIGI_VERS) && (ECAL_MATACQ_DIGI_VERS >= 2))
0059 matacqDigi.bxId(matacq.getBxId());
0060 matacqDigi.l1a(matacq.getEventId());
0061 matacqDigi.triggerType(matacq.getTriggerType());
0062 matacqDigi.orbitId(matacq.getOrbitId());
0063 matacqDigi.trigRec(matacq.getTrigRec());
0064 matacqDigi.postTrig(matacq.getPostTrig());
0065 matacqDigi.vernier(matacq.getVernier());
0066 matacqDigi.delayA(matacq.getDelayA());
0067 matacqDigi.emtcDelay(matacq.getEmtcDelay());
0068 matacqDigi.emtcPhase(matacq.getEmtcPhase());
0069 matacqDigi.attenuation_dB(matacq.getAttenuation_dB());
0070 matacqDigi.laserPower(matacq.getLaserPower());
0071 timeval t;
0072 matacq.getTimeStamp(t);
0073 matacqDigi.timeStamp(t);
0074 #endif
0075 matacqDigiCollection.push_back(matacqDigi);
0076 matacqDigiCollection.back().swap(samples);
0077 }
0078 }
0079
0080 void MatacqDataFormatter::printData(ostream& out, const MatacqRawEvent& matacq) const {
0081 cout << "FED id: " << hex << "0x" << matacq.getFedId() << dec << "\n";
0082 cout << "Event id (lv1): " << hex << "0x" << matacq.getEventId() << dec << "\n";
0083 cout << "FOV: " << hex << "0x" << matacq.getFov() << dec << "\n";
0084 cout << "BX id: " << hex << "0x" << matacq.getBxId() << dec << "\n";
0085 cout << "Trigger type: " << hex << "0x" << matacq.getTriggerType() << dec << "\n";
0086 cout << "DCC Length: " << matacq.getDccLen() << "\n";
0087 cout << "Run number: " << matacq.getRunNum() << "\n";
0088 cout << "Field 'DCC errors': " << hex << "0x" << matacq.getDccErrors() << dec << "\n";
0089
0090 if (matacq.getStatus()) {
0091 cout << "Error in matacq data. Errot code: " << hex << "0x" << matacq.getStatus() << dec << "\n";
0092 }
0093
0094 cout << "MATACQ data format version: " << matacq.getMatacqDataFormatVersion() << "\n";
0095 cout << "Sampling frequency: " << matacq.getFreqGHz() << " GHz\n";
0096 cout << "MATACQ channel count: " << matacq.getChannelCount() << "\n";
0097 time_t timeStamp = matacq.getTimeStamp();
0098 cout << "Data acquired on : " << ctime(&timeStamp);
0099
0100 const vector<MatacqRawEvent::ChannelData>& channels = matacq.getChannelData();
0101 for (unsigned i = 0; i < channels.size(); ++i) {
0102 cout << "-------------------------------------- Channel " << channels[i].chId << ": " << setw(4)
0103 << channels[i].nSamples << " samples --------------------------------------\n";
0104
0105 for (int iSample = 0; iSample < channels[i].nSamples; ++iSample) {
0106 MatacqRawEvent::int16le_t adc = (channels[i].samples)[iSample];
0107 cout << setw(4) << adc << ((iSample % 20 == 19) ? "\n" : " ");
0108 }
0109 }
0110 cout << "=================================================="
0111 "==================================================\n\n";
0112 }