Go to the documentation of this file.00001
00002
00003
00004 #include "EventFilter/EcalRawToDigi/src/MatacqDataFormatter.h"
00005 #include "EventFilter/EcalRawToDigi/interface/MatacqRawEvent.h"
00006 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00007 #include "DataFormats/EcalDigi/interface/EcalMatacqDigi.h"
00008 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00009
00010 #include <algorithm>
00011 #include <iomanip>
00012 #include <iostream>
00013 #include <algorithm>
00014 #include <vector>
00015
00016 using namespace std;
00017
00018
00019
00020 void
00021 MatacqDataFormatter::interpretRawData(const FEDRawData & data, EcalMatacqDigiCollection& matacqDigiCollection) {
00022 #if MATACQ_DEBUG
00023 cout << "****************************************************************\n";
00024 cout << "********************** MATACQ decoder **************************\n";
00025 cout << "****************************************************************\n";
00026 cout << "FEDRawData: \n";
00027 char oldPad = cout.fill('0');
00028 for(int i=0; i < max(100, (int)data.size()); ++i){
00029 cout << hex << setw(2) << (int)(data.data()[i])
00030 << ((i+1)%8?" ":"\n") ;
00031 }
00032 cout.fill(oldPad);
00033 cout << "======================================================================\n";
00034 #endif //MATACQ_DEBUG defined
00035 interpretRawData(MatacqRawEvent(data.data(), data.size()),
00036 matacqDigiCollection);
00037 }
00038
00039 void
00040 MatacqDataFormatter::interpretRawData(const MatacqRawEvent& matacq, EcalMatacqDigiCollection& matacqDigiCollection) {
00041 #if MATACQ_DEBUG
00042 printData(cout, matacq);
00043 #endif //MATACQ_DEBUG defined
00044
00045 const double ns = 1.e-9;
00046 const double ps = 1.e-12;
00047 double ts = ns/matacq.getFreqGHz();
00048 double tTrig = matacq.getTTrigPs()<.5*numeric_limits<int>::max()?
00049 ps*matacq.getTTrigPs():999.;
00050 int version = matacq.getMatacqDataFormatVersion();
00051
00052 vector<int16_t> samples;
00053
00054
00055
00056 const vector<MatacqRawEvent::ChannelData>& chData = matacq.getChannelData();
00057 for(unsigned iCh=0; iCh < chData.size(); ++iCh){
00058
00059 samples.resize(chData[iCh].nSamples);
00060 copy(chData[iCh].samples, chData[iCh].samples+chData[iCh].nSamples,
00061 samples.begin());
00062 int chId = chData[iCh].chId;
00063 vector<int16_t> empty;
00064 EcalMatacqDigi matacqDigi(empty, chId, ts, version, tTrig);
00065 #if (defined(ECAL_MATACQ_DIGI_VERS) && (ECAL_MATACQ_DIGI_VERS >= 2))
00066 matacqDigi.bxId(matacq.getBxId());
00067 matacqDigi.l1a(matacq.getEventId());
00068 matacqDigi.triggerType(matacq.getTriggerType());
00069 matacqDigi.orbitId(matacq.getOrbitId());
00070 matacqDigi.trigRec(matacq.getTrigRec());
00071 matacqDigi.postTrig(matacq.getPostTrig());
00072 matacqDigi.vernier(matacq.getVernier());
00073 matacqDigi.delayA(matacq.getDelayA());
00074 matacqDigi.emtcDelay(matacq.getEmtcDelay());
00075 matacqDigi.emtcPhase(matacq.getEmtcPhase());
00076 matacqDigi.attenuation_dB(matacq.getAttenuation_dB());
00077 matacqDigi.laserPower(matacq.getLaserPower());
00078 timeval t;
00079 matacq.getTimeStamp(t);
00080 matacqDigi.timeStamp(t);
00081 #endif //matacq digi version >=2
00082 matacqDigiCollection.push_back(matacqDigi);
00083 matacqDigiCollection.back().swap(samples);
00084 }
00085 }
00086
00087 void MatacqDataFormatter::printData(ostream& out, const MatacqRawEvent& matacq) const{
00088 cout << "FED id: " << hex << "0x" << matacq.getFedId() << dec << "\n";
00089 cout << "Event id (lv1): "
00090 << hex << "0x" << matacq.getEventId() << dec << "\n";
00091 cout << "FOV: " << hex << "0x" << matacq.getFov() << dec << "\n";
00092 cout << "BX id: " << hex << "0x" << matacq.getBxId() << dec << "\n";
00093 cout << "Trigger type: "
00094 << hex << "0x" << matacq.getTriggerType() << dec << "\n";
00095 cout << "DCC Length: " << matacq.getDccLen() << "\n";
00096 cout << "Run number: " << matacq.getRunNum() << "\n";
00097 cout << "Field 'DCC errors': "
00098 << hex << "0x" << matacq.getDccErrors() << dec << "\n";
00099
00100 if(matacq.getStatus()){
00101 cout << "Error in matacq data. Errot code: "
00102 << hex << "0x" << matacq.getStatus() << dec << "\n";
00103 }
00104
00105 cout << "MATACQ data format version: " << matacq.getMatacqDataFormatVersion()
00106 << "\n";
00107 cout << "Sampling frequency: " << matacq.getFreqGHz() << " GHz\n";
00108 cout << "MATACQ channel count: " << matacq.getChannelCount() << "\n";
00109 time_t timeStamp = matacq.getTimeStamp();
00110 cout << "Data acquired on : " << ctime(&timeStamp);
00111
00112 const vector<MatacqRawEvent::ChannelData>& channels = matacq.getChannelData();
00113 for(unsigned i=0; i< channels.size(); ++i){
00114 cout << "-------------------------------------- Channel "
00115 << channels[i].chId
00116 << ": " << setw(4) << channels[i].nSamples
00117 << " samples --------------------------------------\n";
00118
00119 for(int iSample = 0; iSample<channels[i].nSamples; ++iSample){
00120 MatacqRawEvent::int16le_t adc = (channels[i].samples)[iSample];
00121 cout << setw(4) << adc
00122 << ((iSample%20==19)?"\n":" ");
00123 }
00124 }
00125 cout << "=================================================="
00126 "==================================================\n\n";
00127 }
00128