CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/EcalTBRawToDigi/src/MatacqDataFormatter.cc

Go to the documentation of this file.
00001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 8; -*-
00002 // $Id: MatacqDataFormatter.cc,v 1.7 2008/01/22 18:59:16 muzaffar Exp $
00003 
00004 #include "EventFilter/EcalTBRawToDigi/src/MatacqDataFormatter.h"
00005 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00006 #include "EventFilter/EcalTBRawToDigi/src/MatacqRawEvent.h"
00007 #include "DataFormats/EcalDigi/interface/EcalMatacqDigi.h"
00008 
00009 #include <algorithm>
00010 #include <iomanip>
00011 #include <iostream>
00012 #include <algorithm>
00013 #include <vector>
00014 
00015 
00016 
00017 //#define MATACQ_DEBUG
00018 
00019 void  MatacqTBDataFormatter::interpretRawData(const FEDRawData & data, EcalMatacqDigiCollection& matacqDigiCollection) {
00020 #if MATACQ_DEBUG
00021   std::cout << "****************************************************************\n";
00022   std::cout << "********************** MATACQ decoder **************************\n";
00023   std::cout << "****************************************************************\n";
00024   std::cout << "FEDRawData: \n";
00025   char oldPad = std::cout.fill('0');
00026   for(int i=0; i < max(100, (int)data.size()); ++i){
00027     std::cout << std::hex << std::setw(2) << (int)(data.data()[i])
00028          << ((i+1)%8?" ":"\n") ;
00029   }
00030   std::cout.fill(oldPad);
00031   std::cout << "======================================================================\n";
00032 #endif //MATACQ_DEBUG defined
00033   
00034   MatacqTBRawEvent matacq(data.data(), data.size());
00035 
00036 #if MATACQ_DEBUG
00037   printData(std::cout, matacq);
00038 #endif //MATACQ_DEBUG defined
00039 
00040   const double ns = 1.e-9; //ns->s
00041   const double ps = 1.e-12;//ps->s
00042   double ts = ns/matacq.getFreqGHz();
00043   double tTrig = matacq.getTTrigPs()<.5*std::numeric_limits<int>::max()?
00044     ps*matacq.getTTrigPs():999.;
00045   int version = matacq.getMatacqDataFormatVersion();
00046   
00047   std::vector<int16_t> samples;
00048   //FIXME: the interpretRawData method should fill an EcalMatacqDigiCollection
00049   //instead of an EcalMatacqDigi because Matacq channels are several.
00050   //In the meamtime copy only the first channel appearing in data:
00051   const std::vector<MatacqTBRawEvent::ChannelData>& chData = matacq.getChannelData();
00052   for(unsigned iCh=0; iCh < chData.size(); ++iCh){
00053     //copy time samples into a vector:
00054     samples.resize(chData[iCh].nSamples);
00055     copy(chData[iCh].samples, chData[iCh].samples+chData[iCh].nSamples,
00056          samples.begin());
00057     int chId = chData[iCh].chId;
00058     std::vector<int16_t> empty;
00059     EcalMatacqDigi matacqDigi(empty, chId, ts, version, tTrig);
00060     matacqDigiCollection.push_back(matacqDigi);
00061     matacqDigiCollection.back().swap(samples); //swap is more efficient than a copy
00062   }
00063 }
00064 
00065 void MatacqTBDataFormatter::printData(std::ostream& out, const MatacqTBRawEvent& matacq) const{
00066   std::cout << "FED id: " << std::hex << "0x" << matacq.getFedId() << std::dec << "\n";
00067   std::cout << "Event id (lv1): " 
00068        << std::hex << "0x" << matacq.getEventId() << std::dec << "\n";
00069   std::cout << "FOV: " << std::hex << "0x" << matacq.getFov() << std::dec << "\n";
00070   std::cout << "BX id: " << std::hex << "0x" << matacq.getBxId() << std::dec << "\n";
00071   std::cout << "Trigger type: " 
00072        << std::hex << "0x" << matacq.getTriggerType() << std::dec << "\n";
00073   std::cout << "DCC Length: " << matacq.getDccLen() << "\n";
00074   std::cout << "Run number: " << matacq.getRunNum() << "\n";
00075   std::cout << "Field 'DCC errors': " 
00076        << std::hex << "0x" << matacq.getDccErrors() << std::dec << "\n";
00077   
00078   if(matacq.getStatus()){
00079     std::cout << "Error in matacq data. Errot code: "
00080          << std::hex << "0x" << matacq.getStatus() << std::dec << "\n";
00081   }
00082   
00083   std::cout << "MATACQ data format version: " << matacq.getMatacqDataFormatVersion()
00084        << "\n";
00085   std::cout << "Sampling frequency: " << matacq.getFreqGHz() << " GHz\n";
00086   std::cout << "MATACQ channel count: " << matacq.getChannelCount() << "\n";
00087   time_t timeStamp = matacq.getTimeStamp();
00088   std::cout << "Data acquired on : " << ctime(&timeStamp);
00089 
00090   const std::vector<MatacqTBRawEvent::ChannelData>& channels = matacq.getChannelData();
00091   for(unsigned i=0; i< channels.size(); ++i){
00092     std::cout << "-------------------------------------- Channel "
00093          << channels[i].chId
00094          << ": " << std::setw(4) << channels[i].nSamples
00095          << " samples --------------------------------------\n";
00096     
00097     for(int iSample = 0; iSample<channels[i].nSamples; ++iSample){
00098       MatacqTBRawEvent::int16le_t adc = (channels[i].samples)[iSample];
00099       std::cout << std::setw(4) << adc
00100            << ((iSample%20==19)?"\n":" ");
00101     }
00102   }
00103   std::cout << "=================================================="
00104     "==================================================\n\n";   
00105 }