CMS 3D CMS Logo

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