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 
83 
85  : ESDataFormatter(ps) {
86 }
87 
89 }
90 
91 // FEDRawData * ESDataFormatterV1_1::DigiToRawDCC(int fedId, const Digis & digis) {
92 
93 // int ts[3] = {0, 0, 0};
94 // Word32 word1, word2;
95 // Word64 word;
96 
97 // for (Digis::const_iterator itr = digis.begin(); itr != digis.end(); ++itr) {
98 
99 // if (itr->first != fedId) continue;
100 // const DetDigis & detDigis = itr->second;
101 
102 // for (DetDigis::const_iterator it = detDigis.begin(); it != detDigis.end(); ++it) {
103 
104 // const ESDataFrame& dataframe = (*it);
105 // // const ESDetId& detId = dataframe.id();
106 
107 // for (int is=0; is<dataframe.size(); ++is) ts[is] = dataframe.sample(is).adc();
108 // }
109 // }
110 
111 // // DCC words
112 // vector<Word64> DCCwords;
113 // word2 = (run_number_ << 0) ;
114 // word1 = 0;
115 // word = (Word64(word2) << 32 ) | Word64(word1);
116 
117 // DCCwords.push_back(word);
118 // for (int i=0; i<5; ++i) {
119 // word = 0;
120 // DCCwords.push_back(word);
121 // }
122 
123 // FEDRawData * rawData = new FEDRawData(0);
124 
125 // return rawData;
126 // }
127 
128 void ESDataFormatterV1_1::DigiToRaw(int fedId, Digis& digis, FEDRawData& fedRawData, const Meta_Data & meta_data) const{
129 
130  map<int, vector<Word64> > map_data;
131  map_data.clear();
132 
133  int ts[3] = {0, 0, 0};
134  Word32 word1, word2;
135  Word64 word;
136  vector<Word64> words;
137 
138 
139  const DetDigis& detDigis = digis[fedId];
140 
141 // if (detDigis==digis.end()) {
142 // cout << "ESDataFormatterV1_1::DigiToRaw : could not find digi vector in digis map for fedID: "
143 // << fedId << endl ;
144 // return 0;
145 // }
146 
147  for (DetDigis::const_iterator it = detDigis.begin(); it != detDigis.end(); ++it) {
148 
149  const ESDataFrame& dataframe = (*it);
150  const ESDetId& detId = dataframe.id();
151 
152  for (int is=0; is<dataframe.size(); ++is) ts[is] = dataframe.sample(is).adc();
153 
154  // calculate fake kchip and pace id
155  int kchip = -1;
156  int pace = -1;
157  int ix = -1;
158  int iy = -1;
159 
160  ix = detId.six() % 2;
161  iy = detId.siy() % 2;
162  if (ix == 1 && iy == 1)
163  pace = 0;
164  else if (ix == 0 && iy == 1)
165  pace = 1;
166  else if (ix == 1 && iy == 0)
167  pace = 2;
168  else if (ix == 0 && iy == 0)
169  pace = 3;
170 
171  ix = (1 + detId.six()) / 2;
172  iy = (1 + detId.siy()) / 2;
173  if (detId.zside() == 1 && detId.plane() == 1)
174  kchip = ix + (iy-1)*20 - 1;
175  else if (detId.zside() == 1 && detId.plane() == 2)
176  kchip = ix + (iy-1)*20 + 399;
177  else if (detId.zside() == -1 && detId.plane() == 1)
178  kchip = ix + (iy-1)*20 + 799;
179  else if (detId.zside() == -1 && detId.plane() == 2)
180  kchip = ix + (iy-1)*20 + 1199;
181 
182  if (debug_) cout<<"Si : "<<detId.zside()<<" "<<detId.plane()<<" "<<detId.six()<<" "<<detId.siy()<<" "<<detId.strip()<<" ("<<kchip<<","<<pace<<") "<<ts[2]<<" "<<ts[1]<<" "<<ts[0]<<endl;
183 
184  word1 = (ts[1] << sADC1) | (ts[0] << sADC0);
185  word2 = (2 << sHEAD) | (0 << sE1) | (0 << sE0) | ((detId.strip()-1) << sSTRIP) | (pace << sPACE) | (ts[2] << sADC2);
186  word = (Word64(word2) << 32 ) | Word64(word1);
187 
188  map_data[kchip].push_back(word);
189  }
190 
191 
192  map<int, vector<Word64> >::const_iterator kit;
193  for (kit=map_data.begin(); kit!=map_data.end(); ++kit) {
194 
195  if (debug_) cout<<"KCHIP : "<<kit->first<<endl;
196 
197  word1 = (0 << sKFLAG1) | (0 << sKBC) | (0 << sKFLAG2) | (0 << sKEC);
198  word2 = (1 << sKHEAD2) | (0 << sKHEAD1) | (0 << sFIBER) | (kit->first << sKID) | (0 << sKCE) | (0 << sKCRC) | (0 << sKET);
199  word = (Word64(word2) << 32 ) | Word64(word1);
200 
201  if (debug_) cout<<"KCHIP : "<<print(word)<<endl;
202  words.push_back(word);
203 
204  const vector<Word64> & data = kit->second;
205  for (unsigned int id=0; id<data.size(); ++id) {
206  if (debug_) cout<<"Data : "<<print(data[id])<<endl;
207  words.push_back(data[id]);
208  }
209 
210  }
211 
212  int dataSize = (words.size() + 8) * sizeof(Word64);
213 
214  // DCC words
215  vector<Word64> DCCwords;
216  word2 = (0 << sDHEAD) | (1 <<sDH) | (meta_data.run_number << sDRUN);
217  word1 = (dataSize << sDEL);
218  word = (Word64(word2) << 32 ) | Word64(word1);
219  DCCwords.push_back(word);
220  word2 = (0 << sDHEAD) | (2 <<sDH);
221  word1 = 0;
222  word = (Word64(word2) << 32 ) | Word64(word1);
223  DCCwords.push_back(word);
224  word2 = (0 << sDHEAD) | (3 <<sDH) | (1 << sDVMAJOR) | (1 << sDVMINOR);
225  word1 = (meta_data.orbit_number << sDORBIT);
226  word = (Word64(word2) << 32 ) | Word64(word1);
227  DCCwords.push_back(word);
228  word2 = (0 << sDHEAD) | (4 <<sDH);
229  word1 = 0;
230  word = (Word64(word2) << 32 ) | Word64(word1);
231  DCCwords.push_back(word);
232  word2 = (0 << sDHEAD) | (5 <<sDH);
233  word1 = 0;
234  word = (Word64(word2) << 32 ) | Word64(word1);
235  DCCwords.push_back(word);
236  word2 = (0 << sDHEAD) | (6 <<sDH);
237  word1 = 0;
238  word = (Word64(word2) << 32 ) | Word64(word1);
239  DCCwords.push_back(word);
240 
241  // Output (data size in Bytes)
242  fedRawData.resize(dataSize);
243 
244  Word64 * w = reinterpret_cast<Word64* >(fedRawData.data());
245 
246  // header
247  FEDHeader::set( reinterpret_cast<unsigned char*>(w), trgtype_, meta_data.lv1, meta_data.bx, fedId);
248  w++;
249 
250  // ES-DCC
251  for (unsigned int i=0; i<DCCwords.size(); ++i) {
252  if (debug_) cout<<"DCC : "<<print(DCCwords[i])<<endl;
253  *w = DCCwords[i];
254  w++;
255  }
256 
257  // event data
258  for (unsigned int i=0; i<words.size(); ++i) {
259  *w = words[i];
260  w++;
261  }
262 
263  // trailer
264  FEDTrailer::set( reinterpret_cast<unsigned char*>(w), dataSize/sizeof(Word64),
265  evf::compute_crc(fedRawData.data(), dataSize),
266  0, 0);
267  w++;
268 
269 
270 }
271 
static const int bDRUNTYPE
int strip() const
Definition: ESDetId.h:47
static const int bDEL
static const int sDEL
static const int bE1
static const int sKFLAG2
const double w
Definition: UKUtility.cc:23
static const int sDHEAD
static const int bHEAD
static const int bKCE
static const int bADC1
static const int bKET
static const int bKID
static const int sDORBIT
static const int bDORBIT
static const int sFIBER
static const int bDCOMFLAG
static const int sDVMINOR
static const int sDTRGTYPE
const ESDetId & id() const
Definition: ESDataFrame.h:21
static const int sKCE
static const int bKFLAG1
static const int bDERR
static const int sPACE
static const int bDCH
int six() const
Definition: ESDetId.h:43
static const int sKHEAD1
int size() const
Definition: ESDataFrame.h:23
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
static const int sDERR
int siy() const
Definition: ESDetId.h:45
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:60
static const int bKFLAG2
static const int sE0
void resize(size_t newsize)
Definition: FEDRawData.cc:32
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
const ESSample & sample(int i) const
Definition: ESDataFrame.h:26
static const int bADC2
static const int bFIBER
int zside() const
Definition: ESDetId.h:39
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
static const int sSTRIP
static const int sDCH
static const int bSTRIP
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const bool debug_
static const int sADC0
static const int bDTRGTYPE
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
int plane() const
Definition: ESDetId.h:41
ESDataFormatterV1_1(const edm::ParameterSet &ps)
std::string print(const Word64 &word) const
static const int bDHEAD
int adc() const
get the ADC sample (singed 16 bits)
Definition: ESSample.h:18
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:47
static const int sDH
static const int sKFLAG1
static const int bKHEAD2
static const int sDCOMFLAG
static const int sDVMAJOR
static const int bDH
static const int bDVMAJOR
static const int bPACE
void DigiToRaw(int fedId, Digis &digis, FEDRawData &fedRawData, const Meta_Data &meta_data) const override
std::vector< ESDataFrame > DetDigis