/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/parser/MicrorocXDaqReader.cpp

Go to the documentation of this file.
00001 /* @version $Revision: 1767 $ * @modifiedby $Author: lcdet $ * @lastmodified $Date: 2012-06-08 15:44:25 +0200 (Fri, 08 Jun 2012) $ */
00002 
00003 ////////////////////////////////////////////////////////////////////////
00004 // MICROMEGAS
00005 //
00006 //       EVENT RECONSTRUCTION SOFTWARE FOR MICROROC BOARDS
00007 //
00008 ////////////////////////////////////////////////////////////////////////
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <errno.h>
00013 
00014 #include "parser/MicrorocXDaqReader.hh"
00015 #include "parser/MicrorocSCReader.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 
00032 #include "lcio.h"
00033 #include "IO/LCReader.h"
00034 #include "IMPL/LCTOOLS.h"
00035 #include "IMPL/LCGenericObjectImpl.h"
00036 #include "EVENT/LCCollection.h"
00037 #include "EVENT/LCRunHeader.h"
00038 
00039 #include "geometry/MicrorocChannel.hh"
00040 
00041 #include "ilcConfDb/IlcConfDb.hh"
00042 
00043 
00044 #include <iostream>
00045 #include <iomanip>
00046 
00047 
00048 #define NBBYTETOSKIP  94
00049 
00050 using namespace std;
00051 using namespace lcio ;
00052 
00053 
00054 ////////////////////////////////////////////////////////////////////////
00055 MicrorocXDaqReader::MicrorocXDaqReader(Run& aRun, string aFileFullPath, ui32 lastEventId,bool _forceAnalog, set<unsigned int>*_difList) : MicrorocReader(aRun, NULL, lastEventId), nbChipPerLine(0), analogDataActivate(false), firstEvent(true), slowControlSet(false), difList(_difList) , hexTemperatureAsu1(0), hexTemperatureAsu2(0), hexTemperatureDif(0) , forceAnalog(_forceAnalog) , debugEventId(0)
00056 
00057 {
00058   FILE_LOG(logDEBUG1) << "--MicrorocXDaqReader constructor()"<< endl;
00059 
00060   lcReader = LCFactory::getInstance()->createLCReader() ;
00061   try {
00062     lcReader->open(aFileFullPath);
00063 /* Seems to be not set by XDAQ
00064     EVENT::LCRunHeader *runHeader = lcReader->readNextRunHeader();
00065     if ( runHeader != NULL ) 
00066     {
00067       cout << "-------------runNumber: " << runHeader->getRunNumber() << endl;
00068       cout << "-------------runDetectorName: " << runHeader->getDetectorName() <<endl;
00069       cout << "-------------runDescription: " << runHeader->getDescription() <<endl;
00070       exit (10);
00071     }
00072     else { cout << "runHeader == NULL: "  << endl; }
00073 */
00074   }
00075   catch( IOException& e) {
00076     cout << e.what() << endl ;
00077     exit(-1) ;
00078   }
00079   
00080   if ( lcReader == NULL ) { exit(-1); }
00081 
00082   for ( ui16 line = 0 ; line < NBLINE ; line++)
00083   {
00084     analogDataActivatedLine[line] = false;
00085   }
00086 
00087   localReset();
00088 
00089 }
00090 
00091 //--------------- Destructeur -------------//
00092 MicrorocXDaqReader::~MicrorocXDaqReader()
00093 {
00094   lcReader->close();
00095   delete lcReader;
00096   FILE_LOG(logDEBUG1)<< "----MicrorocXDaqReader destructor"<< endl;
00097 }
00098                                                                                                              
00099 //--------------- reset -------------//
00100 void MicrorocXDaqReader::localReset()
00101 {
00102   reset(); // appel MicrorocReader::reset();
00103   slowControlSet = false;
00104   rawdataList.clear();
00105   hexTemperatureAsu1 = 0;
00106   hexTemperatureAsu2 = 0;
00107   hexTemperatureDif = 0;
00108 }
00109 //------------------------------------------//
00110 int MicrorocXDaqReader::getScData()
00111 {
00112 return 0;
00113 }
00114 //------------------------------------------//
00115 int MicrorocXDaqReader::getNextEvent(Event& event) 
00116 {
00117   Level(0);
00118   ui16 dataFormat = run.getDataFormat();
00119 
00120   if (dataFormat == 0) {
00121     // first read of the file
00122     bcIdDifAbsOrgMap.clear();
00123     // read file header
00124     dataFormat = 1;
00125     run.setDataFormat(dataFormat);
00126     //FILE_LOG(logINFO) << " labview data format[" << hex << dataFormat << "] "<< endl;
00127     //run.setDaqSoftware(333);
00128     //run.setCccFirmware(333);
00129     //globalTime = 333;
00130     
00131     return NEW_CONFIG;
00132   } // end dataFormat == 0
00133 
00134   // loops until a non-empty event has been found
00135   bool eventFound = false;
00136   while (! eventFound)
00137   {
00138     LCEvent* lcioEvt(0) ;
00139     lcioEvt = lcReader->readNextEvent() ;
00140     if ( lcioEvt == NULL ) // EOF reach
00141     {
00142       return LAST_FILE_EVENT;
00143     }
00144 
00145 
00146     // There is one more LCEvent
00147     //LCTOOLS::dumpEvent( lcioEvt ) ;
00148     if ( ! slowControlSet )
00149     {
00150       // Read Slow control from database
00151       if ( event.getRun().getId() == 0 )
00152       {  // try to find run Id in lcioEvt
00153         run.setId(lcioEvt->getRunNumber());
00154         FILE_LOG(logINFO) << "Set run Id from lcioEvent information[" << run.getId() << "]" << endl;
00155       }
00156       
00157       globalTime = (i64) ( lcioEvt->getTimeStamp()*1000 );
00158 
00159       run.setDaqSoftware(0);
00160       run.setCccFirmware(0);
00161 
00162       IlcConfDb *ilcconf = IlcConfDb::getInstance();
00163       if ( ilcconf != NULL )
00164       {
00165         MicrorocSCReader scReader(run);
00166         scReader.parseSCFromDb(*ilcconf);
00167         slowControlSet = true;
00168       }
00169 
00170     }
00171     if ( firstEvent  )
00172     {
00173       FILE_LOG(logINFO) << "firstEvent  skip"  << endl;
00174       firstEvent = false;
00175       // skip first event because of its corruption ???
00176     }
00177 /*
00178     else if (  debugEventId < 637)
00179     {
00180       debugEventId++;
00181       cout << "skip event " << debugEventId << endl;
00182     }
00183 */
00184     else
00185     {
00186       // vnames to store lcioEvt collections name
00187       std::vector<std::string >* vnames;
00188       try
00189       {
00190         vnames= (std::vector<std::string >*)lcioEvt->getCollectionNames();
00191         /*
00192         cout << "run number: " << lcioEvt->getRunNumber()<< endl;
00193         cout << "event number: " << lcioEvt->getEventNumber()<< endl;
00194         cout << "timestamp: " << lcioEvt->getTimeStamp()<< endl;
00195         cout << "detectorName: " << lcioEvt->getDetectorName()<< endl;
00196         cout << "weight: " << lcioEvt->getWeight()<< endl;
00197         */
00198         for ( vector<std::string >::iterator it = vnames->begin();  it!= vnames->end(); it++)
00199         {
00200           if ((*it).compare("RU_XDAQ")==0)
00201           {
00202             EVENT::LCCollection* col= lcioEvt->getCollection(*it);
00203     //        cout << "collection name:["<< *it << "]"  << endl;
00204 
00205             for (int difRawDataIndex=0;difRawDataIndex<col->getNumberOfElements(); difRawDataIndex++)
00206             {
00207               IMPL::LCGenericObjectImpl* go= (IMPL::LCGenericObjectImpl*) col->getElementAt(difRawDataIndex);
00208               int rusize =go->getNInt();
00209      //         std::cout<<" New RU found with "<<rusize<<" int stored" <<std::endl;
00210               if ( rusize == 56 ) continue; // skip first RU_XDAQ si tsille est 56 int
00211 
00212               int shift=-1;
00213               ui16 nbInt = go->getNInt();
00214       //        cout << "DEBUG ---nbInt [" << dec << nbInt << "]-----------------" <<endl;
00215 
00216               
00217               unsigned int buf[go->getNInt()];
00218 
00219               for (int k=0; k < (go->getNInt() );k++) { buf[k] = go->getIntVal(k); }
00220               // skip first NBBYTETOSKIP ( 94 ) bytes 
00221               // then fill rawdataList with unsigned char
00222               unsigned char* bufChar = ( unsigned char* ) &(buf); 
00223               ui16 rapport = (ui16) (sizeof(unsigned int ) / sizeof ( unsigned char) );
00224 
00225               rawdataList.clear();
00226               for ( ui32 j = NBBYTETOSKIP ; j < go->getNInt()*rapport ; j++ )
00227               {
00228                 rawdataList.push_back(*(bufChar+j));
00229               }
00230               
00231               itRawdata = rawdataList.begin();
00232               unsigned int globalHeader = getData(1);
00233 
00234               if (globalHeader == 0xB1) {
00235                 // slow control data
00236                 getScData();
00237                 exit(-1); // Conf in Oracle DB not in raw data
00238               }
00239               else if (globalHeader == 0xC0) {
00240                 // acquisition data
00241                 getAnalogData(event);
00242               }
00243               else if (globalHeader == 0xB0) {
00244                 // acquisition data
00245                 this->analogData.clear();
00246                 getAcqData(event,bufChar);
00247                 //eventFound = true;
00248               }
00249               else if (globalHeader == 0xBB) {
00250                 // acquisition data
00251                 FILE_LOG(logDEBUG) << "  0xBB found " << hex << globalHeader << dec << endl;
00252                 getAcqData(event,bufChar,true);
00253                 //eventFound = true;
00254               }
00255               else {
00256                 FILE_LOG(logERROR) << "  parsing file error. global header error : " << hex << globalHeader << dec << endl;
00257                 event.setValidFlag(UNKNOW_NOT_VALID);
00258               }
00259             } // end for data for dif
00260             eventFound = true ;
00261             event.setId(++lastEventId);
00262           } // ed if collection = XU_XDAQ
00263         } // end for collection in event
00264       }
00265       catch (IOException& e)
00266       {
00267         std::cout << e.what() << std::endl ;
00268         std::string s=e.what();s+=__PRETTY_FUNCTION__;
00269         exit(-1);
00270       }
00271       catch (...)
00272       {
00273         std::cout<<" unknow io exeption "<<std::endl;
00274         exit(-1);
00275       }
00276       /*DEBUG */  unsigned int globalHeader = 0XB0;
00277     } // end else not first event
00278 
00279     
00280   }// end while event not found
00281 
00282   return EVENT_CORRECT;
00283 
00284 
00285 
00286 
00287 
00288 return 0;
00289 }
00290 //------------------------------------------//
00291 int MicrorocXDaqReader::getAcqData(Event& event,unsigned char *bufChar, bool temperatureFill) 
00292 {
00293 
00294   ui32 nbanalogHit = 0;
00295   unsigned int nbHits = 0;
00296 
00297   display(+1);
00298 
00299 
00300   this->setComputeCrcFlag(true);
00301   //FILE_LOG(logDEBUG) << "MicrorocLabviewReader crc adr[" <<  crc << "]" << endl;
00302 
00303   if ( temperatureFill )
00304   {
00305     FILE_LOG(logDEBUG) << " global header BB found" << endl;
00306     FILE_LOG(logDEBUG) << "crc->compute(0xBB)[ "<< crc <<"]"   << endl;
00307     crc->compute(0xBB);
00308   }
00309   else 
00310   {
00311     FILE_LOG(logDEBUG) << " global header B0 found" << endl;
00312      FILE_LOG(logDEBUG) << "crc->compute(0xB0)[ "<< crc <<"]"   << endl;
00313     crc->compute(0xB0);
00314   }
00315 
00316 
00317 
00318   // reset the data for the block
00319   //  bcId_AbsOrg = -1;
00320   bcId_Abs = 0; // max. 48 bits
00321   bcId_Dif = 0;
00322   // the following data is repeated one time for each Dif which has sent data
00323   difId = getData(1);
00324 
00325   difTriggerCounter = getData(4);
00326   informationCounter = getData(4);  // trigger counter version >= 4
00327   globalTriggerCounter = getData(4);
00328 
00329   ui64 bcIdHigh = getData(2);
00330   ui64 bcIdLow = getData(4);
00331   bcId_Abs = (bcIdHigh << 32) + bcIdLow;
00332   //FILE_LOG(logDEBUG) << "bcId_Abs[" << hex << bcId_Abs <<  endl;
00333 
00334   bcId_Dif = getData(3);
00335 
00336   bcId_AbsOrg =  getbcIdAbsOrg(difId, bcId_Abs);
00337   display();
00338 
00339   ui16 lineInfo =  getData(1);
00340   FILE_LOG(logDEBUG)   << " lineInfo[0x" <<hex << lineInfo << "]"  << endl;
00341   ui16 nbLine   = (lineInfo & 0xF0 ) >> 4;
00342   FILE_LOG(logDEBUG)   << " nbline[0x" <<hex << nbLine << "]"  << endl;
00343   ui16 usedLine = lineInfo & 0x0F; //bit 3 (4eme ligne,)  bit 2 (3eme ligne)  bit 1 (2eme ligne)  bit 0 (1ere ligne)
00344   FILE_LOG(logDEBUG)   << " usedLine[0x" <<hex << usedLine << "]"  << endl;
00345   display();
00346 
00347 
00348   if ( temperatureFill )
00349   {
00350     hexTemperatureAsu1 = getData(4);
00351     hexTemperatureAsu2 = getData(4);
00352     hexTemperatureDif = getData(1) & 0xFF;
00353 
00354     
00355 /*
00356   Pour les temperature des ASU
00357 1) j'enleve les 16 bits de poids fort (bit31 a bit16). Le bit 15 signifie alors le bit de signe
00358     C'est a dire qu'il faut que tu mette(bit15 à bit0) dans un integer signé à 16 bits.
00359 
00360 2) il faut supprimer les 3  bits de poids faible (bit2 à bit0). moi, je l'ai fait par une division entiere par 8 (pour garder le signe). Autrement, si tu préfères, tu pourrais faire une décalage de 3 bits des (bits14 à bits0)
00361 
00362 3) il faut diviser le chiffre restant par 16 pour avoir le résultat en degré Celsius.
00363 Cyril.
00364 */
00365     i16 hex16tempAsu1 = hexTemperatureAsu1 & 0xFFFF; 
00366     float tempAsu1 = (float) ((hex16tempAsu1 / 16 ) / 8 );
00367 
00368     i16 hex16tempAsu2 = hexTemperatureAsu2 & 0xFFFF; 
00369     float tempAsu2 = (float) ((hex16tempAsu2 / 16 ) / 8 );
00370 
00371 /* 
00372 Pour la temperature de la Dif
00373 Vlsb est une constante = 20
00374 (ca veut dire qu'un lsb de l'adc de la DIF vaut 20mV)
00375 
00376 Nadc = les 8 bits que tu recois
00377 
00378 Temperature = la conversion en degré Celsius
00379 ================================================
00380 
00381 float V_adc ;
00382 float  V_lm20 ;
00383 
00384 conversion ADC 
00385 V_adc = ( Nadc * Vlsb ) ;
00386 
00387 ampli gain 33K/10K avec point milieu à 1,5V 
00388 V_lm20 = ( (6450 - V_adc) / 3.3 ) ;
00389 
00390 calcul du premier ordre du lm20 pour T entre -30°C et 100°C 
00391 Temperature = (  (V_lm20 - 1860.5) / (-11.77)  ) ;
00392 */
00393     float Vlsb = 20.0;
00394     float V_adc = hexTemperatureDif * Vlsb;
00395     float V_lm20 = ( (6450. - V_adc) / 3.3 ) ;
00396     float tempDif = (V_lm20 - 1860.5) / (-11.77);
00397 
00398 /*
00399     if ( tempDif != 0. )
00400     {
00401       cout << "hexTemperatureDif [0x" << hex << hexTemperatureDif << "]"  << endl;
00402       cout << "Vlsb [" <<  dec <<Vlsb << "]"  << endl;
00403       cout << "V_adc [" <<  dec <<V_adc << "]"  << endl;
00404       cout << "V_lm20 [" <<  dec <<V_lm20 << "]"  << endl;
00405       cout << "tempDif [" <<  dec <<tempDif << "]"  << endl;
00406     }
00407 */
00408     
00409     event.setTemperature(difId, tempAsu1,    tempAsu2 , tempDif);
00410     
00411   }
00412 
00413  // the bcTime in milliseconds
00414   i64 bcTime = ((bcId_Abs - bcId_AbsOrg) * bcPeriod) / 1000;
00415   // the reading time in milliseconds
00416   i64 readTime = globalTime + bcTime;
00417 
00418   FILE_LOG(logDEBUG)   << "  START EVENT ------------- time " << readTime << " ms" << endl;
00419   FILE_LOG(logDEBUG)   << "    bc time               " << bcTime << " ms" << endl;
00420   FILE_LOG(logDEBUG)   << "    DIF Id                0x" << hex << (int)difId << dec << endl;
00421   FILE_LOG(logDEBUG)   << "    DIF trigger counter   " << difTriggerCounter << endl;
00422   FILE_LOG(logDEBUG)   << "    Information counter   " << informationCounter << endl;
00423   FILE_LOG(logDEBUG)   << "    total trigger counter " << globalTriggerCounter << endl;
00424   FILE_LOG(logDEBUG)   << "    absolute bcId         " << bcId_Abs - bcId_AbsOrg << endl;
00425   FILE_LOG(logDEBUG)   << "    nb line          " << dec <<nbLine << endl;
00426   FILE_LOG(logDEBUG)   << "    used line        " << hex << usedLine << dec <<endl;
00427   event.setDifTriggerCounter(difTriggerCounter);
00428   event.setGlobalTriggerCounter(globalTriggerCounter);
00429 
00430 
00431   Detector &detector = run.getDetector();
00432 
00433   // end of global header
00434 
00435  bool difFound = false;
00436   { const ChamberMap_t &chambers = detector.getChambers();
00437     for (ChamberMap_t::const_iterator it = chambers.begin(); it != chambers.end(); ++it) {
00438       try {
00439         Chamber& chamber = *(it->second);
00440         const BoardMap_t& boards = chamber.getBoardsByDifId(difId);
00441       }
00442       catch (...) {
00443         // any error case - try next chamber
00444         continue;
00445       }
00446 
00447       // the DIF has been found in a chamber. Process all data and continue
00448       difFound = true;
00449       break;
00450     } // for
00451     if (detector.getMonitoringId() == difId)
00452     {
00453        difFound = true;
00454     }
00455     if (!difFound) {
00456       FILE_LOG(logERROR) << "    No dif found with Id 0x" << hex << difId << ", " << dec << difId << "                                     " <<endl;
00457       event.setValidFlag(UNKNOW_NOT_VALID);
00458 
00459     }
00460   }
00461 
00462   for (bool finish = false; !finish; ) {
00463     int delimiter = 0;
00464 
00465     display();
00466     for (; delimiter != 0xA0 && delimiter != 0xB4 && delimiter != 0xC4; ) {
00467       // seek for first data frame header (0xB4)
00468       delimiter = getData(1);
00469       if (fileError == EOF) {
00470         delimiter = 0;
00471         break;
00472       }
00473       if (delimiter == 0xA3)
00474       {
00475         FILE_LOG(logERROR) << "    frame trailer A3 found -- should not" << endl;
00476         event.setValidFlag(UNKNOW_NOT_VALID);
00477       }
00478     }
00479     if (delimiter == 0x00) {
00480       FILE_LOG(logERROR) << "  end of file -- should not" << endl;
00481       event.setValidFlag(UNKNOW_NOT_VALID);
00482       break;
00483     }
00484     if (delimiter == 0xA0) 
00485     {
00486       FILE_LOG(logDEBUG) << "    frame trailer A0 found" << endl;
00487       this->setComputeCrcFlag(false);
00488       unsigned short CRC_check = getData(2);
00489       FILE_LOG(logDEBUG) << hex << " Compute CRC[" << crc->getCrc() << "]" <<  endl;
00490       FILE_LOG(logDEBUG) << hex << " Received CRC[" << CRC_check << "]" <<  endl;
00491       if ( CRC_check != crc->getCrc() )
00492       {
00493         FILE_LOG(logERROR)  << " CRC Error for event id " <<  lastEventId 
00494                             <<  " Compute CRC[" << crc->getCrc() 
00495                             << "] Received CRC[" << CRC_check << "]" <<  endl ;
00496         event.setCrcIsCorrect(false);
00497         event.setValidFlag(CRC_ERROR);
00498       }
00499       display(-1);
00500       FILE_LOG(logDEBUG) << " global trailer A0 found" << endl;
00501       break;
00502     }
00503     if (delimiter == 0xC4) 
00504     {
00505       //computeCrc = false;
00506       Dif& dif = run.getDetector().getDifById(difId);
00507       analogDataActivate = true;
00508       ui16 lineNum = 1;
00509       ui16 nbChipByBoard = dif.getBoards().begin()->second->getNbColumns();
00510       ui16 nbBoard =  dif.getBoards().size();
00511       FILE_LOG(logDEBUG) << "nbBoard[" << nbBoard << "]" <<endl;
00512       FILE_LOG(logDEBUG) << "nbChipByBoard[" << nbChipByBoard << "]" <<endl;
00513 
00514       for ( ui16 iLine = 0 ; iLine < nbLine ; iLine++)
00515       {
00516         if ( usedLine & lineNum ) // LINE 1
00517         {
00518           ui16 nbChips = getData(1);
00519           FILE_LOG(logDEBUG)  << endl << " Line " << lineNum << " nb Chip[" << dec <<  nbChips << "]"  << endl;
00520 
00521           for ( i32 col = nbBoard * nbChipByBoard -1  ; col >= 0; col--)
00522           {
00523             ui16 board = col/nbChipByBoard;
00524             FILE_LOG(logDEBUG)<< dec << "board [" << board << "] line[" << lineNum-1 << "] col[" <<  col << "]" << endl; 
00525             Chip& chip = dif.getChipByRowCol(board, lineNum-1,col % 6);   // board / row /column
00526             if( chip.getBypassed() == false )
00527             {
00528 
00529               FILE_LOG(logDEBUG)<< dec << "chip Id[" << chip.getId() << "]" << endl;
00530               map<ui16,ui16> channelsValues;
00531               for ( ui16 iChannel = 0 ; iChannel < 64 ; iChannel++)
00532               {
00533                 ui16 foo = getData(2);
00534                 channelsValues[iChannel] = foo; 
00535                 FILE_LOG(logDEBUG) << "difId["<< dif.getId() << "] ,chipId["<< chip.getId() <<"] analogData line["<< line <<
00536                                       "], col number["<< col << "] , channel[" << iChannel << "= " << hex <<foo << "]" << dec << endl;
00537               } // end for iChannel
00538               this->analogData[chip.getId()] = channelsValues;
00539             }
00540           } // end for iChip
00541         } // end if usedLine
00542         lineNum++;
00543       } // end for iLine
00544      //computeCrc = true;
00545     }
00546     if ( forceAnalog )
00547     {
00548       for ( map<ui16,map<ui16,ui16> >::iterator iterAnal = analogData.begin(); iterAnal!= analogData.end(); iterAnal++)
00549       {
00550         map<ui16,ui16>& byChip = iterAnal->second;
00551         ui16 chipId = iterAnal->first;
00552         // When analog is anable, all channel of all chip enable for analogic respond
00553         for ( std::map<ui16,ui16>::iterator iterChip = byChip.begin(); iterChip != byChip.end();iterChip++)
00554         {
00555           ui16 analogValue =  iterChip->second;
00556           ui16 channelId = iterChip->first;
00557           if ( difList == NULL || difList->find(difId) != difList->end()  ) // No difid filter or difId in difList
00558           {
00559             nbHits += newHit(event, detector, 0, analogValue,channelId , chipId, difId);
00560             nbanalogHit++;
00561           }
00562         }
00563       }
00564     }
00565 
00566     if (delimiter == 0xB4) 
00567     {
00568       display(+1);
00569       FILE_LOG(logDEBUG) << "   frame header B4 found" << endl;
00570 
00571 
00572 
00573       int chipId = -1;
00574       ui16 orderInChipMemory = 0;
00575       for (; ; )  // Read in chip memory for different BCId_HIT. 
00576       {
00577         chipId = getData(1);
00578        // FILE_LOG(logDEBUG) << "8 bits read[" << chipId << "] [0x"  << hex << chipId << "]" << dec << endl;
00579 
00580         if (fileError == EOF) {
00581           finish = true;
00582           FILE_LOG(logINFO) << "    end of file found -- should not" << endl;
00583           break;
00584         }
00585         if (chipId == 0x00) {
00586           // dummy null bytes
00587           continue;
00588         }
00589     else if (chipId == 0xA3) {
00590           display(-1);
00591           FILE_LOG(logDEBUG) << "   frame trailer A3 found" << endl;
00592           break;
00593         }
00594         else if (chipId == 0xA0) {
00595           finish = true;
00596           display(-1);
00597           break;
00598         }
00599         else if (chipId == 0xC3) {
00600           display(-1);
00601           FILE_LOG(logERROR) << "    frame trailer C3 found - error occured during data transfer" << endl;
00602           event.setValidFlag(UNKNOW_NOT_VALID);
00603           break;
00604         }
00605 
00606         // bcId from hardroc chip is counted as Gray code
00607         bcId_Hit = grayToBinary(getData(3));
00608         FILE_LOG(logDEBUG) << dec << "bcId_Hit[" << bcId_Hit << "]" << endl;
00609         // event time in milliseconds
00610         eventTime = readTime + (((bcId_Dif - bcId_Hit) * bcPeriod) / 1000);
00611 
00612         orderInChipMemory++;
00613         // not on first line and bcId OK : get and check data
00614         if (difFound)
00615         {
00616           for (int chNum = 48; chNum >= 0; chNum -= 16)  // read data ( 128) for different channel Id with same BCID_HIT
00617           {
00618             unsigned int data4 = getData(4); // lit 4 bytes => 8 char => 16 canaux
00619             for (int index = 0; index < 16; index++)
00620             {
00621                 // sur les 16 canaux, recupere les donnees canal par canal
00622               int trigger = (data4 >> ((15 - index) * 2)) & 0x03; // 2 bits
00623               // store new event data if any
00624               if (trigger)  // on elimine tous les hits dans la valeur est 0 
00625               {
00626                 if ( difList == NULL || difList->find(difId) != difList->end()  ) // No difid filter or difId in difList
00627                 { 
00628                    if ( analogDataActivate && orderInChipMemory == 1 )
00629                    {
00630                     i16 analogValue = analogData[chipId][index + chNum];
00631                     nbHits += newHit(event, detector, trigger, analogValue, index + chNum, chipId, difId,orderInChipMemory);
00632                    }
00633                    else
00634                    {
00635                     nbHits += newHit(event, detector, trigger, 0, index + chNum, chipId, difId,orderInChipMemory);
00636                    }
00637                 }
00638 
00639                   //digital[index+chNum]=trigger;
00640             //      FILE_LOG(logDEBUG) << "digital chipId[" << chipId << "] channelNum["<< index+chNum <<"]= " << trigger << endl;
00641               }
00642             } // for (index)
00643           } // End digital data. for (chNum)
00644         }
00645       display();
00646       } // for(;;)
00647     }  // end if delimiter = 0xB4
00648   } // for (;;)
00649   display(-1);
00650 
00651  // CREATE EVENT for current Run
00652 
00653   event.setTimeStamp(globalTime + ((bcId_AbsOrg /1000000 * bcPeriod) )  );  // globalTime -> millisecond and bcId_AbsOrg * bcPeriod -> nano second
00654   FILE_LOG(logDEBUG) << "Dif[" << dec << difId << "]  Number of created hit for event  EVENT " << lastEventId << ", " << nbHits << " total hits, within " << nbanalogHit << " analogic hits" << endl;
00655 
00656 
00657 
00658   if (SkippedBcId) {
00659     FILE_LOG(logWARNING) << "    skipped " << SkippedBcId << " data because of bad bcId" << endl;
00660     SkippedBcId = 0;
00661   }
00662 
00663   return(nbHits);
00664 
00665 
00666 }
00667 
00668 //------------------------------------------//
00669 int MicrorocXDaqReader::getAnalogData(Event& event) 
00670 {
00671 return 0;
00672 }
00673 
00674 //------------------------------------------//
00675 unsigned int MicrorocXDaqReader::getData(const unsigned int nBytes)
00676 {
00677 unsigned int result = 0;
00678 
00679   fileError = 0;
00680   for (unsigned int byte = 0; byte < nBytes; ++byte) 
00681   {
00682     unsigned int data = *itRawdata;
00683     itRawdata++;
00684     if ( computeCrc ) 
00685     {
00686      // if  ( data != 0xc4 && data != 0xd4 )
00687       {
00688         crc->compute(data) ;
00689       }
00690     }
00691     result = (result << 8) + data;
00692   }
00693 
00694 putData(result, nBytes);
00695 
00696 return result;
00697 }
00698 
00699 //------------------------------------------//
00700 /*
00701 void MicrorocXDaqReader::display(const int inc) {
00702   line++;
00703   if (inc < 0) {
00704     level += inc;
00705     if (level < 0) level = 0;
00706   }
00707     FILE_LOG(logDEBUG) << setfill(' ') << setw(level * 2) << "display[" << hex << (unsigned int)( *itRawdata )<< "]" << endl;
00708 
00709   if (inc > 0)
00710     level += inc;
00711 } // DifReader.display
00712 */
00713 

Generated on Mon Jun 11 16:55:46 2012 for MicromegasFramework by  doxygen 1.4.7