00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <errno.h>
00013
00014 #include "parser/MicrorocSCReader.hh"
00015 #include "parser/MicrorocOldLabviewReader.hh"
00016 #include "parser/AcquisitionParser.hh"
00017
00018 #include "event/Event.hh"
00019
00020 #include "geometry/Chamber.hh"
00021 #include "geometry/Board.hh"
00022 #include "geometry/Dif.hh"
00023 #include "geometry/MicrorocChip.hh"
00024 #include "geometry/Detector.hh"
00025
00026 #include "tools/Toolbox.hh"
00027 #include "tools/SteerDesc.hh"
00028 #include "tools/Log.hh"
00029 #include "tools/MicroException.hh"
00030
00031 #include <iostream>
00032 #include <iomanip>
00033
00034 using namespace std;
00035
00036
00037 MicrorocOldLabviewReader::MicrorocOldLabviewReader(Run& aRun, FILE *aFile, ui32 lastEventId) : MicrorocReader(aRun, aFile, lastEventId), nbChipPerLine(0), analogDataActivate(false), hexTemperatureAsu1(0), hexTemperatureAsu2(0), hexTemperatureDif(0)
00038 {
00039 FILE_LOG(logDEBUG1) << "--MicrorocOldLabviewReader constructor()"<< endl;
00040 FILE_LOG(logDEBUG) << "cwMixrorocLabview ReaderDifReader Constructeur crc adr[" << crc << "]" << endl;
00041
00042 for ( ui16 line = 0 ; line < NBLINE ; line++)
00043 {
00044 analogDataActivatedLine[line] = false;
00045 }
00046
00047 reset();
00048
00049 }
00050
00051
00052 MicrorocOldLabviewReader::~MicrorocOldLabviewReader()
00053 {
00054 FILE_LOG(logDEBUG1)<< "----MicrorocOldLabviewReader destructor"<< endl;
00055 }
00056
00057
00058
00059 int MicrorocOldLabviewReader::getScData() {
00060 unsigned int data;
00061 display(+1);
00062 FILE_LOG(logDEBUG) << " Slow Control data header B1 found" << endl;
00063
00064
00065 int scHRNumber = 24;
00066
00067 difId=1;
00068 ui16 dataFormat = run.getDataFormat();
00069 if ( dataFormat == 11 || dataFormat == 12 )
00070 {
00071
00072 nbChipPerLine = 12;
00073 bool findA1 = false;
00074 difId = getData(1);
00075 display(+1);
00076 FILE_LOG(logDEBUG) << "--- difId[" << difId << "] config ---" << endl;
00077
00078 Dif& dif = run.getDetector().getDifById(difId);
00079 FILE_LOG(logINFO) << "-------- dif Id[0x" << hex << dif.getId() << "]" << endl;
00080 dif.setDifFirmware(getData(2));
00081 display(+2);
00082 FILE_LOG(logINFO) << "-------- difFirmware[0x" << hex << dif.getDifFirmware() << "]" << endl;
00083
00084 dif.setDifConfig (getData(1));
00085 display(+1);
00086 FILE_LOG(logINFO) << "-------- difConfig[0x" << hex << dif.getDifConfig() << "]" << endl;
00087
00088 dif.setAsicType(getData(1));
00089 display(+1);
00090 FILE_LOG(logINFO) << "-------- asicType[0x" << dif.getAsicType() << "]" << endl;
00091 if ( dif.getAsicType() == 4 )
00092 {
00093 FILE_LOG(logINFO) << "------------------ [ Microroc ]" << endl;
00094 }
00095 dif.setConfigured(true);
00096
00097 if ( dataFormat == 12)
00098 {
00099
00100 int foo = getData(1);
00101 if ( foo != 0x0 )
00102 {
00103 analogDataActivate = true;
00104 ui16 bitshift = 0x1;
00105 for ( ui16 line = 0 ; line < NBLINE; line++)
00106 {
00107 analogDataActivatedLine[line] = foo & bitshift;
00108 bitshift = bitshift * 2;
00109 FILE_LOG(logDEBUG) << "line [" << line << "] analog activation["<< analogDataActivatedLine[line] <<"]" << endl;
00110 }
00111 FILE_LOG(logINFO) << "-------- analog data enable. Mask to enable line [0x" <<hex << foo <<"]" << endl;
00112 }
00113 else
00114 {
00115 analogDataActivate = false;
00116 FILE_LOG(logINFO) << "-------- analogData disable" << endl;
00117 }
00118 }
00119
00120 dif.setAsu1Id(getData(1));
00121 FILE_LOG(logINFO) << "-------- ASU 1 Id[0x" << hex << dif.getAsu1Id() << "]" << endl;
00122 display(+1);
00123
00124
00125
00126
00127
00128
00129 ui16 boardColToCheck = 0;
00130 if ( dif.getAsu1Id() != 0)
00131 {
00132 if ( dif.getBoardByCol(boardColToCheck).getId() != dif.getAsu1Id() )
00133 {
00134 FILE_LOG(logINFO) << "Error data say ASU id = "<< dif.getAsu1Id() << " for ASU close to DIF ( left side ) while XML say ASU id = " << dif.getBoardByCol(boardColToCheck).getId() << endl;
00135 FILE_LOG(logINFO) << "Please consider modifying XML file" << endl;
00136 exit(-1);
00137 }
00138 boardColToCheck++;
00139 }
00140
00141
00142 dif.setAsu2Id (getData(1));
00143 FILE_LOG(logINFO) << "-------- ASU 2 Id[0x" <<hex << dif.getAsu2Id() << "]" << endl;
00144 display(+1);
00145 if ( dif.getAsu2Id() != 0)
00146 {
00147 if ( dif.getBoardByCol(boardColToCheck).getId() != dif.getAsu2Id() )
00148 {
00149 FILE_LOG(logINFO) << "Error data say ASU id = "<< dif.getAsu2Id() << " for ASU far away to DIF ( right side ) while XML say ASU id = " << dif.getBoardByCol(boardColToCheck).getId() << endl;
00150 FILE_LOG(logINFO) << "Please consider modifying XML file" << endl;
00151 exit(-1);
00152 }
00153 }
00154 scHRNumber = getData(1);
00155 FILE_LOG(logINFO) << "-------- Nombre de chip en Slow control[0x" << hex << scHRNumber << "]" << endl;
00156
00157
00158
00159 dif.setChipByPassed(true);
00160 for ( int nbChip = 0 ; (nbChip < scHRNumber) & findA1 == false ; nbChip++)
00161 {
00162 const unsigned char *buf = initGetBits(74, false);
00163 vector<int> sc;
00164 for ( ui16 i = 0; i < 74 ; i++)
00165 {
00166 int foo = getBits(8);
00167 sc.push_back(foo);
00168 }
00169 finishGetBits();
00170 MicrorocSCReader scReader(run,sc,difId);
00171 scReader.parseSC(difId);
00172
00173
00174
00175 }
00176 if ( ! findA1) {
00177 unsigned char *buf = initGetBits(1, false);
00178 if ( !buf)
00179 {
00180 FILE_LOG(logERROR) << " malloc error while getting SC buffer" << endl;
00181 exit ( -1);
00182 }
00183
00184 int foo = getBits(8);
00185 finishGetBits();
00186
00187 FILE_LOG(logDEBUG) << "Header[" <<hex << foo <<"]" << endl;
00188 if ( foo != 0xa1)
00189 {
00190 FILE_LOG(logERROR) << " Header A1 not found" << endl;
00191 exit (-1);
00192 }
00193 FILE_LOG(logDEBUG1) << "Header A1 found" << endl;
00194
00195 }
00196
00197 }
00198 if ( dataFormat == 13 )
00199 {
00200
00201 FILE_LOG(logDEBUG) << "SC START" << endl;
00202 difId = getData(1);
00203 display(+1);
00204 FILE_LOG(logDEBUG) << "--- difId[" << difId << "] ---" << endl;
00205 ui16 asicHeader = getData(1);
00206 display(+1);
00207 FILE_LOG(logDEBUG) << "--- asic header[" << asicHeader << "] ---" << endl;
00208 ui16 cyrilbug = getData(2);
00209 ui16 scsize = getData(1);
00210 display(+1);
00211 FILE_LOG(logDEBUG) << "--- sc size 74 or 109[" << dec << scsize << "] ---" << endl;
00212 scsize=74;
00213 const unsigned char *buf = initGetBits(74, false);
00214 vector<int> sc;
00215 for ( ui16 i = 0 ; i<scsize ; i++ )
00216 {
00217 ui16 scAsic = getBits(8) ;
00218 sc.push_back(scAsic);
00219 }
00220 finishGetBits();
00221 MicrorocSCReader scReader(run,sc,difId);
00222 scReader.parseSC(difId);
00223
00224
00225 ui16 foo2 = 0xff;
00226 while ( foo2 != 0xb0 && foo2 !=0 && fileError != EOF)
00227 {
00228 ui16 foo = getData(1);
00229 while ( foo != 0xa1 )
00230 {
00231 foo = getData(1);
00232 FILE_LOG(logDEBUG) << "-- Wait foo 0xa1[" << hex << foo << "]" << endl;
00233 }
00234 foo2 = getData(1);
00235 FILE_LOG(logDEBUG) << "-- Wait foo 0xb0[" << hex << foo << "]" << endl;
00236
00237 }
00238 FILE_LOG(logDEBUG) << "SC END" << endl;
00239 }
00240
00241 return(1);
00242 }
00243
00244
00245
00246 int MicrorocOldLabviewReader::getAnalogData(Event& event) {
00247 FILE_LOG(logDEBUG) << " global header C0 found" << endl;
00248 this->setComputeCrcFlag(true);
00249 crc->compute(0xC0);
00250
00251 ui16 nbchannel = 64;
00252 ui16 nbLine = 4;
00253 ui16 nbBitsPerLine = this->nbChipPerLine * nbchannel * 16;
00254 Dif& dif = run.getDetector().getDifById(difId);
00255 ui16 nbChipByBoard = dif.getBoards().begin()->second->getNbColumns();
00256 ui16 nbBoard = dif.getBoards().size();
00257 FILE_LOG(logDEBUG) << "nbBoard[" << nbBoard << "]" <<endl;
00258 FILE_LOG(logDEBUG) << "nbChipByBoard[" << nbChipByBoard << "]" <<endl;
00259
00260 this->analogData.clear();
00261 bool firstLine=true;
00262 for ( ui16 line = 0; line < nbLine ; line++)
00263 {
00264 if ( analogDataActivatedLine[line] == true )
00265 {
00266 FILE_LOG(logDEBUG) << " New Line[" << line << "]" << endl;
00267 if ( !firstLine )
00268 {
00269 int foo = getData(1);
00270 FILE_LOG(logDEBUG) << " foo C0["<< hex << foo << "]" << endl;
00271 if ( foo != 0xC0 )
00272 {
00273 FILE_LOG(logERROR) << "C0 header not found[0x" << hex << foo << "]" << endl;
00274 exit(-1);
00275 }
00276 }
00277 if( firstLine == true) { firstLine = false; }
00278
00279 for ( i32 col = nbBoard * nbChipByBoard -1 ; col >= 0; col--)
00280 {
00281 FILE_LOG(logDEBUG)<< hex << "col index[0x" << col << "]board col["<< col/nbChipByBoard << "] line["<< line <<"], col["<< col%nbChipByBoard <<"] "<<endl;
00282 Chip& chip = dif.getChipByRowCol(col/nbChipByBoard, line,col%nbChipByBoard);
00283 FILE_LOG(logDEBUG) << "------------chipId["<< chip.getId() << "] chip bypassed[" << chip.getBypassed() << "]" <<endl;
00284 if( chip.getBypassed() == false )
00285 {
00286 map<ui16,ui16> channelsValues;
00287 for ( ui16 channel = 0 ; channel < nbchannel ;channel++)
00288 {
00289 int foo = getData(2);
00290
00291 channelsValues[channel] = foo;
00292 FILE_LOG(logDEBUG) << "chipId["<< chip.getId() <<"] analogData line["<< line <<"], col number["<< col << "] , channel[" << channel << "= " << hex <<foo << dec << endl;
00293 }
00294 this->analogData[chip.getId()] = channelsValues;
00295 }
00296 }
00297
00298
00299 int foo = getData(1);
00300 if ( foo != 0xD0 )
00301 {
00302 FILE_LOG(logERROR) << "D0 header not found[0x" << hex << foo << "]" << endl;
00303 exit(-1);
00304 }
00305 }
00306 else
00307 {
00308 FILE_LOG(logDEBUG) << " line[ " << line +1<< "] is disable ( starting number at 1 )" << endl;
00309 }
00310 }
00311
00312
00313 this->setComputeCrcFlag(false);
00314 unsigned short CRC_check = getData(2);
00315 if ( CRC_check != crc->getCrc() )
00316 {
00317 FILE_LOG(logERROR) << endl << " CRC Error event Id: " << lastEventId << endl;
00318 FILE_LOG(logERROR) << hex << " Compute CRC[" << crc->getCrc() << "]" << endl;
00319 FILE_LOG(logERROR) << hex << " Received CRC[" << CRC_check << "]" << endl;
00320 event.setCrcIsCorrect(false);
00321 }
00322 else
00323 {
00324 event.setCrcIsCorrect(true);
00325 }
00326
00327 return 0;
00328 }
00329
00330
00331 int MicrorocOldLabviewReader::getAcqData(Event& event, bool temperatureFill) {
00332
00333 ui16 dataFormat = run.getDataFormat();
00334 if ( dataFormat == 11 || dataFormat == 12 )
00335 {
00336 ui32 nbanalogHit = 0;
00337 unsigned int nbHits = 0;
00338
00339 display(+1);
00340 FILE_LOG(logDEBUG) << " global header B0 found" << endl;
00341
00342
00343 this->setComputeCrcFlag(true);
00344
00345 FILE_LOG(logDEBUG) << "crc->compute(0xB0)[ "<< crc <<"]" << endl;
00346
00347 crc->compute(0xB0);
00348
00349
00350
00351
00352
00353 bcId_Abs = 0;
00354 bcId_Dif = 0;
00355
00356 difId = getData(1);
00357
00358 difTriggerCounter = getData(4);
00359 usbBusyTrigger = getData(4);
00360 globalTriggerCounter = getData(4);
00361 ui64 bcIdHigh = getData(2);
00362 ui64 bcIdLow = getData(4);
00363 bcId_Abs = (bcIdHigh << 32) + bcIdLow;
00364 FILE_LOG(logDEBUG1) << "bcId_Abs[" <<bcId_Abs << endl;
00365 bcId_Dif = getData(3);
00366
00367 bcId_AbsOrg = getbcIdAbsOrg(difId, bcId_Abs);
00368
00369 ui16 lineInfo = getData(1);
00370 ui16 nbLine = (lineInfo & 0xF0 ) >> 4;
00371 ui16 usedLine = lineInfo & 0x0F;
00372
00373
00374 display();
00375
00376
00377 i64 bcTime = ((bcId_Abs - bcId_AbsOrg) * bcPeriod) / 1000;
00378
00379 i64 readTime = globalTime + bcTime;
00380
00381 FILE_LOG(logDEBUG) << " START EVENT ------------- time " << readTime << " ms" << endl;
00382 FILE_LOG(logDEBUG) << " bc time " << bcTime << " ms" << endl;
00383 FILE_LOG(logDEBUG) << " DIF Id 0x" << hex << (int)difId << dec << endl;
00384 FILE_LOG(logDEBUG) << " DIF trigger counter " << difTriggerCounter << endl;
00385 FILE_LOG(logDEBUG) << " USB Busy trigger counter " << usbBusyTrigger << endl;
00386 FILE_LOG(logDEBUG) << " total trigger counter " << globalTriggerCounter << endl;
00387 FILE_LOG(logDEBUG) << " absolute bcId " << bcId_Abs - bcId_AbsOrg << endl;
00388 FILE_LOG(logDEBUG) << " nb line " << dec <<nbLine << endl;
00389 FILE_LOG(logDEBUG) << " used line " << hex << usedLine << dec <<endl;
00390 event.setDifTriggerCounter(difTriggerCounter);
00391 event.setGlobalTriggerCounter(globalTriggerCounter);
00392
00393
00394 Detector &detector = run.getDetector();
00395
00396 if ( analogDataActivate )
00397 {
00398 for ( map<ui16,map<ui16,ui16> >::iterator iterAnal = analogData.begin(); iterAnal!= analogData.end(); iterAnal++)
00399 {
00400 map<ui16,ui16>& byChip = iterAnal->second;
00401 ui16 chipId = iterAnal->first;
00402
00403 for ( std::map<ui16,ui16>::iterator iterChip = byChip.begin(); iterChip != byChip.end();iterChip++)
00404 {
00405 ui16 analogValue = iterChip->second;
00406 ui16 channelId = iterChip->first;
00407
00408 nbHits += newHit(event, detector, 0, analogValue,channelId , chipId, difId);
00409 nbanalogHit++;
00410 }
00411 }
00412 }
00413
00414
00415 bool difFound = false;
00416 { const ChamberMap_t &chambers = detector.getChambers();
00417 for (ChamberMap_t::const_iterator it = chambers.begin(); it != chambers.end(); ++it) {
00418 try {
00419 Chamber& chamber = *(it->second);
00420 const BoardMap_t& boards = chamber.getBoardsByDifId(difId);
00421 }
00422 catch (...) {
00423
00424 continue;
00425 }
00426
00427
00428 difFound = true;
00429 break;
00430 }
00431 if (!difFound) {
00432 FILE_LOG(logERROR) << " No dif found with Id 0x" << hex << difId << dec << endl;
00433 }
00434 }
00435
00436 for (bool finish = false; !finish; ) {
00437 int delimiter = 0;
00438
00439 display();
00440 for (; delimiter != 0xA0 && delimiter != 0xB4; ) {
00441
00442 delimiter = getData(1);
00443 if (fileError == EOF) {
00444 delimiter = 0;
00445 break;
00446 }
00447 if (delimiter == 0xA3)
00448 FILE_LOG(logERROR) << " frame trailer A3 found -- should not" << endl;
00449 }
00450 if (delimiter == 0x00) {
00451 FILE_LOG(logERROR) << " end of file -- should not" << endl;
00452 break;
00453 }
00454 if (delimiter == 0xA0) {
00455 FILE_LOG(logDEBUG) << " frame trailer A0 found" << endl;
00456 this->setComputeCrcFlag(false);
00457 unsigned short CRC_check = getData(2);
00458 FILE_LOG(logDEBUG) << hex << " Compute CRC[" << crc->getCrc() << "]" << endl;
00459 FILE_LOG(logDEBUG) << hex << " Received CRC[" << CRC_check << "]" << endl;
00460 if ( CRC_check != crc->getCrc() )
00461 {
00462 FILE_LOG(logERROR) << endl << " CRC Error for event id " << lastEventId << endl;
00463 event.setCrcIsCorrect(false);
00464
00465 }
00466 else
00467 {
00468 event.setCrcIsCorrect(true);
00469 }
00470
00471
00472 display(-1);
00473 FILE_LOG(logDEBUG) << " global trailer A0 found" << endl;
00474 break;
00475 }
00476 display(+1);
00477 FILE_LOG(logDEBUG) << " frame header B4 found" << endl;
00478
00479
00480 int chipId = -1;
00481 ui16 orderInChipMemory = 0;
00482 for (; ; )
00483 {
00484 chipId = getData(1);
00485 FILE_LOG(logDEBUG) << "8 bits read[" << chipId << "] [0x" << hex << chipId << "]" << dec << endl;
00486
00487 if (fileError == EOF) {
00488 finish = true;
00489 FILE_LOG(logINFO) << " end of file found -- should not" << endl;
00490 break;
00491 }
00492 if (chipId == 0x00) {
00493
00494 continue;
00495 }
00496 else if (chipId == 0xA3) {
00497 display(-1);
00498 FILE_LOG(logDEBUG) << " frame trailer A3 found" << endl;
00499 break;
00500 }
00501 else if (chipId == 0xA0) {
00502 finish = true;
00503 display(-1);
00504 FILE_LOG(logERROR) << " global trailer A0 found -- should not" << endl;
00505 int CRC_check = getData(1);
00506 break;
00507 }
00508 else if (chipId == 0xC3) {
00509 display(-1);
00510 FILE_LOG(logERROR) << " frame trailer C3 found - error occured during data transfer" << endl;
00511 break;
00512 }
00513
00514
00515 bcId_Hit = grayToBinary(getData(3));
00516
00517 eventTime = readTime + (((bcId_Dif - bcId_Hit) * bcPeriod) / 1000);
00518
00519 orderInChipMemory++;
00520
00521 if (difFound)
00522 {
00523 FILE_LOG(logDEBUG) << " chip Id 0x" << hex << (int)chipId << dec << endl;
00524 FILE_LOG(logDEBUG) << " bcId Microroc " << hex << (int)bcId_Hit << endl;
00525 FILE_LOG(logDEBUG) << " event time " << eventTime << endl;
00526
00527 for (int chNum = 48; chNum >= 0; chNum -= 16)
00528 {
00529 unsigned int data4 = getData(4);
00530 for (int index = 0; index < 16; index++)
00531 {
00532
00533 int trigger = (data4 >> ((15 - index) * 2)) & 0x03;
00534
00535 if (trigger)
00536 {
00537
00538 if ( analogDataActivate && orderInChipMemory == 1 )
00539 {
00540
00541 i16 analogValue = analogData[chipId][index + chNum];
00542 nbHits += newHit(event, detector, trigger, analogValue, index + chNum, chipId, difId,orderInChipMemory);
00543 }
00544 else
00545 {
00546 nbHits += newHit(event, detector, trigger, 0, index + chNum, chipId, difId,orderInChipMemory);
00547 }
00548
00549
00550 FILE_LOG(logDEBUG) << "digital chipId[" << chipId << "] channelNum["<< index+chNum <<"]= " << trigger << endl;
00551 }
00552 }
00553 }
00554 }
00555 display();
00556 }
00557
00558 }
00559 display(-1);
00560
00561
00562
00563
00564
00565 event.setTimeStamp(globalTime + ((bcId_AbsOrg /1000000 * bcPeriod) ) );
00566 event.setId(++lastEventId);
00567 FILE_LOG(logDEBUG) << " STORE EVENT " << lastEventId << ", " << nbHits << " hits" << endl;
00568
00569
00570
00571
00572
00573
00574
00575 if (SkippedBcId) {
00576 FILE_LOG(logWARNING) << " skipped " << SkippedBcId << " data because of bad bcId" << endl;
00577 SkippedBcId = 0;
00578 }
00579
00580 return(nbHits);
00581 }
00582 else if ( dataFormat == 13)
00583 {
00584
00585
00586 ui32 nbanalogHit = 0;
00587 unsigned int nbHits = 0;
00588
00589 display(+1);
00590
00591
00592 this->setComputeCrcFlag(true);
00593
00594
00595 if ( temperatureFill )
00596 {
00597 FILE_LOG(logDEBUG) << " global header BB found" << endl;
00598 FILE_LOG(logDEBUG) << "crc->compute(0xBB)[ "<< crc <<"]" << endl;
00599 crc->compute(0xBB);
00600 }
00601 else
00602 {
00603 FILE_LOG(logDEBUG) << " global header B0 found" << endl;
00604 FILE_LOG(logDEBUG) << "crc->compute(0xB0)[ "<< crc <<"]" << endl;
00605 crc->compute(0xB0);
00606 }
00607
00608
00609
00610
00611
00612 bcId_Abs = 0;
00613 bcId_Dif = 0;
00614
00615 difId = getData(1);
00616
00617 difTriggerCounter = getData(4);
00618 informationCounter = getData(4);
00619 globalTriggerCounter = getData(4);
00620
00621 ui64 bcIdHigh = getData(2);
00622 ui64 bcIdLow = getData(4);
00623 bcId_Abs = (bcIdHigh << 32) + bcIdLow;
00624
00625
00626 bcId_Dif = getData(3);
00627
00628 bcId_AbsOrg = getbcIdAbsOrg(difId, bcId_Abs);
00629 display();
00630
00631 ui16 lineInfo = getData(1);
00632 FILE_LOG(logDEBUG) << " lineInfo[0x" <<hex << lineInfo << "]" << endl;
00633 ui16 nbLine = (lineInfo & 0xF0 ) >> 4;
00634 FILE_LOG(logDEBUG) << " nbline[0x" <<hex << nbLine << "]" << endl;
00635 ui16 usedLine = lineInfo & 0x0F;
00636 FILE_LOG(logDEBUG) << " usedLine[0x" <<hex << usedLine << "]" << endl;
00637 display();
00638
00639
00640 if ( temperatureFill )
00641 {
00642 hexTemperatureAsu1 = getData(4);
00643 hexTemperatureAsu2 = getData(4);
00644 hexTemperatureDif = getData(1) & 0xFF;
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657 i16 hex16tempAsu1 = hexTemperatureAsu1 & 0xFFFF;
00658 float tempAsu1 = (float) ((hex16tempAsu1 / 16 ) / 8 );
00659
00660 i16 hex16tempAsu2 = hexTemperatureAsu2 & 0xFFFF;
00661 float tempAsu2 = (float) ((hex16tempAsu2 / 16 ) / 8 );
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685 float Vlsb = 20.0;
00686 float V_adc = hexTemperatureDif * Vlsb;
00687 float V_lm20 = ( (6450. - V_adc) / 3.3 ) ;
00688 float tempDif = (V_lm20 - 1860.5) / (-11.77);
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701 event.setTemperature(difId, tempAsu1, tempAsu2 , tempDif);
00702
00703 }
00704
00705
00706 i64 bcTime = ((bcId_Abs - bcId_AbsOrg) * bcPeriod) / 1000;
00707
00708 i64 readTime = globalTime + bcTime;
00709
00710 FILE_LOG(logDEBUG) << " START EVENT ------------- time " << readTime << " ms" << endl;
00711 FILE_LOG(logDEBUG) << " bc time " << bcTime << " ms" << endl;
00712 FILE_LOG(logDEBUG) << " DIF Id 0x" << hex << (int)difId << dec << endl;
00713 FILE_LOG(logDEBUG) << " DIF trigger counter " << difTriggerCounter << endl;
00714 FILE_LOG(logDEBUG) << " Information counter " << informationCounter << endl;
00715 FILE_LOG(logDEBUG) << " total trigger counter " << globalTriggerCounter << endl;
00716 FILE_LOG(logDEBUG) << " absolute bcId " << bcId_Abs - bcId_AbsOrg << endl;
00717 FILE_LOG(logDEBUG) << " nb line " << dec <<nbLine << endl;
00718 FILE_LOG(logDEBUG) << " used line " << hex << usedLine << dec <<endl;
00719 event.setDifTriggerCounter(difTriggerCounter);
00720 event.setGlobalTriggerCounter(globalTriggerCounter);
00721
00722
00723 Detector &detector = run.getDetector();
00724
00725
00726
00727 bool difFound = false;
00728 { const ChamberMap_t &chambers = detector.getChambers();
00729 for (ChamberMap_t::const_iterator it = chambers.begin(); it != chambers.end(); ++it) {
00730 try {
00731 Chamber& chamber = *(it->second);
00732 const BoardMap_t& boards = chamber.getBoardsByDifId(difId);
00733 }
00734 catch (...) {
00735
00736 continue;
00737 }
00738
00739
00740 difFound = true;
00741 break;
00742 }
00743 if (detector.getMonitoringId() == difId)
00744 {
00745 difFound = true;
00746 }
00747 if (!difFound) {
00748 FILE_LOG(logERROR) << " No dif found with Id 0x" << hex << difId << ", " << dec << difId << " " <<endl;
00749 event.setValidFlag(BAD_DIF_ID,false);
00750
00751 }
00752 }
00753
00754 for (bool finish = false; !finish; ) {
00755 int delimiter = 0;
00756
00757 display();
00758 for (; delimiter != 0xA0 && delimiter != 0xB4 && delimiter != 0xC4; ) {
00759
00760 delimiter = getData(1);
00761 if (fileError == EOF) {
00762 delimiter = 0;
00763 break;
00764 }
00765 if (delimiter == 0xA3)
00766 {
00767 FILE_LOG(logERROR) << " frame trailer A3 found -- should not" << endl;
00768 event.setValidFlag(FRAME_HEADER_ERROR,false);
00769 }
00770 }
00771 if (delimiter == 0x00) {
00772 FILE_LOG(logERROR) << " end of file -- should not" << endl;
00773 event.setValidFlag(END_OF_FILE_ERROR,false);
00774 break;
00775 }
00776 if (delimiter == 0xA0)
00777 {
00778 FILE_LOG(logDEBUG) << " frame trailer A0 found" << endl;
00779 this->setComputeCrcFlag(false);
00780 unsigned short CRC_check = getData(2);
00781 FILE_LOG(logDEBUG) << hex << " Compute CRC[" << crc->getCrc() << "]" << endl;
00782 FILE_LOG(logDEBUG) << hex << " Received CRC[" << CRC_check << "]" << endl;
00783 if ( CRC_check != crc->getCrc() )
00784 {
00785 FILE_LOG(logERROR) << " CRC Error for event id " << lastEventId
00786 << " Compute CRC[" << crc->getCrc()
00787 << "] Received CRC[" << CRC_check << "]" << endl ;
00788 event.setCrcIsCorrect(false);
00789 event.setValidFlag(CRC_ERROR,false);
00790 }
00791 display(-1);
00792 FILE_LOG(logDEBUG) << " global trailer A0 found" << endl;
00793 break;
00794 }
00795 if (delimiter == 0xC4)
00796 {
00797
00798 Dif& dif = run.getDetector().getDifById(difId);
00799 analogDataActivate = true;
00800 ui16 lineNum = 1;
00801 ui16 nbChipByBoard = dif.getBoards().begin()->second->getNbColumns();
00802 ui16 nbBoard = dif.getBoards().size();
00803 FILE_LOG(logDEBUG) << "nbBoard[" << nbBoard << "]" <<endl;
00804 FILE_LOG(logDEBUG) << "nbChipByBoard[" << nbChipByBoard << "]" <<endl;
00805
00806 for ( ui16 iLine = 0 ; iLine < nbLine ; iLine++)
00807 {
00808 if ( usedLine & lineNum )
00809 {
00810 ui16 nbChips = getData(1);
00811 FILE_LOG(logDEBUG) << endl << " Line " << lineNum << " nb Chip[" << dec << nbChips << "]" << endl;
00812
00813 for ( i32 col = nbBoard * nbChipByBoard -1 ; col >= 0; col--)
00814 {
00815 ui16 board = col/nbChipByBoard;
00816 FILE_LOG(logDEBUG)<< dec << "board [" << board << "] line[" << lineNum-1 << "] col[" << col << "]" << endl;
00817 Chip& chip = dif.getChipByRowCol(board, lineNum-1,col % 6);
00818 if( chip.getBypassed() == false )
00819 {
00820
00821 FILE_LOG(logDEBUG)<< dec << "chip Id[" << chip.getId() << "]" << endl;
00822 map<ui16,ui16> channelsValues;
00823 for ( ui16 iChannel = 0 ; iChannel < 64 ; iChannel++)
00824 {
00825 ui16 foo = getData(2);
00826 channelsValues[iChannel] = foo;
00827 FILE_LOG(logDEBUG) << "difId["<< dif.getId() << "] ,chipId["<< chip.getId() <<"] analogData line["<< line <<
00828 "], col number["<< col << "] , channel[" << iChannel << "= " << hex <<foo << "]" << dec << endl;
00829 }
00830 this->analogData[chip.getId()] = channelsValues;
00831 }
00832 }
00833 }
00834 lineNum++;
00835 }
00836
00837 }
00838 if ( forceAnalog )
00839 {
00840 for ( map<ui16,map<ui16,ui16> >::iterator iterAnal = analogData.begin(); iterAnal!= analogData.end(); iterAnal++)
00841 {
00842 map<ui16,ui16>& byChip = iterAnal->second;
00843 ui16 chipId = iterAnal->first;
00844
00845 for ( std::map<ui16,ui16>::iterator iterChip = byChip.begin(); iterChip != byChip.end();iterChip++)
00846 {
00847 ui16 analogValue = iterChip->second;
00848 ui16 channelId = iterChip->first;
00849
00850 {
00851 nbHits += newHit(event, detector, 0, analogValue,channelId , chipId, difId);
00852 nbanalogHit++;
00853 }
00854 }
00855 }
00856 }
00857
00858 if (delimiter == 0xB4)
00859 {
00860 display(+1);
00861 FILE_LOG(logDEBUG) << " frame header B4 found" << endl;
00862
00863
00864
00865 int chipId = -1;
00866 ui16 orderInChipMemory = 0;
00867 for (; ; )
00868 {
00869 chipId = getData(1);
00870
00871
00872
00873 if (fileError == EOF) {
00874 finish = true;
00875 FILE_LOG(logINFO) << " end of file found -- should not" << endl;
00876 break;
00877 }
00878 if (chipId == 0x00) {
00879
00880 continue;
00881 }
00882 else if (chipId == 0xA3) {
00883 display(-1);
00884 FILE_LOG(logDEBUG) << " frame trailer A3 found" << endl;
00885 break;
00886 }
00887 else if (chipId == 0xA0) {
00888 finish = true;
00889 display(-1);
00890 break;
00891 }
00892 else if (chipId == 0xC3) {
00893 display(-1);
00894 FILE_LOG(logERROR) << " frame trailer C3 found - error occured during data transfer" << endl;
00895 event.setValidFlag(TRAILER_C3_FOUND,false);
00896 break;
00897 }
00898
00899 bool supressionDeDonnee = 0;
00900 if ( supressionDeDonnee == 1 )
00901 {
00902
00903 ui16 supressValue = (chipId & 0xc0) >> 6;
00904 FILE_LOG(logINFO) << "supressValue[" << hex << supressValue << "]" << endl;
00905
00906
00907 chipId = chipId & 0x3F;
00908 FILE_LOG(logINFO) << "chip Id apres avoir enleve supressValue[" << hex <<chipId << "]" << endl;
00909
00910
00911 bcId_Hit = grayToBinary(getData(3));
00912 FILE_LOG(logDEBUG) << dec << "bcId_Hit[" << bcId_Hit << "]" << endl;
00913
00914 ui16 dataSup = getData(1);
00915 display(1);
00916 FILE_LOG(logINFO) << "wait 1 for 0xA3 -> [" << hex << dataSup << "]" << endl;
00917 while ( dataSup != 0xa3 )
00918 {
00919 ui16 voie = ( dataSup & 0xfc ) >> 6;
00920 ui16 seuil = dataSup & 0x3;
00921 FILE_LOG(logINFO) << "voie[" << hex << voie << "], seuil[" << seuil << "]" << endl;
00922 dataSup = getData(1);
00923 display(1);
00924 FILE_LOG(logINFO) << " wait 2 for 0xA3 -> [" << hex << dataSup << "]" << endl;
00925 }
00926 }
00927
00928
00929 bcId_Hit = grayToBinary(getData(3));
00930 FILE_LOG(logDEBUG) << dec << "bcId_Hit[" << bcId_Hit << "]" << endl;
00931
00932 eventTime = readTime + (((bcId_Dif - bcId_Hit) * bcPeriod) / 1000);
00933
00934 orderInChipMemory++;
00935
00936 if (difFound)
00937 {
00938
00939 for (int chNum = 48; chNum >= 0; chNum -= 16)
00940 {
00941 unsigned int data4 = getData(4);
00942 if ( data4 == 0xffffffff )
00943 {
00944 event.setValidFlag(ONLY_FFFF);
00945 FILE_LOG(logDEBUG) << "event.setValidFlag(ONLY_FFFF)" << endl;
00946 }
00947 else if ( data4 == 0xaaaaaaaa )
00948 {
00949 event.setValidFlag(ONLY_AAAA);
00950 FILE_LOG(logDEBUG) << "event.setValidFlag(ONLY_AAAA)" << endl;
00951 }
00952 else if ( data4 == 0x55555555 )
00953 {
00954 event.setValidFlag(ONLY_5555);
00955 FILE_LOG(logDEBUG) << "event.setValidFlag(ONLY_5555)" << endl;
00956 }
00957 for (int index = 0; index < 16; index++)
00958 {
00959
00960 int trigger = (data4 >> ((15 - index) * 2)) & 0x03;
00961 FILE_LOG(logDEBUG) << "trigger[" << trigger << "]" << endl;
00962
00963 if (trigger)
00964 {
00965 FILE_LOG(logDEBUG) << "difId[" << difId << "]" << endl;
00966
00967 {
00968 if ( analogDataActivate && orderInChipMemory == 1 )
00969 {
00970 i16 analogValue = analogData[chipId][index + chNum];
00971 nbHits += newHit(event, detector, trigger, analogValue, index + chNum, chipId, difId,orderInChipMemory);
00972 }
00973 else
00974 {
00975 nbHits += newHit(event, detector, trigger, 0, index + chNum, chipId, difId,orderInChipMemory);
00976 }
00977 }
00978 }
00979 }
00980 }
00981 }
00982 display();
00983 }
00984 }
00985 }
00986 display(-1);
00987
00988
00989
00990 event.setTimeStamp(globalTime + ((bcId_AbsOrg /1000000 * bcPeriod) ) );
00991 event.setId(++lastEventId);
00992 FILE_LOG(logDEBUG) << "Dif[" << dec << difId << "] Number of created hit for event EVENT " << lastEventId << ", " << nbHits << " total hits, within " << nbanalogHit << " analogic hits" << endl;
00993
00994
00995
00996 if (SkippedBcId) {
00997 FILE_LOG(logWARNING) << " skipped " << SkippedBcId << " data because of bad bcId" << endl;
00998 SkippedBcId = 0;
00999 }
01000
01001 return(nbHits);
01002
01003
01004 }
01005 }
01006
01007
01008
01009
01010
01011
01012 int MicrorocOldLabviewReader::getNextEvent(Event& event) {
01013
01014 Level(0);
01015
01016 ui16 dataFormat = run.getDataFormat();
01017
01018 if (dataFormat == 0) {
01019
01020 bcIdDifAbsOrgMap.clear();
01021
01022 dataFormat = getData(1);
01023 FILE_LOG(logINFO) << " labview data format[" << hex << dataFormat << "] "<< endl;
01024 if ( dataFormat == 0x10 ) { dataFormat = 0xa; }
01025 run.setDataFormat(dataFormat);
01026
01027
01028 if (fileError == EOF) {
01029 FILE_LOG(logERROR) << "parsing file[" << inputFile << "] - error " << errno << ":" << strerror(errno) << endl;
01030 reset();
01031 return(LAST_FILE_EVENT);
01032 }
01033 display(+1);
01034 FILE_LOG(logINFO) << " Microroc LABVIEW DATA FORMAT : " << dataFormat << endl;
01035
01036 if (! ( dataFormat == 11 || dataFormat == 12 || dataFormat == 13) ){
01037
01038 FILE_LOG(logERROR) << " Microroc LABVIEW data format " << dataFormat << " is not implemented" << endl;
01039 reset();
01040 return(LAST_FILE_EVENT);
01041 }
01042
01043 if ( dataFormat == 11 || dataFormat == 12 )
01044 {
01045 run.setDaqSoftware( getData(1));
01046 display(+1);
01047 FILE_LOG(logINFO) << " DAQ software version : " << run.getDaqSoftware() << endl;
01048
01049 run.setCccFirmware(getData(1));
01050 display(+1);
01051 FILE_LOG(logINFO) << " ccc firware : " << run.getCccFirmware() << endl;
01052
01053 globalTime = getData(4) ;
01054 FILE_LOG(logDEBUG) << "globalTime in second:[" << hex << globalTime << "]" << endl;
01055 globalTime *= 1000;
01056 FILE_LOG(logDEBUG1) << "globalTime in millisecond:[" << globalTime << "]" << endl;
01057 }
01058
01059 if ( dataFormat == 13 )
01060 {
01061
01062 run.setDaqSoftware(getData(2) );
01063 display(+1);
01064 FILE_LOG(logINFO) << hex << " DAQ software version : " << run.getDaqSoftware() <<endl;
01065
01066 run.setSDccFirmware(getData(2));
01067 display(+1);
01068 FILE_LOG(logINFO) << hex << " SDcc firware : 0x" << run.getSDccFirmware() << endl;
01069
01070 run.setDifFirmware(getData(2));
01071 display(+1);
01072 FILE_LOG(logINFO) << hex << " Dif firware : 0x" << run.getDifFirmware() << endl;
01073
01074 globalTime = getData(4) ;
01075 FILE_LOG(logDEBUG) << "globalTime in second:[0x" << hex << globalTime << "] decimal[" << dec << globalTime << "]" << endl;
01076 globalTime *= 1000;
01077 FILE_LOG(logDEBUG) << "globalTime in millisecond:[" << globalTime << "]" << endl;
01078
01079 globalTimeMilli = getData(4) ;
01080 FILE_LOG(logDEBUG) << "Plus globalTimeMilli in millisecond:[0x" << hex << globalTimeMilli << "] decimal [" << dec << globalTimeMilli << "]" << endl;
01081 }
01082
01083
01084 if (fileError == EOF) {
01085 FILE_LOG(logDEBUG) << " END OF DATA FILE" << endl;
01086 reset();
01087 return(LAST_FILE_EVENT);
01088 }
01089
01090 display(-1);
01091 return NEW_CONFIG;
01092 }
01093
01094
01095
01096
01097 bool eventFound = false;
01098 while (! eventFound)
01099 {
01100
01101 unsigned int globalHeader = getData(1);
01102 if (fileError == EOF) {
01103 FILE_LOG(logDEBUG) << " END OF DATA FILE" << endl;
01104 reset();
01105 return(LAST_FILE_EVENT);
01106 }
01107 FILE_LOG(logDEBUG) << "globalHeader:["<< hex << globalHeader << "]" << endl;
01108 if (globalHeader == 0xB1) {
01109
01110 getScData();
01111 }
01112 else if (globalHeader == 0xC0) {
01113
01114 getAnalogData(event);
01115 }
01116 else if (globalHeader == 0xB0) {
01117
01118 getAcqData(event);
01119 eventFound = true;
01120 }
01121 else if (globalHeader == 0xBB) {
01122
01123 getAcqData(event,true);
01124 eventFound = true;
01125 }
01126 else {
01127 display();
01128 FILE_LOG(logERROR) << " parsing file error. global header error : " << hex << globalHeader << dec << endl;
01129 }
01130 }
01131
01132
01133 return EVENT_CORRECT;
01134 }
01135