186 if (
debug_)
cout <<
"enter in TowerBlockFormatter::EndEvent. First reorder the FE's. " << endl;
188 for (
int idcc=1; idcc <= 54; idcc++) {
196 FEDRawData& fedData = productRawData -> FEDData(FEDid);
197 if (fedData.
size() <= 16)
continue;
199 if (
debug_)
cout <<
"This is FEDid = " << FEDid << endl;
201 unsigned char * pData = fedData.
data();
205 int length = fedData.
size() / 8;
206 int iDAQ_header(-1), iDCC_header(-1), iTCCBlock_header(-1),
207 iSRBlock_header(-1), iTowerBlock_header(-1), iDAQ_trailer(-1);
209 for (
int i=length-1;
i > -1;
i--) {
210 if ( ( (words[
i] >> 60) & 0xF) == 0x5 ) iDAQ_header=
i;
211 if ( ( (words[
i] >> 62) & 0x3) == 0x0 ) iDCC_header=
i;
212 if ( ( (words[
i] >> 61) & 0x7) == 0x3 ) iTCCBlock_header=
i;
213 if ( ( (words[
i] >> 61) & 0x7) == 0x4 ) iSRBlock_header=
i;
214 if ( ( (words[
i] >> 62) & 0x3) == 0x3 ) iTowerBlock_header=
i;
215 if ( ( (words[
i] >> 60) & 0xF) == 0xA ) iDAQ_trailer=
i;
218 if (iTowerBlock_header < 0) iTowerBlock_header = iDAQ_trailer;
219 if (iSRBlock_header < 0) iSRBlock_header = iTowerBlock_header;
220 if (iTCCBlock_header < 0) iTCCBlock_header = iSRBlock_header;
223 cout <<
"iDAQ_header = " << iDAQ_header << endl;
224 cout <<
" iDCC_header = " << iDCC_header << endl;
225 cout <<
" iTCCBlock_header = " << iTCCBlock_header << endl;
226 cout <<
" iSRBlock_header = " << iSRBlock_header << endl;
227 cout <<
" iTowerBlock_header = " << iTowerBlock_header << endl;
228 cout <<
" iDAQ_trailer = " << iDAQ_trailer << endl;
231 std::map<int, int> FrontEnd;
232 std::map<int, std::vector<Word64> > Map_xtal_data;
234 int iTowerBlock_header_keep = iTowerBlock_header;
236 while (iTowerBlock_header < iDAQ_trailer) {
237 int fe = words[iTowerBlock_header] & 0xFF;
238 int nlines = (words[iTowerBlock_header] >> 48) & 0x1FF;
239 if (
debug_)
cout <<
"This is FE number " << fe <<
"needs nlines = " << nlines << endl;
240 FrontEnd[fe] = nlines;
241 std::vector<Word64> xtal_data;
242 for (
int j=0;
j < nlines;
j++) {
243 Word64 ww = words[iTowerBlock_header+
j];
244 xtal_data.push_back(ww);
246 Map_xtal_data[fe] = xtal_data;
247 iTowerBlock_header += nlines;
251 cout <<
"vector of FrontEnd : " << FrontEnd.size() << endl;
252 for (std::map<int, int>::const_iterator it=FrontEnd.begin();
253 it != FrontEnd.end(); it++) {
254 int fe = it ->
first;
256 cout <<
"FE line " << fe <<
" " << l << endl;
260 iTowerBlock_header = iTowerBlock_header_keep;
261 for (std::map<int, int>::const_iterator it=FrontEnd.begin();
262 it != FrontEnd.end(); it++) {
263 int fe = it ->
first;
264 int nlines = it ->
second;
265 if (
debug_)
cout <<
"iTowerBlock_header = " << iTowerBlock_header << endl;
266 vector<Word64> xtal_data = Map_xtal_data[fe];
267 for (
int j=0;
j < nlines;
j++) {
268 words[iTowerBlock_header+
j] = xtal_data[
j];
269 if (
debug_)
cout <<
"update line " << iTowerBlock_header+
j << endl;
272 int jFE = pData[8*(iTowerBlock_header)];
273 cout <<
"Front End on RD : " << jFE << endl;
275 iTowerBlock_header += nlines;
282 if (
debug_)
cout <<
"now reorder the xtals within the FEs" << endl;
284 iTowerBlock_header = iTowerBlock_header_keep;
286 for (std::map<int, int>::const_iterator it=FrontEnd.begin();
287 it != FrontEnd.end(); it++) {
289 int fe = it ->
first;
290 if (fe > 68)
cout <<
"Problem... fe = " << fe <<
" in FEDid = " << FEDid << endl;
291 if (
debug_)
cout <<
" This is for FE = " << fe << endl;
292 int nlines = it ->
second;
293 int timesamples = pData[8*iTowerBlock_header+1] & 0x7F;
294 int n4=timesamples-3;
296 if ( n4 % 4 != 0) n_lines4 ++;
297 if (n_lines4<0) n_lines4=0;
298 int Nxtal_max = (nlines-1)/(1+n_lines4);
301 map< int, map<int, vector<Word64> > > Strip_Map;
303 while (Nxtal < Nxtal_max) {
305 int i_xtal = iTowerBlock_header+1 + Nxtal*(1+n_lines4);
306 int strip = words[i_xtal] & 0x7;
307 int xtal = ( words[i_xtal] >>4) & 0x7;
309 map< int, map<int, vector<Word64> > >::iterator iit = Strip_Map.find(strip);
311 map<int, vector<Word64> > NewMap;
312 map<int, vector<Word64> > Xtal_Map;
314 if (iit == Strip_Map.end()) {
321 std::vector<Word64> xtal_data;
322 for (
int j=0;
j < n_lines4 +1;
j++) {
324 xtal_data.push_back(ww);
326 Xtal_Map[xtal] = xtal_data;
327 Strip_Map[
strip] = Xtal_Map;
335 for (
map<
int,
map<
int, vector<Word64> > >::const_iterator jt = Strip_Map.begin();
336 jt != Strip_Map.end(); jt++) {
338 int strip = jt ->
first;
339 if (
debug_)
cout <<
" this is strip number " << strip << endl;
340 map<int, vector<Word64> > Xtal_Map = jt ->
second;
342 for (
map<
int, vector<Word64> >::const_iterator kt = Xtal_Map.begin();
343 kt != Xtal_Map.end(); kt++) {
344 int xtal = kt ->
first;
345 if (
debug_)
cout <<
" this is xtal number " << xtal << endl;
346 vector<Word64> xtal_data = kt ->
second;
348 int mlines = (
int)xtal_data.size();
349 if (
debug_)
cout <<
" mlines = " << mlines << endl;
350 for (
int j=0;
j < mlines;
j++) {
351 int line = iTowerBlock_header+1+idx+
j;
352 if (line >= iDAQ_trailer)
cout <<
"smth wrong... line " << line <<
" trailer " << iDAQ_trailer << endl;
353 words[
line] = xtal_data[
j] ;
354 if (
debug_)
cout <<
" updated line " << iTowerBlock_header+idx+j << endl;
365 iTowerBlock_header += nlines;
369 if (
debug_)
cout <<
" DONE FOR FED " << FEDid << endl;
371 Map_xtal_data.clear();
size_t size() const
Lenght of the data buffer in bytes.
U second(std::pair< T, U > const &p)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.