CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MatacqDataFormatter.cc
Go to the documentation of this file.
1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 8; -*-
2 // $Id: MatacqDataFormatter.cc,v 1.1 2009/02/25 14:44:25 pgras Exp $
3 
9 
10 #include <algorithm>
11 #include <iomanip>
12 #include <iostream>
13 #include <algorithm>
14 #include <vector>
15 
16 using namespace std;
17 
18 //#define MATACQ_DEBUG
19 
20 void
22 #if MATACQ_DEBUG
23  cout << "****************************************************************\n";
24  cout << "********************** MATACQ decoder **************************\n";
25  cout << "****************************************************************\n";
26  cout << "FEDRawData: \n";
27  char oldPad = cout.fill('0');
28  for(int i=0; i < max(100, (int)data.size()); ++i){
29  cout << hex << setw(2) << (int)(data.data()[i])
30  << ((i+1)%8?" ":"\n") ;
31  }
32  cout.fill(oldPad);
33  cout << "======================================================================\n";
34 #endif //MATACQ_DEBUG defined
35  interpretRawData(MatacqRawEvent(data.data(), data.size()),
36  matacqDigiCollection);
37 }
38 
39 void
41 #if MATACQ_DEBUG
42  printData(cout, matacq);
43 #endif //MATACQ_DEBUG defined
44 
45  const double ns = 1.e-9; //ns->s
46  const double ps = 1.e-12;//ps->s
47  double ts = ns/matacq.getFreqGHz();
48  double tTrig = matacq.getTTrigPs()<.5*numeric_limits<int>::max()?
49  ps*matacq.getTTrigPs():999.;
50  int version = matacq.getMatacqDataFormatVersion();
51 
52  vector<int16_t> samples;
53  //FIXME: the interpretRawData method should fill an EcalMatacqDigiCollection
54  //instead of an EcalMatacqDigi because Matacq channels are several.
55  //In the meamtime copy only the first channel appearing in data:
56  const vector<MatacqRawEvent::ChannelData>& chData = matacq.getChannelData();
57  for(unsigned iCh=0; iCh < chData.size(); ++iCh){
58  //copy time samples into a vector:
59  samples.resize(chData[iCh].nSamples);
60  copy(chData[iCh].samples, chData[iCh].samples+chData[iCh].nSamples,
61  samples.begin());
62  int chId = chData[iCh].chId;
63  vector<int16_t> empty;
64  EcalMatacqDigi matacqDigi(empty, chId, ts, version, tTrig);
65 #if (defined(ECAL_MATACQ_DIGI_VERS) && (ECAL_MATACQ_DIGI_VERS >= 2))
66  matacqDigi.bxId(matacq.getBxId());
67  matacqDigi.l1a(matacq.getEventId());
68  matacqDigi.triggerType(matacq.getTriggerType());
69  matacqDigi.orbitId(matacq.getOrbitId());
70  matacqDigi.trigRec(matacq.getTrigRec());
71  matacqDigi.postTrig(matacq.getPostTrig());
72  matacqDigi.vernier(matacq.getVernier());
73  matacqDigi.delayA(matacq.getDelayA());
74  matacqDigi.emtcDelay(matacq.getEmtcDelay());
75  matacqDigi.emtcPhase(matacq.getEmtcPhase());
76  matacqDigi.attenuation_dB(matacq.getAttenuation_dB());
77  matacqDigi.laserPower(matacq.getLaserPower());
78  timeval t;
79  matacq.getTimeStamp(t);
80  matacqDigi.timeStamp(t);
81 #endif //matacq digi version >=2
82  matacqDigiCollection.push_back(matacqDigi);
83  matacqDigiCollection.back().swap(samples); //swap is more efficient than a copy
84  }
85 }
86 
87 void MatacqDataFormatter::printData(ostream& out, const MatacqRawEvent& matacq) const{
88  cout << "FED id: " << hex << "0x" << matacq.getFedId() << dec << "\n";
89  cout << "Event id (lv1): "
90  << hex << "0x" << matacq.getEventId() << dec << "\n";
91  cout << "FOV: " << hex << "0x" << matacq.getFov() << dec << "\n";
92  cout << "BX id: " << hex << "0x" << matacq.getBxId() << dec << "\n";
93  cout << "Trigger type: "
94  << hex << "0x" << matacq.getTriggerType() << dec << "\n";
95  cout << "DCC Length: " << matacq.getDccLen() << "\n";
96  cout << "Run number: " << matacq.getRunNum() << "\n";
97  cout << "Field 'DCC errors': "
98  << hex << "0x" << matacq.getDccErrors() << dec << "\n";
99 
100  if(matacq.getStatus()){
101  cout << "Error in matacq data. Errot code: "
102  << hex << "0x" << matacq.getStatus() << dec << "\n";
103  }
104 
105  cout << "MATACQ data format version: " << matacq.getMatacqDataFormatVersion()
106  << "\n";
107  cout << "Sampling frequency: " << matacq.getFreqGHz() << " GHz\n";
108  cout << "MATACQ channel count: " << matacq.getChannelCount() << "\n";
109  time_t timeStamp = matacq.getTimeStamp();
110  cout << "Data acquired on : " << ctime(&timeStamp);
111 
112  const vector<MatacqRawEvent::ChannelData>& channels = matacq.getChannelData();
113  for(unsigned i=0; i< channels.size(); ++i){
114  cout << "-------------------------------------- Channel "
115  << channels[i].chId
116  << ": " << setw(4) << channels[i].nSamples
117  << " samples --------------------------------------\n";
118 
119  for(int iSample = 0; iSample<channels[i].nSamples; ++iSample){
120  MatacqRawEvent::int16le_t adc = (channels[i].samples)[iSample];
121  cout << setw(4) << adc
122  << ((iSample%20==19)?"\n":" ");
123  }
124  }
125  cout << "=================================================="
126  "==================================================\n\n";
127 }
128 
int adc(sample_type sample)
get the ADC sample (12 bits)
int getTTrigPs() const
int i
Definition: DBlmapReader.cc:9
timeval timeStamp() const
int emtcDelay() const
static unsigned getRunNum(unsigned char *data, size_t size)
int getEmtcPhase() const
int getFreqGHz() const
int getDelayA() const
int getPostTrig() const
static unsigned getOrbitId(unsigned char *data, size_t size)
int getTrigRec() const
void push_back(T const &t)
std::vector< int > vernier() const
int32_t getStatus() const
int delayA() const
int attenuation_dB() const
int emtcPhase() const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
unsigned getDccLen() const
int getChannelCount() const
int getMatacqDataFormatVersion() const
const T & max(const T &a, const T &b)
void printData(std::ostream &out, const MatacqRawEvent &event) const
UInt_t orbitId() const
int getDccErrors() const
int getTriggerType() const
int getBxId() const
int triggerType() const
int l1a() const
tuple out
Definition: dbtoconf.py:99
int getEmtcDelay() const
int getAttenuation_dB() const
int getFedId() const
unsigned getEventId() const
int getLaserPower() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
time_t getTimeStamp() const
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
int postTrig() const
int trigRec() const
const std::vector< ChannelData > & getChannelData() const
void interpretRawData(const FEDRawData &data, EcalMatacqDigiCollection &matacqDigiCollection)
tuple cout
Definition: gather_cfg.py:121
int getFov() const
std::vector< int > getVernier() const
int laserPower() const
int bxId() const
std::string timeStamp(TimePoint_t)
Definition: Utils.cc:23
const_reference back() const