Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:57

0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 8; -*-
0002 
0003 #include "EventFilter/EcalTBRawToDigi/src/MatacqDataFormatter.h"
0004 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0005 #include "EventFilter/EcalTBRawToDigi/src/MatacqRawEvent.h"
0006 #include "DataFormats/EcalDigi/interface/EcalMatacqDigi.h"
0007 
0008 #include <algorithm>
0009 #include <iomanip>
0010 #include <iostream>
0011 #include <algorithm>
0012 #include <vector>
0013 
0014 //#define MATACQ_DEBUG
0015 
0016 void MatacqTBDataFormatter::interpretRawData(const FEDRawData& data, EcalMatacqDigiCollection& matacqDigiCollection) {
0017 #if MATACQ_DEBUG
0018   std::cout << "****************************************************************\n";
0019   std::cout << "********************** MATACQ decoder **************************\n";
0020   std::cout << "****************************************************************\n";
0021   std::cout << "FEDRawData: \n";
0022   char oldPad = std::cout.fill('0');
0023   for (int i = 0; i < max(100, (int)data.size()); ++i) {
0024     std::cout << std::hex << std::setw(2) << (int)(data.data()[i]) << ((i + 1) % 8 ? " " : "\n");
0025   }
0026   std::cout.fill(oldPad);
0027   std::cout << "======================================================================\n";
0028 #endif  //MATACQ_DEBUG defined
0029 
0030   MatacqTBRawEvent matacq(data.data(), data.size());
0031 
0032 #if MATACQ_DEBUG
0033   printData(std::cout, matacq);
0034 #endif  //MATACQ_DEBUG defined
0035 
0036   const double ns = 1.e-9;   //ns->s
0037   const double ps = 1.e-12;  //ps->s
0038   double ts = ns / matacq.getFreqGHz();
0039   double tTrig = matacq.getTTrigPs() < .5 * std::numeric_limits<int>::max() ? ps * matacq.getTTrigPs() : 999.;
0040   int version = matacq.getMatacqDataFormatVersion();
0041 
0042   std::vector<int16_t> samples;
0043   //FIXME: the interpretRawData method should fill an EcalMatacqDigiCollection
0044   //instead of an EcalMatacqDigi because Matacq channels are several.
0045   //In the meamtime copy only the first channel appearing in data:
0046   const std::vector<MatacqTBRawEvent::ChannelData>& chData = matacq.getChannelData();
0047   for (unsigned iCh = 0; iCh < chData.size(); ++iCh) {
0048     //copy time samples into a vector:
0049     samples.resize(chData[iCh].nSamples);
0050     copy(chData[iCh].samples, chData[iCh].samples + chData[iCh].nSamples, samples.begin());
0051     int chId = chData[iCh].chId;
0052     std::vector<int16_t> empty;
0053     EcalMatacqDigi matacqDigi(empty, chId, ts, version, tTrig);
0054     matacqDigiCollection.push_back(matacqDigi);
0055     matacqDigiCollection.back().swap(samples);  //swap is more efficient than a copy
0056   }
0057 }
0058 
0059 void MatacqTBDataFormatter::printData(std::ostream& out, const MatacqTBRawEvent& matacq) const {
0060   std::cout << "FED id: " << std::hex << "0x" << matacq.getFedId() << std::dec << "\n";
0061   std::cout << "Event id (lv1): " << std::hex << "0x" << matacq.getEventId() << std::dec << "\n";
0062   std::cout << "FOV: " << std::hex << "0x" << matacq.getFov() << std::dec << "\n";
0063   std::cout << "BX id: " << std::hex << "0x" << matacq.getBxId() << std::dec << "\n";
0064   std::cout << "Trigger type: " << std::hex << "0x" << matacq.getTriggerType() << std::dec << "\n";
0065   std::cout << "DCC Length: " << matacq.getDccLen() << "\n";
0066   std::cout << "Run number: " << matacq.getRunNum() << "\n";
0067   std::cout << "Field 'DCC errors': " << std::hex << "0x" << matacq.getDccErrors() << std::dec << "\n";
0068 
0069   if (matacq.getStatus()) {
0070     std::cout << "Error in matacq data. Errot code: " << std::hex << "0x" << matacq.getStatus() << std::dec << "\n";
0071   }
0072 
0073   std::cout << "MATACQ data format version: " << matacq.getMatacqDataFormatVersion() << "\n";
0074   std::cout << "Sampling frequency: " << matacq.getFreqGHz() << " GHz\n";
0075   std::cout << "MATACQ channel count: " << matacq.getChannelCount() << "\n";
0076   time_t timeStamp = matacq.getTimeStamp();
0077   std::cout << "Data acquired on : " << ctime(&timeStamp);
0078 
0079   const std::vector<MatacqTBRawEvent::ChannelData>& channels = matacq.getChannelData();
0080   for (unsigned i = 0; i < channels.size(); ++i) {
0081     std::cout << "-------------------------------------- Channel " << channels[i].chId << ": " << std::setw(4)
0082               << channels[i].nSamples << " samples --------------------------------------\n";
0083 
0084     for (int iSample = 0; iSample < channels[i].nSamples; ++iSample) {
0085       MatacqTBRawEvent::int16le_t adc = (channels[i].samples)[iSample];
0086       std::cout << std::setw(4) << adc << ((iSample % 20 == 19) ? "\n" : " ");
0087     }
0088   }
0089   std::cout << "=================================================="
0090                "==================================================\n\n";
0091 }