CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:34:40 2009 for CMSSW by  doxygen 1.5.4