#include <CalibHR2Parser.hh>
Inheritance diagram for CalibHR2Parser:
Public Member Functions | |
CalibHR2Parser (Run &aRun, FILE *aFile, ui32 firstEventId) | |
virtual | ~CalibHR2Parser () |
int | getNextEvent (Event &eventToFill) |
Static Public Member Functions | |
static const char * | type () |
Private Member Functions | |
unsigned int | getData (FILE *inputFile, const int nBytes) |
unsigned int | getDecimalData (FILE *inputFile, const int nBytes) |
unsigned int | checkData (FILE *inputFile, const int nBytes) |
int | getLine (FILE *file, std::string &line) |
int | getDacValue (std::string line) |
void | setMotifValue (std::string line) |
void | initParsing (FILE *inputFile) |
unsigned int | grayToBinary (unsigned int gray) |
int | newHit (Event &event, const Detector &detector, int data, const int chNum, const int chipId, const int difId) |
std::string | binaire (unsigned int nombre) |
void | reset () |
bool | checkNextLine (FILE *inputFile, std::string target) |
Private Attributes | |
bool | init |
bool | motif [MOTIFNB] |
bool | newCalibration |
bool | newDif |
bool | newHR |
int | difId |
int | dac [3] |
Definition at line 27 of file CalibHR2Parser.hh.
CalibHR2Parser::CalibHR2Parser | ( | Run & | aRun, | |
FILE * | aFile, | |||
ui32 | firstEventId | |||
) |
Definition at line 53 of file CalibHR2Parser.cpp.
00054 : AcquisitionParser(aRun, aFile, _firstEventId) 00055 { 00056 FILE_LOG(logDEBUG1) << "--CalibHR2Parser constructor()"<< endl; 00057 00058 run.setCalibrationRun(true); 00059 00060 reset(); 00061 }
CalibHR2Parser::~CalibHR2Parser | ( | ) | [virtual] |
static const char* CalibHR2Parser::type | ( | ) | [inline, static] |
int CalibHR2Parser::getNextEvent | ( | Event & | eventToFill | ) | [virtual] |
Implements AcquisitionParser.
Definition at line 179 of file CalibHR2Parser.cpp.
00180 { 00181 unsigned int nbHits = 0; 00182 // The first line does not contains needed informations 00183 // init fill the motifCtest and place streaming just before the first event 00184 if ( ! init) 00185 { 00186 initParsing(inputFile); 00187 init = true; 00188 } 00189 00190 string line; 00191 00192 if ( newCalibration) 00193 { // get calibration parameters ( DAC_2, DAC_1, D AC_0 values ) 00194 FILE_LOG(logDEBUG1) << "New calibration !" << endl; 00195 size_t found; 00196 00197 do 00198 { 00199 int result = getLine ( inputFile, line); 00200 if (result == EOF) 00201 { 00202 FILE_LOG(logDEBUG1) << "End of file !" << endl; 00203 reset(); 00204 FILE_LOG(logDEBUG1) << "return LAST_FILE_EVENT:[" << LAST_FILE_EVENT << endl; 00205 return LAST_FILE_EVENT; 00206 } 00207 00208 // Get DAC_2 00209 found=line.find("DAC_2"); 00210 } 00211 while (found==string::npos); 00212 00213 dac[0] = -1; 00214 dac[1] = -1; 00215 dac[2] = getDacValue(line); 00216 00217 // Get DAC_1 00218 if ( getLine ( inputFile, line) != EOF ) 00219 { 00220 if ( line.find("DAC_1")!=string::npos) { dac[1] = getDacValue(line); } 00221 else { return EVENT_ERROR; } // DAC_1 value not found 00222 } 00223 00224 // Get DAC_0 00225 if ( getLine ( inputFile, line) != EOF ) 00226 { 00227 if ( line.find("DAC_0")!=string::npos) { dac[0] = getDacValue(line); } 00228 else { return EVENT_ERROR; } // DAC_0 value not found 00229 } 00230 FILE_LOG(logINFO) << "dac_2[" << dac[2] << "]" << endl; 00231 FILE_LOG(logINFO) << "dac_1[" << dac[1] << "]" << endl; 00232 FILE_LOG(logINFO) << "dac_0[" << dac[0] << "]" << endl; 00233 00234 // Set chip configuration 00235 run.setName("turlututu"); 00236 const Detector &detector = run.getDetector(); 00237 try { 00238 ChamberMap_t chambers = detector.getChambers(); 00239 for (ChamberMap_t::iterator chamberIt = chambers.begin(); chamberIt != chambers.end(); chamberIt++) { 00240 Chamber& chamber = *chamberIt->second; 00241 DifMap_t difs = chamber.getDifs(); 00242 for (DifMap_t::iterator difIt = difs.begin(); difIt != difs.end(); difIt++) { 00243 Dif& dif = *difIt->second; 00244 BoardMap_t boards = dif.getBoards(); 00245 for (BoardMap_t::iterator boardIt = boards.begin(); boardIt != boards.end(); boardIt++) { 00246 Board& b = *boardIt->second; 00247 ChipMap_t chips = b.getChips(); 00248 for (ChipMap_t::iterator chipIt = chips.begin(); chipIt != chips.end(); chipIt++) { 00249 Hardroc2Chip &chip = dynamic_cast<Hardroc2Chip &> (*chipIt->second); 00250 chip.setThresholdDac_0(dac[0]); 00251 chip.setThresholdDac_1(dac[1]); 00252 chip.setThresholdDac_2(dac[2]); 00253 for (int chNum = 0; chNum < 64; chNum++) { 00254 Channel& ch = chip.getChannelById(chNum); 00255 ch.setEnable(1); 00256 } 00257 } 00258 } 00259 } 00260 } 00261 } 00262 catch (MicroException &e) { cout << e.getMessage() << endl; } 00263 00264 newCalibration = false; // nany event could be attach to these calibration parametre ( DAC_2 ... ) 00265 return NEW_CONFIG; 00266 } // end if new calibratio 00267 if ( newDif) 00268 { 00269 FILE_LOG(logDEBUG1) << "New Dif !" << endl; 00270 // Place file streamer after B4 00271 int space = 0; // nb bytes beetween B4 and B0 tags 00272 int b0Pos = 6; // B0 tag position 00273 bool find = false; 00274 do 00275 { 00276 b0Pos = ftell(inputFile); 00277 if (getLine ( inputFile, line) == EOF) { 00278 return(LAST_FILE_EVENT); 00279 } 00280 // FILE_LOG(logINFO) << "line[" << line << "]" << endl; 00281 // On verifie que l'on ne retombe pas sur le mot DAC_2, ce qui ce produit si aucune Dif n'a repondu ( du a un BUG ) 00282 if (checkNextLine(inputFile,"DAC_") ) 00283 { 00284 newCalibration = true; 00285 FILE_LOG(logWARNING) << "No data for DAC values:[" << dac[0] << "," << dac[1] << "," << dac[2] << "]" << endl; 00286 return getNextEvent( event); 00287 } 00288 00289 int b0find = line.find("B0",18); 00290 int b4pos = 0; 00291 do 00292 { 00293 b4pos = line.find("B4",b4pos+1); 00294 00295 if ( b4pos - b0find == 46 ) 00296 { 00297 find = true; 00298 } 00299 } 00300 while (b4pos != string::npos && find == false ); 00301 00302 } 00303 while ( !find ); 00304 00305 b0Pos = b0Pos + 18 + 2 ; // position du B0 00306 fseek(inputFile, b0Pos, SEEK_SET); 00307 00308 // File after position "B0" 00309 // Here we are sure to be at the correct position in the file to start 00310 00311 // New DIF 00312 difId = getData(inputFile, 1); 00313 FILE_LOG(logDEBUG1) << " difId[" << difId << "]" << endl; 00314 00315 fseek(inputFile, 42, SEEK_CUR); 00316 // Fichier avant la position "B4" 00317 // New B4 Tag 00318 00319 int dataHeader = getData(inputFile, 1); 00320 FILE_LOG(logDEBUG1) << (hex) << " dataHeader[" << dataHeader << "]" << endl; 00321 if (dataHeader == 0xB4) 00322 { 00323 FILE_LOG(logDEBUG1) << " data header B4 found" << endl; 00324 } 00325 else 00326 { 00327 FILE_LOG(logERROR) << " parsing file error. data header error : " << hex << dataHeader << dec << endl; 00328 return EVENT_ERROR; 00329 } 00330 00331 newDif = false; 00332 00333 00334 } 00335 if ( newHR) 00336 { 00337 FILE_LOG(logDEBUG1) << "New HR !" << endl; 00338 // VERIF TAG A3 pas de skip. Dans le cas ou aucun des chips ne repond 00339 if ( checkData(inputFile, 1) == 0xA3) 00340 { 00341 FILE_LOG(logERROR) << "ERROR TAG A3 just after newHR for DAC values:[" << dac[0] << "," << dac[1] << "," << dac[2] << "]" << endl; 00342 return EVENT_ERROR; 00343 } 00344 // On skip les insultes du hardroc 00345 //fseek ( inputFile, 40, SEEK_CUR); 00346 newHR = false; 00347 } 00348 00349 00350 // On Verifie en hexadecimal que l'on a pas de tag A0 00351 // Pour une Dif, lit ChipId + BCId + donnee 00352 // get Chip Id. Warning ! Decimal 00353 00354 int chipId = -1; 00355 // On doit lire 2 fois car le tag A3 est en Hexedecimal alors que le chipId est en decimal 00356 int foo = getData(inputFile , 1); 00357 if ( foo == 0xA3) 00358 { // Fin de donnees chip(HR) 00359 FILE_LOG(logDEBUG1) << " -------- TAG A3 " << endl; 00360 newHR = true; 00361 foo = getData(inputFile , 1); 00362 if ( foo == 0xA0 ) 00363 { 00364 newDif = true; 00365 FILE_LOG(logDEBUG1) << " -------- Tag A0 derriere A3 " << endl; 00366 foo = getData(inputFile , 2 ); // READ CRC 00367 try { 00368 foo = getData(inputFile, 1 ); 00369 } 00370 catch ( MicroException &e) 00371 { 00372 foo = 0; 00373 } 00374 if ( foo != 0xB0) 00375 { 00376 // On verifie si apres la ligne separatrice "-----------------"c'est une nouvelle acquisition on des nouvelles valeur de DAC 00377 if ( getLine ( inputFile, line) == EOF ) { return LAST_FILE_EVENT ;} // ligne separatrice --------------- 00378 if (checkNextLine(inputFile,"acquisition") ) 00379 { 00380 newDif = true; 00381 } 00382 else 00383 { 00384 00385 00386 newCalibration = true; 00387 FILE_LOG(logDEBUG1) << " -------- Pas de B0 derrire le CRC donc newCalibration = true " << endl; 00388 } 00389 } 00390 else { 00391 FILE_LOG(logDEBUG1) << " -------- B0 derrire le CRC donc Dif " << endl; 00392 } 00393 00394 } 00395 return getNextEvent( event); 00396 } 00397 else 00398 { // Pas Fin de donnees chip(HR) 00399 fseek ( inputFile, -2, SEEK_CUR); 00400 chipId = getData(inputFile, 1); 00401 00402 00403 // get bcid 00404 int bcId = getData(inputFile, 3); 00405 FILE_LOG(logDEBUG1) << (hex) << " bcid[" << bcId << "]" << endl; 00406 00407 00408 // the following data is repeated one time for each Dif which has sent data 00409 00410 bool difFound = false; 00411 Detector& detector = run.getDetector(); 00412 { const ChamberMap_t &chambers = detector.getChambers(); 00413 for (ChamberMap_t::const_iterator it = chambers.begin(); it != chambers.end(); ++it) { 00414 try { 00415 Chamber& chamber = *(it->second); 00416 const BoardMap_t& boards = chamber.getBoardsByDifId(difId); 00417 } 00418 catch (...) { 00419 // any error case - try next chamber 00420 continue; 00421 } 00422 00423 // the DIF has been found in a chamber. Process all data and continue 00424 difFound = true; 00425 break; 00426 } // for 00427 if (!difFound) { 00428 FILE_LOG(logERROR) << " No dif found with Id 0x" << hex << difId << dec << endl; 00429 return EVENT_ERROR; 00430 } 00431 } 00432 00433 // trigger data for 64 channels : 1 bit trigger1, 1 bit trigger0 for each channel from 63 downto 0. 00434 // this makes 2-bit values which should not give bit 1 without bit 0 00435 00436 int canal[16]={0}; 00437 for (int chNum = 48; chNum >= 0; chNum -= 16) { 00438 unsigned int data4; 00439 try { 00440 data4 = getData(inputFile, 4); // on lit 4 Bytes => 8 cara => 16 cannaux 00441 } 00442 catch ( MicroException &e) 00443 { 00444 continue; 00445 } 00446 00447 00448 int index = 0; 00449 for ( index = 0; index <= 15 ; index++) 00450 { 00451 // sur les 16 canaux, on recupere les donnees canal par canal 00452 canal[index] = (data4 >> ((15 - index )* 2 )) & 0x03; // 2 Most Significant Bits of the digi 00453 00454 if ( motif[index+chNum]) 00455 { 00456 if ( newHit(event, detector, canal[index], index + chNum , chipId, difId) != 1 ) 00457 { 00458 // Format de donées non valid, on cherche une balise A3 pour tenter de recuperer les prochain evemements 00459 try 00460 { 00461 foo = getData(inputFile, 1) ; 00462 while ( foo != 0xA3 ) 00463 { 00464 00465 foo = getData(inputFile, 1) ; 00466 } 00467 } 00468 catch ( MicroException &e) 00469 { 00470 FILE_LOG(logINFO) << "End of line 0xA3 not Found !!!" << endl; 00471 newDif = true; 00472 // event.setId(++lastEventId); 00473 //FILE_LOG(logDEBUG1) << " STORE EVENT " << lastEventId << ", " << nbHits << " hits" << endl; 00474 //return EVENT_CORRECT; 00475 00476 00477 } 00478 00479 } 00480 else 00481 {//, dac); 00482 nbHits++; 00483 } 00484 } 00485 } 00486 } 00487 00488 event.setId(++lastEventId); 00489 FILE_LOG(logDEBUG1) << " STORE EVENT " << lastEventId << ", " << nbHits << " hits" << endl; 00490 return EVENT_CORRECT; 00491 } 00492 00493 }
unsigned int CalibHR2Parser::getData | ( | FILE * | inputFile, | |
const int | nBytes | |||
) | [private] |
Definition at line 526 of file CalibHR2Parser.cpp.
Referenced by checkData(), and getNextEvent().
00526 { 00527 unsigned int result = 0; 00528 for (int byte = 0; byte < nBytes; ++byte) { 00529 int data = 0; 00530 if (fscanf(inputFile, "%2x", &data) != 1) { 00531 throw MicroException("get data: fcanf error"); 00532 00533 // return(0); 00534 } 00535 result = (result << 8) + data; 00536 } 00537 return(result); 00538 }
unsigned int CalibHR2Parser::getDecimalData | ( | FILE * | inputFile, | |
const int | nBytes | |||
) | [private] |
Definition at line 543 of file CalibHR2Parser.cpp.
00543 { 00544 unsigned int result = 0; 00545 for (int byte = 0; byte < nBytes; ++byte) { 00546 int data = 0; 00547 if (fscanf(inputFile, "%2d", &data) != 1) { 00548 return(0); 00549 } 00550 result = (result << 8) + data; 00551 } 00552 return(result); 00553 }
unsigned int CalibHR2Parser::checkData | ( | FILE * | inputFile, | |
const int | nBytes | |||
) | [private] |
Definition at line 516 of file CalibHR2Parser.cpp.
Referenced by getNextEvent().
00516 { 00517 00518 int curPos = ftell(inputFile); 00519 unsigned int result = getData(inputFile, nBytes); 00520 fseek(inputFile,curPos,SEEK_SET); 00521 return result; 00522 }
int CalibHR2Parser::getLine | ( | FILE * | file, | |
std::string & | line | |||
) | [private] |
Referenced by getNextEvent(), and initParsing().
int CalibHR2Parser::getDacValue | ( | std::string | line | ) | [private] |
Referenced by getNextEvent().
void CalibHR2Parser::setMotifValue | ( | std::string | line | ) | [private] |
Referenced by initParsing().
void CalibHR2Parser::initParsing | ( | FILE * | inputFile | ) | [private] |
Definition at line 133 of file CalibHR2Parser.cpp.
Referenced by getNextEvent().
00134 { 00135 00136 string line; 00137 size_t found; 00138 00139 00140 do 00141 { 00142 if ( getLine ( inputFile, line) == EOF ) { return ;} 00143 found = line.find("Chips en calibration" ); 00144 00145 line.clear(); 00146 } 00147 while (found==string::npos); 00148 00149 // get motifCTest 00150 if ( getLine ( inputFile, line) == EOF ) { return ;} 00151 found = line.find("motif Ctest" ); 00152 if (found!=string::npos) 00153 { 00154 setMotifValue(line); 00155 } 00156 }
unsigned int CalibHR2Parser::grayToBinary | ( | unsigned int | gray | ) | [private] |
Reimplemented from AcquisitionParser.
int CalibHR2Parser::newHit | ( | Event & | event, | |
const Detector & | detector, | |||
int | data, | |||
const int | chNum, | |||
const int | chipId, | |||
const int | difId | |||
) | [private] |
Definition at line 558 of file CalibHR2Parser.cpp.
Referenced by getNextEvent().
00559 { 00560 // cannot be binary pattern 10 00561 // if (data == 0x2) { 00562 //FILE_LOG(logERROR) << " CHANNEL DATA = 0x02" << endl; 00563 // return(0); 00564 // } 00565 00566 const ChamberMap_t &chambers = detector.getChambers(); 00567 for (ChamberMap_t::const_iterator it = chambers.begin(); it != chambers.end(); ++it) { 00568 try { 00569 Chamber& chamber = *(it->second); 00570 const BoardMap_t& boards = chamber.getBoardsByDifId(difId); 00571 // look for type of chamber 00572 //if (chamber.getType() != HARDROC1CHAMBER) 00573 // continue; 00574 // store new event data 00575 try { 00576 const Channel& channel = chamber.getChannelById(chNum, chipId, difId); 00577 i16 analogValue = 0; 00578 //ChannelHit *hit = new ChannelHit(channel, data, analogValue, dac); 00579 ChannelHit *hit = new ChannelHit(channel, data, analogValue); 00580 // hit->setHardrocTime(globalTime, bcId_Abs, bcId_Dif, bcId_Hit); 00581 event.insertHit(chamber, hit); 00582 FILE_LOG(logDEBUG1) << " new Hit : ch " << chNum << ", chip " << chipId << ", dif " << difId 00583 << " Data=" << data << " , x:" << channel.getX() << ", y:" << channel.getY() << endl; 00584 return(1); 00585 } 00586 catch (MicroException &e) { 00587 FILE_LOG(logERROR) << "ch " << chNum << ", chip " << chipId << ", dif " << difId << " : " << e.getMessage() << endl; 00588 return(0); 00589 } 00590 } 00591 catch (...) { 00592 continue; 00593 } 00594 00595 } // for 00596 return(0); 00597 }
string CalibHR2Parser::binaire | ( | unsigned int | nombre | ) | [private] |
Definition at line 603 of file CalibHR2Parser.cpp.
00604 { 00605 string res = ""; 00606 unsigned int val = nombre; 00607 00608 while (val != 0) { 00609 /* Invariant de boucle : code_binaire(val) + res = code_binaire(nombre) */ 00610 00611 if (val & 1 == 1) { 00612 res = string("1") + res; 00613 } 00614 else { 00615 /* val & 1 == 0 */ 00616 res = string("0") + res; 00617 } 00618 00619 val = val >> 1; 00620 } 00621 return res; 00622 }
void CalibHR2Parser::reset | ( | ) | [private] |
Definition at line 70 of file CalibHR2Parser.cpp.
Referenced by CalibHR2Parser(), and getNextEvent().
00071 { 00072 init = false; 00073 newCalibration = true; 00074 newDif = true; 00075 newHR = true; 00076 difId = -1; 00077 dac[0] = -1; 00078 dac[1] = -1; 00079 dac[2] = -1; 00080 difId = -1; 00081 00082 00083 00084 }
bool CalibHR2Parser::checkNextLine | ( | FILE * | inputFile, | |
std::string | target | |||
) | [private] |
Referenced by getNextEvent().
bool CalibHR2Parser::init [private] |
bool CalibHR2Parser::motif[MOTIFNB] [private] |
bool CalibHR2Parser::newCalibration [private] |
bool CalibHR2Parser::newDif [private] |
bool CalibHR2Parser::newHR [private] |
int CalibHR2Parser::difId [private] |
int CalibHR2Parser::dac[3] [private] |