CMS 3D CMS Logo

ESDataFormatterV1_1.cc
Go to the documentation of this file.
1 
7 
9 
10 const int ESDataFormatterV1_1::bDHEAD = 2;
11 const int ESDataFormatterV1_1::bDH = 6;
12 const int ESDataFormatterV1_1::bDEL = 24;
13 const int ESDataFormatterV1_1::bDERR = 8;
14 const int ESDataFormatterV1_1::bDRUN = 24;
15 const int ESDataFormatterV1_1::bDRUNTYPE = 32;
16 const int ESDataFormatterV1_1::bDTRGTYPE = 16;
17 const int ESDataFormatterV1_1::bDCOMFLAG = 8;
18 const int ESDataFormatterV1_1::bDORBIT = 32;
19 const int ESDataFormatterV1_1::bDVMAJOR = 8;
20 const int ESDataFormatterV1_1::bDVMINOR = 8;
21 const int ESDataFormatterV1_1::bDCH = 4;
22 const int ESDataFormatterV1_1::bDOPTO = 8;
23 
24 const int ESDataFormatterV1_1::sDHEAD = 26;
25 const int ESDataFormatterV1_1::sDH = 24;
26 const int ESDataFormatterV1_1::sDEL = 0;
27 const int ESDataFormatterV1_1::sDERR = bDEL + sDEL;
28 const int ESDataFormatterV1_1::sDRUN = 0;
29 const int ESDataFormatterV1_1::sDRUNTYPE = 0;
30 const int ESDataFormatterV1_1::sDTRGTYPE = 0;
31 const int ESDataFormatterV1_1::sDCOMFLAG = bDTRGTYPE + sDTRGTYPE;
32 const int ESDataFormatterV1_1::sDORBIT = 0;
33 const int ESDataFormatterV1_1::sDVMINOR = 8;
34 const int ESDataFormatterV1_1::sDVMAJOR = bDVMINOR + sDVMINOR;
35 const int ESDataFormatterV1_1::sDCH = 0;
36 const int ESDataFormatterV1_1::sDOPTO = 16;
37 
38 const int ESDataFormatterV1_1::bKEC = 8; // KCHIP packet event counter
39 const int ESDataFormatterV1_1::bKFLAG2 = 8;
40 const int ESDataFormatterV1_1::bKBC = 12; // KCHIP packet bunch counter
41 const int ESDataFormatterV1_1::bKFLAG1 = 4;
42 const int ESDataFormatterV1_1::bKET = 1;
43 const int ESDataFormatterV1_1::bKCRC = 1;
44 const int ESDataFormatterV1_1::bKCE = 1;
45 const int ESDataFormatterV1_1::bKID = 11;
46 const int ESDataFormatterV1_1::bFIBER = 6; // Fiber number
47 const int ESDataFormatterV1_1::bKHEAD1 = 2;
48 const int ESDataFormatterV1_1::bKHEAD2 = 2;
49 
50 const int ESDataFormatterV1_1::sKEC = 0;
51 const int ESDataFormatterV1_1::sKFLAG2 = bKEC + sKEC;
52 const int ESDataFormatterV1_1::sKBC = bKFLAG2 + sKFLAG2;
53 const int ESDataFormatterV1_1::sKFLAG1 = bKBC + sKBC;
54 const int ESDataFormatterV1_1::sKET = 0;
55 const int ESDataFormatterV1_1::sKCRC = bKET + sKET;
56 const int ESDataFormatterV1_1::sKCE = bKCRC + sKCRC;
57 const int ESDataFormatterV1_1::sKID = bKCE + sKCE + 5;
58 const int ESDataFormatterV1_1::sFIBER = bKID + sKID + 1;
59 const int ESDataFormatterV1_1::sKHEAD1 = bFIBER + sFIBER + 2;
60 const int ESDataFormatterV1_1::sKHEAD2 = bKHEAD1 + sKHEAD1;
61 
62 const int ESDataFormatterV1_1::bADC0 = 16;
63 const int ESDataFormatterV1_1::bADC1 = 16;
64 const int ESDataFormatterV1_1::bADC2 = 16;
65 const int ESDataFormatterV1_1::bPACE = 2;
66 const int ESDataFormatterV1_1::bSTRIP = 5;
67 const int ESDataFormatterV1_1::bE0 = 1;
68 const int ESDataFormatterV1_1::bE1 = 1;
69 const int ESDataFormatterV1_1::bHEAD = 2;
70 
71 const int ESDataFormatterV1_1::sADC0 = 0;
72 const int ESDataFormatterV1_1::sADC1 = bADC0 + sADC0;
73 const int ESDataFormatterV1_1::sADC2 = 0;
74 const int ESDataFormatterV1_1::sPACE = bADC2 + sADC2;
75 const int ESDataFormatterV1_1::sSTRIP = bPACE + sPACE;
76 const int ESDataFormatterV1_1::sE0 = bSTRIP + sSTRIP + 1;
77 const int ESDataFormatterV1_1::sE1 = bE0 + sE0;
78 const int ESDataFormatterV1_1::sHEAD = bE1 + sE1 + 4;
79 
80 using namespace std;
81 using namespace edm;
82 
84 
86 
87 // FEDRawData * ESDataFormatterV1_1::DigiToRawDCC(int fedId, const Digis & digis) {
88 
89 // int ts[3] = {0, 0, 0};
90 // Word32 word1, word2;
91 // Word64 word;
92 
93 // for (Digis::const_iterator itr = digis.begin(); itr != digis.end(); ++itr) {
94 
95 // if (itr->first != fedId) continue;
96 // const DetDigis & detDigis = itr->second;
97 
98 // for (DetDigis::const_iterator it = detDigis.begin(); it != detDigis.end(); ++it) {
99 
100 // const ESDataFrame& dataframe = (*it);
101 // // const ESDetId& detId = dataframe.id();
102 
103 // for (int is=0; is<dataframe.size(); ++is) ts[is] = dataframe.sample(is).adc();
104 // }
105 // }
106 
107 // // DCC words
108 // vector<Word64> DCCwords;
109 // word2 = (run_number_ << 0) ;
110 // word1 = 0;
111 // word = (Word64(word2) << 32 ) | Word64(word1);
112 
113 // DCCwords.push_back(word);
114 // for (int i=0; i<5; ++i) {
115 // word = 0;
116 // DCCwords.push_back(word);
117 // }
118 
119 // FEDRawData * rawData = new FEDRawData(0);
120 
121 // return rawData;
122 // }
123 
124 void ESDataFormatterV1_1::DigiToRaw(int fedId, Digis& digis, FEDRawData& fedRawData, const Meta_Data& meta_data) const {
125  map<int, vector<Word64> > map_data;
126  map_data.clear();
127 
128  int ts[3] = {0, 0, 0};
129  Word32 word1, word2;
130  Word64 word;
131  vector<Word64> words;
132 
133  const DetDigis& detDigis = digis[fedId];
134 
135  // if (detDigis==digis.end()) {
136  // cout << "ESDataFormatterV1_1::DigiToRaw : could not find digi vector in digis map for fedID: "
137  // << fedId << endl ;
138  // return 0;
139  // }
140 
141  for (DetDigis::const_iterator it = detDigis.begin(); it != detDigis.end(); ++it) {
142  const ESDataFrame& dataframe = (*it);
143  const ESDetId& detId = dataframe.id();
144 
145  for (int is = 0; is < dataframe.size(); ++is)
146  ts[is] = dataframe.sample(is).adc();
147 
148  // calculate fake kchip and pace id
149  int kchip = -1;
150  int pace = -1;
151  int ix = -1;
152  int iy = -1;
153 
154  ix = detId.six() % 2;
155  iy = detId.siy() % 2;
156  if (ix == 1 && iy == 1)
157  pace = 0;
158  else if (ix == 0 && iy == 1)
159  pace = 1;
160  else if (ix == 1 && iy == 0)
161  pace = 2;
162  else if (ix == 0 && iy == 0)
163  pace = 3;
164 
165  ix = (1 + detId.six()) / 2;
166  iy = (1 + detId.siy()) / 2;
167  if (detId.zside() == 1 && detId.plane() == 1)
168  kchip = ix + (iy - 1) * 20 - 1;
169  else if (detId.zside() == 1 && detId.plane() == 2)
170  kchip = ix + (iy - 1) * 20 + 399;
171  else if (detId.zside() == -1 && detId.plane() == 1)
172  kchip = ix + (iy - 1) * 20 + 799;
173  else if (detId.zside() == -1 && detId.plane() == 2)
174  kchip = ix + (iy - 1) * 20 + 1199;
175 
176  if (debug_)
177  cout << "Si : " << detId.zside() << " " << detId.plane() << " " << detId.six() << " " << detId.siy() << " "
178  << detId.strip() << " (" << kchip << "," << pace << ") " << ts[2] << " " << ts[1] << " " << ts[0] << endl;
179 
180  word1 = (ts[1] << sADC1) | (ts[0] << sADC0);
181  word2 =
182  (2 << sHEAD) | (0 << sE1) | (0 << sE0) | ((detId.strip() - 1) << sSTRIP) | (pace << sPACE) | (ts[2] << sADC2);
183  word = (Word64(word2) << 32) | Word64(word1);
184 
185  map_data[kchip].push_back(word);
186  }
187 
188  map<int, vector<Word64> >::const_iterator kit;
189  for (kit = map_data.begin(); kit != map_data.end(); ++kit) {
190  if (debug_)
191  cout << "KCHIP : " << kit->first << endl;
192 
193  word1 = (0 << sKFLAG1) | (0 << sKBC) | (0 << sKFLAG2) | (0 << sKEC);
194  word2 = (1 << sKHEAD2) | (0 << sKHEAD1) | (0 << sFIBER) | (kit->first << sKID) | (0 << sKCE) | (0 << sKCRC) |
195  (0 << sKET);
196  word = (Word64(word2) << 32) | Word64(word1);
197 
198  if (debug_)
199  cout << "KCHIP : " << print(word) << endl;
200  words.push_back(word);
201 
202  const vector<Word64>& data = kit->second;
203  for (unsigned int id = 0; id < data.size(); ++id) {
204  if (debug_)
205  cout << "Data : " << print(data[id]) << endl;
206  words.push_back(data[id]);
207  }
208  }
209 
210  int dataSize = (words.size() + 8) * sizeof(Word64);
211 
212  // DCC words
213  vector<Word64> DCCwords;
214  word2 = (0 << sDHEAD) | (1 << sDH) | (meta_data.run_number << sDRUN);
215  word1 = (dataSize << sDEL);
216  word = (Word64(word2) << 32) | Word64(word1);
217  DCCwords.push_back(word);
218  word2 = (0 << sDHEAD) | (2 << sDH);
219  word1 = 0;
220  word = (Word64(word2) << 32) | Word64(word1);
221  DCCwords.push_back(word);
222  word2 = (0 << sDHEAD) | (3 << sDH) | (1 << sDVMAJOR) | (1 << sDVMINOR);
223  word1 = (meta_data.orbit_number << sDORBIT);
224  word = (Word64(word2) << 32) | Word64(word1);
225  DCCwords.push_back(word);
226  word2 = (0 << sDHEAD) | (4 << sDH);
227  word1 = 0;
228  word = (Word64(word2) << 32) | Word64(word1);
229  DCCwords.push_back(word);
230  word2 = (0 << sDHEAD) | (5 << sDH);
231  word1 = 0;
232  word = (Word64(word2) << 32) | Word64(word1);
233  DCCwords.push_back(word);
234  word2 = (0 << sDHEAD) | (6 << sDH);
235  word1 = 0;
236  word = (Word64(word2) << 32) | Word64(word1);
237  DCCwords.push_back(word);
238 
239  // Output (data size in Bytes)
240  fedRawData.resize(dataSize);
241 
242  Word64* w = reinterpret_cast<Word64*>(fedRawData.data());
243 
244  // header
245  FEDHeader::set(reinterpret_cast<unsigned char*>(w), trgtype_, meta_data.lv1, meta_data.bx, fedId);
246  w++;
247 
248  // ES-DCC
249  for (unsigned int i = 0; i < DCCwords.size(); ++i) {
250  if (debug_)
251  cout << "DCC : " << print(DCCwords[i]) << endl;
252  *w = DCCwords[i];
253  w++;
254  }
255 
256  // event data
257  for (unsigned int i = 0; i < words.size(); ++i) {
258  *w = words[i];
259  w++;
260  }
261 
262  // trailer
263  FEDTrailer::set(reinterpret_cast<unsigned char*>(w),
264  dataSize / sizeof(Word64),
265  evf::compute_crc(fedRawData.data(), dataSize),
266  0,
267  0);
268  w++;
269 }
static const int bDRUNTYPE
const ESDetId & id() const
Definition: ESDataFrame.h:19
static const int bDEL
static const int sDEL
static const int bE1
static const int sKFLAG2
static const int sDHEAD
static const int bHEAD
static const int bKCE
static const int bADC1
static const int bKET
static const int bKID
int size() const
Definition: ESDataFrame.h:21
T w() const
static const int sDORBIT
static const int bDORBIT
static const int sFIBER
static const int bDCOMFLAG
static const int sDVMINOR
static const int sDTRGTYPE
static const int sKCE
static const int bKFLAG1
static const int bDERR
static const int sPACE
static const int bDCH
int zside() const
Definition: ESDetId.h:39
static const int sKHEAD1
static const int bKBC
std::map< int, DetDigis > Digis
static const int bKEC
static const int sDOPTO
static const int sKHEAD2
static const int bDVMINOR
static const int sKEC
static const int sHEAD
int adc() const
get the ADC sample (singed 16 bits)
Definition: ESSample.h:16
const ESSample & sample(int i) const
Definition: ESDataFrame.h:24
static const int sDERR
uint64_t word
static const int sADC1
static const int bKHEAD1
ESDataFormatter::Word64 Word64
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:31
static const int bKFLAG2
static const int sE0
int plane() const
Definition: ESDetId.h:41
const int trgtype_
static const int bE0
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
static const int sDRUNTYPE
static const int sKCRC
static const int bADC2
static const int bFIBER
static const int sKID
static const int sKET
static const int bKCRC
static const int bDOPTO
static const int sE1
static const int sKBC
static const int bADC0
static const int sADC2
static const int sDRUN
int siy() const
Definition: ESDetId.h:45
static const int sSTRIP
std::string print(const Word64 &word) const
static const int sDCH
static const int bSTRIP
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
const bool debug_
static const int sADC0
int six() const
Definition: ESDetId.h:43
static const int bDTRGTYPE
int strip() const
Definition: ESDetId.h:47
ESDataFormatterV1_1(const edm::ParameterSet &ps)
static const int bDHEAD
static const int bDRUN
static void set(unsigned char *header, uint8_t triggerType, uint32_t lvl1ID, uint16_t bxID, uint16_t sourceID, uint8_t version=0, bool moreHeaders=false)
Set all fields in the header.
Definition: FEDHeader.cc:25
static const int sDH
static const int sKFLAG1
void DigiToRaw(int fedId, Digis &digis, FEDRawData &fedRawData, const Meta_Data &meta_data) const override
static const int bKHEAD2
static const int sDCOMFLAG
static const int sDVMAJOR
static const int bDH
static const int bDVMAJOR
static const int bPACE
std::vector< ESDataFrame > DetDigis