#include <Hardroc1Reader.hh>
Inheritance diagram for Hardroc1Reader:
Public Member Functions | |
Hardroc1Reader (Run &aRun, FILE *aFile, ui32 lastEventId) | |
~Hardroc1Reader () | |
int | getNextEvent (Event &eventToFill) |
Static Public Member Functions | |
static const char * | type (const int subtype=0) |
Protected Types | |
typedef std::set< int > | SkippedChipSet_t |
Protected Attributes | |
unsigned short | CRC |
int | difId |
ui32 | difTriggerCounter |
ui32 | acqTriggerCounter |
ui32 | globalTriggerCounter |
ui32 | bcPeriod |
i64 | bcId_Abs |
i64 | bcId_AbsOrg |
i64 | bcId_Dif |
i64 | bcId_Hit |
i64 | eventTime |
SkippedChipSet_t | skippedChips |
int | SkippedBcId |
Private Member Functions | |
void | reset () |
int | getScData () |
int | getAcqData (Event &event) |
int | storeEvent (Event &event) |
int | newHit (Event &event, const Detector &detector, int data, const int chNum, const int chipId, const int difId) |
Definition at line 26 of file Hardroc1Reader.hh.
typedef std::set<int> Hardroc1Reader::SkippedChipSet_t [protected] |
Definition at line 59 of file Hardroc1Reader.hh.
Hardroc1Reader::Hardroc1Reader | ( | Run & | aRun, | |
FILE * | aFile, | |||
ui32 | lastEventId | |||
) |
Definition at line 53 of file Hardroc1Reader.cpp.
00053 : DifReader(aRun, aFile, lastEventId) 00054 { 00055 FILE_LOG(logDEBUG1) << "--Hardroc1Reader constructor()"<< endl; 00056 reset(); 00057 }
Hardroc1Reader::~Hardroc1Reader | ( | ) |
static const char* Hardroc1Reader::type | ( | const int | subtype = 0 |
) | [inline, static] |
Definition at line 30 of file Hardroc1Reader.hh.
Referenced by main().
00030 { return CROSSDAQHR1; };
int Hardroc1Reader::getNextEvent | ( | Event & | eventToFill | ) | [virtual] |
Implements AcquisitionParser.
Definition at line 471 of file Hardroc1Reader.cpp.
00471 { 00472 // Start data reconstruction 00473 Level(0); 00474 00475 ui16 dataFormat = run.getDataFormat(); 00476 00477 if (dataFormat == 0) { 00478 // first read of the file 00479 bcIdDifAbsOrgMap.clear(); 00480 // read file header 00481 dataFormat = getData(1); 00482 run.setDataFormat(dataFormat); 00483 if (fileError == EOF) { 00484 FILE_LOG(logERROR) << "parsing file[" << inputFile << "] - error " << errno << ":" << strerror(errno) << endl; 00485 reset(); 00486 return(LAST_FILE_EVENT); 00487 } 00488 display(+1); 00489 FILE_LOG(logINFO) << " HARDROC1 Dif VHDL data format : " << dataFormat << endl; 00490 00491 if (dataFormat != 2 && dataFormat != 3 && dataFormat != 4 && dataFormat != 7 && dataFormat != 8) { 00492 // unknown format 00493 FILE_LOG(logERROR) << " HARDROC1 Dif VHDL data format " << dataFormat << " is not implemented" << endl; 00494 reset(); 00495 return(LAST_FILE_EVENT); 00496 } 00497 00498 FILE_LOG(logDEBUG) << run.getDetector() << endl; 00499 display(-1); 00500 return NEW_CONFIG; 00501 } 00502 00503 // empty the list of chips for which first line has to be skipped 00504 skippedChips.clear(); 00505 00506 // loops until a non-empty event has been found 00507 for (unsigned int nbHits = 0; !nbHits; ) { 00508 00509 if (dataFormat == 2 || dataFormat == 3 || dataFormat == 4) { 00510 ui32 timestampTime = getData(4); 00511 ui32 timestampMilliseconds = getData(4); 00512 globalTime = timestampTime * 1000 + timestampMilliseconds; 00513 } 00514 else if (dataFormat == 7) { 00515 // read in Slow Control data 00516 } 00517 else if (dataFormat == 8) { 00518 ui32 timestampTime = getData(4); 00519 globalTime = timestampTime * 1000; 00520 } 00521 00522 // look for a global data header and process corresponding data 00523 unsigned int globalHeader = getData(1); 00524 if (fileError == EOF) { 00525 FILE_LOG(logINFO) << " END OF DATA FILE" << endl; 00526 reset(); 00527 return(LAST_FILE_EVENT); 00528 } 00529 00530 if (globalHeader == 0xB1) { 00531 // slow control data 00532 getScData(); 00533 } 00534 else if (globalHeader == 0xB0) { 00535 // acquisition data 00536 nbHits = getAcqData(event); 00537 } 00538 else { 00539 display(); 00540 FILE_LOG(logERROR) << " parsing file error. global header error : " << hex << globalHeader << dec << endl; 00541 } 00542 } // for (nbHits) 00543 00544 return EVENT_CORRECT; 00545 }
void Hardroc1Reader::reset | ( | ) | [private] |
Definition at line 66 of file Hardroc1Reader.cpp.
Referenced by getNextEvent(), and Hardroc1Reader().
00066 { 00067 bcId_AbsOrg = -1; // the bcId origin in milliseconds 00068 CRC = 0; // current CRC for the whole file 00069 SkippedBcId = 0; 00070 00071 // following initializations are useless 00072 globalTime = 0; 00073 difId = -1; 00074 difTriggerCounter = acqTriggerCounter = globalTriggerCounter = 0; 00075 bcPeriod = 200; 00076 bcId_Abs = bcId_Dif = bcId_Hit = 0; 00077 } // Hardroc1Reader.reset
int Hardroc1Reader::getScData | ( | ) | [private] |
Definition at line 81 of file Hardroc1Reader.cpp.
Referenced by getNextEvent().
00081 { 00082 unsigned int data; 00083 00084 display(+1); 00085 FILE_LOG(logDEBUG) << " Slow Control data header B1 found" << endl; 00086 ui16 dataFormat = run.getDataFormat(); 00087 00088 if (dataFormat == 7) { 00089 // get time stamp 00090 i64 timestampTime = getData(4); 00091 globalTime = timestampTime * 1000; 00092 display(); 00093 FILE_LOG(logDEBUG) << " timestampTime = 0x" << hex << timestampTime << " = " << dec << timestampTime << endl; 00094 } 00095 00096 int scBoardNumber = getData(1); 00097 display(); 00098 FILE_LOG(logDEBUG) << "NB chip configuration[" << scBoardNumber << "]" << endl; 00099 00100 // skip al data 00101 // for (int dataNum = 0; ; ) { 00102 // data = getData(1); ++dataNum; 00103 // if ((dataNum % 72) == 0) 00104 00105 00106 for ( int nbChip = 0 ; nbChip < scBoardNumber ; nbChip++) 00107 { 00108 unsigned char *buf = initGetBits(72, false); 00109 if (!buf) 00110 { 00111 FILE_LOG(logERROR) << " malloc error while getting SC buffer" << endl; 00112 break; 00113 } 00114 FILE_LOG(logDEBUG) << "------------------- Config chip [" << nbChip << "]" << endl; 00115 ui16 en = getBits(4); 00116 //FILE_LOG(logDEBUG) << "En 1-4[" << BinOut(en,4) <<"]" << endl; 00117 ui16 chipId = getBits(8); 00118 FILE_LOG(logDEBUG) << "header chip id: 5-12 [" << BinOut(chipId,8) <<"]=" << dec<< chipId << "]" << endl; 00119 ui16 bypass_chip = getBits(1); 00120 //FILE_LOG(logDEBUG) << "bypass_chip 13 [ " << BinOut(bypass_chip,1) <<"]" << endl; 00121 00122 ui16 en2 = getBits(6); 00123 //FILE_LOG(logDEBUG) << "En2 14-19 [" << BinOut(en2,6) <<"]" << endl; 00124 00125 getBits(1); 00126 00127 ui32 validTrig = getBits(32); 00128 //FILE_LOG(logDEBUG) << "validTrig 21-52[" << BinOut(validTrig,32) <<"]" << endl; 00129 validTrig = getBits(32); 00130 // FILE_LOG(logDEBUG) << "validTrig 53-84[" << BinOut(validTrig,32) <<"]" << endl; 00131 00132 ui32 bzero = getBits(10); 00133 FILE_LOG(logDEBUG) << "b0 85-94[" << BinOut(bzero) <<"]" << dec<< bzero << "]" << endl; 00134 00135 00136 ui32 bun = getBits(10); 00137 FILE_LOG(logDEBUG) << "b1 95-104[" << BinOut(bun,20) <<"]" << dec<< bun << "]" << endl; 00138 00139 ui32 on = getBits(3); 00140 //FILE_LOG(logDEBUG) << "on 105-107[" << BinOut(on,3) <<"]" << endl; 00141 00142 ui32 ctest = getBits(32); 00143 //FILE_LOG(logDEBUG) << "ctest 108-139[" << BinOut(ctest,32) <<"]" << endl; 00144 ctest = getBits(32); 00145 //FILE_LOG(logDEBUG) << "ctest 140 - 171[" << BinOut(ctest,32) <<"]" << endl; 00146 00147 for ( int chIndex = 0 ; chIndex <=63 ; chIndex++ ) 00148 { 00149 ui32 pream = getBits(6); 00150 //FILE_LOG(logDEBUG) << "preamp ch"<< chIndex << " " << 172+(chIndex*6) << "-" << 172+(chIndex*6)+ 6 << "["<< BinOut(pream,6) <<"]" << endl; 00151 FILE_LOG(logDEBUG) << "gain channel"<< chIndex << "["<< BinOut(pream,6) <<"]=" << dec << pream << endl; 00152 } 00153 00154 on = getBits(7); 00155 //FILE_LOG(logDEBUG) << "on 556 - 562 " << BinOut(on,7) <<"]" << endl; 00156 00157 ui16 valid_dc = getBits(1); 00158 //FILE_LOG(logDEBUG) << "valid_dc 563[" << BinOut(valid_dc,1) <<"]" << endl; 00159 00160 ui16 sw = getBits(4); 00161 //FILE_LOG(logDEBUG) << "sw 564 - 567 [" << BinOut(sw,4) <<"]" << endl; 00162 00163 ui16 choix_caisson = getBits(1); 00164 //FILE_LOG(logDEBUG) << "choix_caisson 568 [" << BinOut(choix_caisson,1) <<"]" << endl; 00165 00166 sw = getBits(3); 00167 //FILE_LOG(logDEBUG) << "sw 569 - 571[" << BinOut(sw,3) <<"]" << endl; 00168 00169 getBits(4); 00170 00171 00172 finishGetBits(); 00173 00174 00175 00176 // Store config information to Hardroc1Chip 00177 00178 const Detector &detector = run.getDetector(); 00179 try 00180 { 00181 Dif& dif = detector.getDifById(difId); 00182 try { 00183 Hardroc1Chip& chip = dynamic_cast<Hardroc1Chip &> (dif.getChipById(chipId)); 00184 FILE_LOG(logDEBUG1) << " Hardroc1 slow control for chip " << chipId << " et Dif " << difId << " configuration set: " << endl; 00185 chip.setThresholdDac_0(bzero); 00186 chip.setThresholdDac_1(bun); 00187 } 00188 catch ( ... ) 00189 { 00190 } 00191 } 00192 catch ( MicroException e ) 00193 { 00194 FILE_LOG(logINFO) << " Hardroc1 slow control for chip " << chipId << " et Dif " << difId << " configuration: " << e.getMessage() << endl; 00195 00196 } 00197 00198 } 00199 00200 while ( getData(1) != 0xA1) 00201 { 00202 FILE_LOG(logERROR) << "0xA1 trailer not found" << endl; 00203 } 00204 data = 0xA1; 00205 display(); 00206 // if (data == 0xA1) 00207 // break; 00208 //} 00209 00210 00211 display(-1); 00212 if (data != 0xA1) 00213 FILE_LOG(logERROR) << " parsing file error : Slow control trailer 0xA1 not found [" << hex << data << dec << "]" << endl; 00214 00215 return(1); 00216 } // Hardroc1Reader.getScData
int Hardroc1Reader::getAcqData | ( | Event & | event | ) | [private] |
Definition at line 220 of file Hardroc1Reader.cpp.
Referenced by getNextEvent().
00220 { 00221 unsigned int nbHits = 0; 00222 00223 ui16 dataFormat = run.getDataFormat(); 00224 display(+1); 00225 FILE_LOG(logDEBUG) << " global header B0 found" << endl; 00226 00227 // reset the data for the block 00228 // bcId_AbsOrg = -1; 00229 bcId_Abs = 0; // max. 48 bits 00230 bcId_Dif = 0; 00231 // the following data is repeated one time for each Dif which has sent data 00232 difId = getData(1); 00233 difTriggerCounter = getData(4); 00234 if (dataFormat == 4 || dataFormat == 7 || dataFormat == 8) 00235 acqTriggerCounter = getData(4); // trigger counter version >= 4 00236 globalTriggerCounter = getData(4); 00237 if (dataFormat == 3 || dataFormat == 4) { 00238 bcId_Abs = getData(3); 00239 } 00240 else if (dataFormat == 7 || dataFormat == 8) { 00241 ui64 bcIdHigh = getData(2); 00242 ui64 bcIdLow = getData(4); 00243 bcId_Abs = (bcIdHigh << 32) + bcIdLow; 00244 bcId_Dif = getData(3); 00245 } 00246 00247 // if (bcId_AbsOrg == -1) { 00248 // // set the absolute bcId origin 00249 // bcId_AbsOrg = bcId_Abs; 00250 // FILE_LOG(logDEBUG) << " set bc origin " << bcId_AbsOrg << endl; 00251 // } 00252 bcId_AbsOrg = getbcIdAbsOrg(difId, bcId_Abs); 00253 display(); 00254 00255 // the bcTime in milliseconds 00256 i64 bcTime = ((bcId_Abs - bcId_AbsOrg) * bcPeriod) / 1000; 00257 // the reading time in milliseconds 00258 i64 readTime = globalTime + bcTime; 00259 00260 FILE_LOG(logDEBUG) << " START EVENT ------------- time " << readTime << " ms" << endl; 00261 FILE_LOG(logDEBUG) << " bc time " << bcTime << " ms" << endl; 00262 FILE_LOG(logDEBUG) << " DIF Id 0x" << hex << (int)difId << dec << endl; 00263 FILE_LOG(logDEBUG) << " DIF trigger counter " << difTriggerCounter << endl; 00264 if (dataFormat == 4 || dataFormat == 7 || dataFormat == 8) 00265 FILE_LOG(logDEBUG) << " ACQ trigger counter " << acqTriggerCounter << endl; 00266 FILE_LOG(logDEBUG) << " total trigger counter " << globalTriggerCounter << endl; 00267 if (dataFormat == 3 || dataFormat == 4 || dataFormat == 7 || dataFormat == 8) 00268 FILE_LOG(logDEBUG) << " absolute bcId " << bcId_Abs - bcId_AbsOrg << endl; 00269 // end of global header 00270 00271 bool difFound = false; 00272 Detector &detector = run.getDetector(); 00273 { const ChamberMap_t &chambers = detector.getChambers(); 00274 for (ChamberMap_t::const_iterator it = chambers.begin(); it != chambers.end(); ++it) { 00275 try { 00276 Chamber& chamber = *(it->second); 00277 const BoardMap_t& boards = chamber.getBoardsByDifId(difId); 00278 } 00279 catch (...) { 00280 // any error case - try next chamber 00281 continue; 00282 } 00283 00284 // the DIF has been found in a chamber. Process all data and continue 00285 difFound = true; 00286 break; 00287 } // for 00288 if (!difFound) { 00289 FILE_LOG(logERROR) << " No dif found with Id 0x" << hex << difId << dec << endl; 00290 } 00291 } 00292 00293 for (bool finish = false; !finish; ) { 00294 int delimiter = 0; 00295 00296 display(); 00297 for (; delimiter != 0xA0 && delimiter != 0xB4; ) { 00298 // seek for first data frame header (0xB4) 00299 delimiter = getData(1); 00300 if (fileError == EOF) { 00301 delimiter = 0; 00302 break; 00303 } 00304 if (delimiter == 0xA3) 00305 FILE_LOG(logERROR) << " frame trailer A3 found -- should not" << endl; 00306 } 00307 if (delimiter == 0x00) { 00308 FILE_LOG(logERROR) << " end of file -- should not" << endl; 00309 break; 00310 } 00311 if (delimiter == 0xA0) { 00312 unsigned short CRC_check = getData(2); 00313 display(-1); 00314 FILE_LOG(logDEBUG) << " global trailer A0 found" << endl; 00315 break; 00316 } 00317 display(+1); 00318 FILE_LOG(logDEBUG) << " frame header B4 found" << endl; 00319 00320 int chipId = -1; 00321 for (; ; ) { 00322 chipId = getData(1); 00323 if (fileError == EOF) { 00324 finish = true; 00325 FILE_LOG(logINFO) << " end of file found -- should not" << endl; 00326 break; 00327 } 00328 if (chipId == 0x00) { 00329 // dummy null bytes 00330 continue; 00331 } 00332 else if (chipId == 0xA3) { 00333 display(-1); 00334 FILE_LOG(logDEBUG) << " frame trailer A3 found" << endl; 00335 break; 00336 } 00337 else if (chipId == 0xA0) { 00338 finish = true; 00339 display(-1); 00340 FILE_LOG(logERROR) << " global trailer A0 found -- should not" << endl; 00341 int CRC_check = getData(1); 00342 break; 00343 } 00344 else if (chipId == 0xC3) { 00345 display(-1); 00346 FILE_LOG(logERROR) << " frame trailer C3 found - error occured during data transfer" << endl; 00347 break; 00348 } 00349 00350 // bcId from hardroc chip is counted as Gray code 00351 bcId_Hit = grayToBinary(getData(3)); 00352 // event time in milliseconds 00353 eventTime = readTime + (((bcId_Dif - bcId_Hit) * bcPeriod) / 1000); 00354 00355 // for each chip, always skip first line of data which is corrupted 00356 // <=> if chip not found in the list then this is the first line 00357 // also skip lines where bcId is < 2 (most of the time, data is corrupted) 00358 int logicalChipId = (difId << 8) + chipId; 00359 SkippedChipSet_t::const_iterator chipIt = skippedChips.find(logicalChipId); 00360 if (chipIt == skippedChips.end() 00361 || (bcId_Hit <= 1)) { 00362 if (chipIt == skippedChips.end()) { 00363 FILE_LOG(logDEBUG) << " skip data (first line for chip 0x" << hex << logicalChipId << dec << ")" << endl; 00364 skippedChips.insert(logicalChipId); 00365 } 00366 else { 00367 FILE_LOG(logDEBUG) << " skip data (bcIdHit = " << (int)bcId_Hit << ")" << endl; 00368 SkippedBcId++; 00369 } 00370 00371 for (int chNum = 48; chNum >= 0; chNum -= 16) { 00372 unsigned int data4 = getData(4); // lit 4 bytes => 8 char => 16 canaux 00373 } 00374 } 00375 else { 00376 // not on first line and bcId OK : get and check data 00377 if (difFound) { 00378 FILE_LOG(logDEBUG) << " chip Id 0x" << hex << (int)chipId << dec << endl; 00379 FILE_LOG(logDEBUG) << " bcId Hardroc " << (int)bcId_Hit << endl; 00380 FILE_LOG(logDEBUG) << " event time " << eventTime << endl; 00381 } 00382 00383 // trigger data for 64 channels : 1 bit trigger1, 1 bit trigger0 for each channel from 63 downto 0. 00384 // this makes 2-bit values which should not give bit 1 without bit 0 00385 for (int chNum = 48; chNum >= 0; chNum -= 16) { 00386 unsigned int data4 = getData(4); // lit 4 bytes => 8 char => 16 canaux 00387 00388 if (difFound) { 00389 for (int index = 0; index < 16; index++) { 00390 // sur les 16 canaux, recupere les donnees canal par canal 00391 int trigger = (data4 >> ((15 - index) * 2)) & 0x03; // 2 bits 00392 // store new event data if any 00393 if (trigger) { 00394 nbHits += newHit(event, detector, trigger, index + chNum, chipId, difId); 00395 } 00396 } // for (index) 00397 } 00398 } // for (chNum) 00399 } 00400 display(); 00401 } // for(;;) 00402 00403 } // for (;;) 00404 display(-1); 00405 00406 if (nbHits) { 00407 // CREATE EVENT for current Run 00408 event.setTimeStamp(globalTime + (bcId_AbsOrg * bcPeriod) / 1000); 00409 00410 event.setId(++lastEventId); 00411 FILE_LOG(logDEBUG1) << " STORE EVENT " << lastEventId << ", " << nbHits << " hits" << endl; 00412 } 00413 else 00414 FILE_LOG(logDEBUG) << " EMPTY EVENT" << endl; 00415 00416 00417 if (SkippedBcId) { 00418 FILE_LOG(logWARNING) << " skipped " << SkippedBcId << " data because of bad bcId" << endl; 00419 SkippedBcId = 0; 00420 } 00421 00422 return(nbHits); 00423 } // Hardroc1Reader.getAcqData
int Hardroc1Reader::storeEvent | ( | Event & | event | ) | [private] |
int Hardroc1Reader::newHit | ( | Event & | event, | |
const Detector & | detector, | |||
int | data, | |||
const int | chNum, | |||
const int | chipId, | |||
const int | difId | |||
) | [private] |
Definition at line 426 of file Hardroc1Reader.cpp.
Referenced by getAcqData().
00426 { 00427 // cannot be binary pattern 10 00428 if (data == 0x2) { 00429 FILE_LOG(logERROR) << " CHANNEL DATA = 0x02" << endl; 00430 // return(0); 00431 } 00432 00433 const ChamberMap_t &chambers = detector.getChambers(); 00434 for (ChamberMap_t::const_iterator it = chambers.begin(); it != chambers.end(); ++it) { 00435 try { 00436 Chamber& chamber = *(it->second); 00437 const BoardMap_t& boards = chamber.getBoardsByDifId(difId); 00438 // look for type of chamber 00439 // if (chamber.getType() != HARDROC1CHAMBER) 00440 // continue; 00441 // store new event data 00442 try { 00443 const Channel& channel = chamber.getChannelById(chNum, chipId, difId); 00444 i32 analogValue = 0; 00445 ChannelHit *hit = new ChannelHit(channel, data, analogValue); 00446 00447 hit->setHardrocTime(globalTime, bcId_Abs, bcId_Dif, bcId_Hit,0); 00448 event.insertHit(chamber, hit); 00449 FILE_LOG(logDEBUG) << " new Hit : ch " << chNum << ", chip " << chipId << ", dif " << difId 00450 << ", Time=" << globalTime << " abs=" << bcId_Abs << " dif=" << bcId_Dif << " hit=" << bcId_Hit << " Data=" << data << endl; 00451 return(1); 00452 } 00453 catch (MicroException &e) { 00454 FILE_LOG(logERROR) << "ch " << chNum << ", chip " << chipId << ", dif " << difId << " : " << e.getMessage() << endl; 00455 return(0); 00456 } 00457 } 00458 catch (...) { 00459 FILE_LOG(logDEBUG) << " board list not found - try next" << endl; 00460 continue; 00461 } 00462 00463 } // for 00464 FILE_LOG(logERROR) << " ch " << chNum << ", chip " << chipId << ", dif " << difId << " : geometry element not found" << endl; 00465 return(0); 00466 } // Hardroc1Reader.newHit
unsigned short Hardroc1Reader::CRC [protected] |
int Hardroc1Reader::difId [protected] |
Definition at line 48 of file Hardroc1Reader.hh.
Referenced by getAcqData(), getScData(), and reset().
ui32 Hardroc1Reader::difTriggerCounter [protected] |
ui32 Hardroc1Reader::acqTriggerCounter [protected] |
ui32 Hardroc1Reader::globalTriggerCounter [protected] |
ui32 Hardroc1Reader::bcPeriod [protected] |
i64 Hardroc1Reader::bcId_Abs [protected] |
i64 Hardroc1Reader::bcId_AbsOrg [protected] |
i64 Hardroc1Reader::bcId_Dif [protected] |
i64 Hardroc1Reader::bcId_Hit [protected] |
i64 Hardroc1Reader::eventTime [protected] |
SkippedChipSet_t Hardroc1Reader::skippedChips [protected] |
int Hardroc1Reader::SkippedBcId [protected] |