CalibHR1Parser Class Reference

#include <CalibHR1Parser.hh>

Inheritance diagram for CalibHR1Parser:

Inheritance graph
[legend]
Collaboration diagram for CalibHR1Parser:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CalibHR1Parser (Run &aRun, FILE *aFile, ui32 firstEventId)
virtual ~CalibHR1Parser ()
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]

Detailed Description

CLASS DATAREADER //

Definition at line 27 of file CalibHR1Parser.hh.


Constructor & Destructor Documentation

CalibHR1Parser::CalibHR1Parser ( Run aRun,
FILE *  aFile,
ui32  firstEventId 
)

Definition at line 52 of file CalibHR1Parser.cpp.

00053 : AcquisitionParser(aRun, aFile,_firstEventId)
00054 {
00055   FILE_LOG(logDEBUG1) << "--CalibHR1Parser constructor()"<< endl;
00056 
00057   run.setCalibrationRun(true);
00058 
00059   reset();
00060 }

CalibHR1Parser::~CalibHR1Parser (  )  [virtual]

Definition at line 63 of file CalibHR1Parser.cpp.

00064 {
00065   FILE_LOG(logDEBUG1)<< "----CalibHR1Parser destructeur"<< endl;
00066 }


Member Function Documentation

static const char* CalibHR1Parser::type (  )  [inline, static]

Definition at line 33 of file CalibHR1Parser.hh.

Referenced by main().

00033 { return CALIBHR1; } ;

int CalibHR1Parser::getNextEvent ( Event eventToFill  )  [virtual]

Implements AcquisitionParser.

Definition at line 182 of file CalibHR1Parser.cpp.

00183 {
00184     unsigned int nbHits = 0;
00185     // The first line does not contains needed informations
00186     // init fill the motifCtest and place streaming just before the first event
00187     if ( ! init)
00188     {
00189         initParsing(inputFile);
00190         init = true;
00191     }
00192 
00193     string line;
00194 
00195     if ( newCalibration)
00196     { // get calibration parameters ( DAC_2, DAC_1, D AC_0 values )
00197         FILE_LOG(logDEBUG1) <<  "New calibration !" << endl;
00198         size_t found;
00199 
00200         FILE_LOG(logDEBUG1) <<  "---------> DEBUG A" << endl;
00201         do
00202         {
00203            int result = getLine ( inputFile, line);
00204            if (result == EOF)
00205            {
00206                reset();
00207                return LAST_FILE_EVENT;
00208            }
00209 
00210            // Get DAC_2
00211            found=line.find("DAC_1");
00212         }
00213         while (found==string::npos);
00214 
00215         dac[0] = -1;
00216         dac[1] = getDacValue(line);
00217 
00218         // Get DAC_0
00219         if ( getLine ( inputFile, line) != EOF )
00220         {
00221             if ( line.find("DAC_0")!=string::npos) { dac[0] = getDacValue(line); }
00222             else { return EVENT_ERROR;  }  // DAC_1 value not found
00223         }
00224 
00225 
00226         // Set chip configuration
00227         run.setName("turlututu");
00228         const Detector &detector = run.getDetector();
00229         try {
00230           ChamberMap_t chambers = detector.getChambers();
00231           for (ChamberMap_t::iterator chamberIt = chambers.begin(); chamberIt != chambers.end(); chamberIt++) {
00232             Chamber& chamber = *chamberIt->second;
00233             DifMap_t difs = chamber.getDifs();
00234             for (DifMap_t::iterator difIt = difs.begin(); difIt != difs.end(); difIt++) {
00235               Dif& dif = *difIt->second;
00236               BoardMap_t boards = dif.getBoards();
00237               for (BoardMap_t::iterator boardIt = boards.begin(); boardIt != boards.end(); boardIt++) {
00238                 Board& b = *boardIt->second;
00239                 ChipMap_t chips = b.getChips();
00240                 for (ChipMap_t::iterator chipIt = chips.begin(); chipIt != chips.end(); chipIt++) {
00241 //                  Chip& chip = *chipIt->second;
00242                   Hardroc1Chip &chip = dynamic_cast<Hardroc1Chip &> (*chipIt->second);
00243                   chip.setThresholdDac_0(dac[0]);
00244                   chip.setThresholdDac_1(dac[1]);
00245                   for (int chNum = 0; chNum < 64; chNum++) {
00246                     Channel& ch = chip.getChannelById(chNum);
00247                     ch.setEnable(1);
00248                   }
00249                 }
00250               }
00251             }
00252           }
00253         }
00254         catch (MicroException &e) { cout << e.getMessage() << endl; }
00255 
00256         newCalibration = false; // nany event could be attach to these calibration parametre ( DAC_2 ... )
00257         return NEW_CONFIG;
00258      } // end if new calibratio
00259    if ( newDif)
00260    {
00261           FILE_LOG(logDEBUG1) <<  "New Dif !" << endl;
00262         // Place file streamer after B4
00263         int space = 0;  // nb bytes beetween B4 and B0 tags
00264         int b0Pos = 6;  // B0 tag position
00265         bool find = false;
00266         do
00267         {
00268            b0Pos = ftell(inputFile);
00269            if (getLine ( inputFile, line) == EOF) {
00270              return(LAST_FILE_EVENT);
00271            }
00272 //           FILE_LOG(logINFO) << "line[" << line << "]" << endl;
00273            // 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 )
00274            if (checkNextLine(inputFile,"DAC_") )
00275            {
00276                newCalibration = true;
00277                FILE_LOG(logWARNING) <<  "No data for DAC values:[" << dac[0] << "," << dac[1] << "," << dac[2] << "]" << endl;
00278                return getNextEvent( event);
00279            }
00280 
00281            int b0find = line.find("B0");
00282            int b4pos = 0;
00283            do
00284            {
00285                b4pos = line.find("B4",b4pos+1);
00286 
00287                if ( b4pos - b0find == 46 )
00288                {
00289                    find = true;
00290                }
00291            }
00292            while  (b4pos != string::npos && find == false );
00293 
00294         }
00295         while ( !find );
00296 
00297         b0Pos = b0Pos + 18 + 2 ;  // position du B0
00298         fseek(inputFile, b0Pos, SEEK_SET);
00299 
00300         // File after position "B0"
00301         // Here we are sure to be at the correct position in the file to start
00302 
00303        // New DIF
00304        difId = getData(inputFile, 1);
00305        FILE_LOG(logDEBUG1) << "  difId[" << difId << "]" <<  endl;
00306 
00307        fseek(inputFile, 42, SEEK_CUR);
00308        // Fichier avant la position "B4"
00309        // New B4 Tag
00310 
00311        int dataHeader = getData(inputFile, 1);
00312        FILE_LOG(logDEBUG1) << (hex) << "  dataHeader[" << dataHeader << "]" <<  endl;
00313        if (dataHeader == 0xB4)
00314        {
00315            FILE_LOG(logDEBUG1) << "  data header B4 found" << endl;
00316        }
00317        else
00318        {
00319            FILE_LOG(logERROR) << "  parsing file error. data header error : " << hex << dataHeader << dec << endl;
00320            return EVENT_ERROR;
00321        }
00322 
00323        newDif = false;
00324 
00325 
00326     }
00327     if ( newHR)
00328     {
00329           FILE_LOG(logDEBUG1) <<  "New HR !" << endl;
00330        // VERIF TAG A3 pas de skip. Dans le cas ou aucun des chips ne repond
00331           if ( checkData(inputFile, 1) == 0xA3)
00332           {
00333              FILE_LOG(logERROR) <<  "ERROR TAG A3 just after newHR for DAC values:[" << dac[0] << "," << dac[1] << "," << dac[2] << "]" << endl;
00334              return EVENT_ERROR;
00335           }
00336        // On skip les insultes du hardroc
00337        fseek ( inputFile, 40, SEEK_CUR);
00338        newHR = false;
00339     }
00340 
00341 
00342     // On Verifie en hexadecimal que l'on a pas de tag A0
00343     // Pour une Dif, lit ChipId + BCId + donnee
00344     // get Chip Id. Warning ! Decimal
00345 
00346     int chipId = -1;
00347     // On doit lire 2 fois car le tag A3 est en Hexedecimal alors que le chipId est en decimal
00348     int foo = getData(inputFile , 1);
00349     if ( foo == 0xA3)
00350     { // Fin de donnees chip(HR)
00351         FILE_LOG(logDEBUG1) << " -------- TAG A3 " <<  endl;
00352         newHR = true;
00353         foo = getData(inputFile , 1);
00354         if ( foo == 0xA0 )
00355         {
00356             newDif = true;
00357             FILE_LOG(logDEBUG1) << " -------- Tag A0 derriere A3 " <<  endl;
00358             foo = getData(inputFile , 2 ); // READ CRC
00359             foo = getData(inputFile, 1 );
00360             if ( foo != 0xB0)
00361             {
00362 
00363                 newCalibration = true;
00364                 FILE_LOG(logDEBUG1) << " -------- Pas de B0 derrire le CRC donc newCalibration = true " <<  endl;
00365             }
00366             else {
00367                 FILE_LOG(logDEBUG1) << " -------- B0 derrire le CRC donc Dif  " <<  endl;
00368             }
00369 
00370         }
00371         return getNextEvent( event);
00372     }
00373     else
00374     { // Pas Fin de donnees chip(HR)
00375       fseek ( inputFile, -2, SEEK_CUR);
00376       chipId = getData(inputFile, 1);
00377 
00378     // get bcid
00379     int bcId = getData(inputFile, 3);
00380     FILE_LOG(logDEBUG1) << (hex) << "  bcid[" << bcId << "]" <<  endl;
00381 
00382 
00383     // the following data is repeated one time for each Dif which has sent data
00384 
00385     bool difFound = false;
00386     Detector& detector = run.getDetector();
00387     { const ChamberMap_t &chambers = detector.getChambers();
00388       for (ChamberMap_t::const_iterator it = chambers.begin(); it != chambers.end(); ++it) {
00389         try {
00390           Chamber& chamber = *(it->second);
00391           const BoardMap_t& boards = chamber.getBoardsByDifId(difId);
00392         }
00393         catch (...) {
00394           // any error case - try next chamber
00395           continue;
00396         }
00397 
00398         // the DIF has been found in a chamber. Process all data and continue
00399         difFound = true;
00400         break;
00401       } // for
00402       if (!difFound) {
00403         FILE_LOG(logERROR) << "    No dif found with Id 0x" << hex << difId << dec << endl;
00404         return EVENT_ERROR;
00405       }
00406     }
00407 
00408    // trigger data for 64 channels : 1 bit trigger1, 1 bit trigger0 for each channel from 63 downto 0.
00409         // this makes 2-bit values which should not give bit 1 without bit 0
00410 
00411         int canal[16]={0};
00412         for (int chNum = 48; chNum >= 0; chNum -= 16) {
00413           unsigned int data4 = getData(inputFile, 4); // on lit 4 Bytes => 8 cara => 16 cannaux
00414 
00415           int index = 0;
00416           for ( index = 0; index <= 15 ; index++)
00417           {
00418              // sur les 16 canaux, on recupere les donnees canal par canal
00419              canal[index] = (data4 >> ((15 - index )* 2 )) & 0x03; // 2 Most Significant Bits of the digi
00420 
00421              if ( motif[index+chNum])
00422              {
00423                 newHit(event, detector, canal[index], index + chNum    , chipId, difId);//, dac);
00424                 nbHits++;
00425              }
00426           }
00427       }
00428 
00429       event.setId(++lastEventId);
00430       FILE_LOG(logDEBUG1) << "  STORE EVENT " << lastEventId << ", " << nbHits << " hits" << endl;
00431       return EVENT_CORRECT;
00432     }
00433 
00434 }

unsigned int CalibHR1Parser::getData ( FILE *  inputFile,
const int  nBytes 
) [private]

Definition at line 467 of file CalibHR1Parser.cpp.

Referenced by checkData(), and getNextEvent().

00467                                                                       {
00468   unsigned int result = 0;
00469   for (int byte = 0; byte < nBytes; ++byte) {
00470     int data = 0;
00471     if (fscanf(inputFile, "%2x", &data) != 1) {
00472       return(0);
00473     }
00474     result = (result << 8) + data;
00475   }
00476   return(result);
00477 } 

unsigned int CalibHR1Parser::getDecimalData ( FILE *  inputFile,
const int  nBytes 
) [private]

Definition at line 482 of file CalibHR1Parser.cpp.

00482                                                                              {
00483   unsigned int result = 0;
00484   for (int byte = 0; byte < nBytes; ++byte) {
00485     int data = 0;
00486     if (fscanf(inputFile, "%2d", &data) != 1) {
00487       return(0);
00488     }
00489     result = (result << 8) + data;
00490   }
00491   return(result);
00492 } 

unsigned int CalibHR1Parser::checkData ( FILE *  inputFile,
const int  nBytes 
) [private]

Definition at line 457 of file CalibHR1Parser.cpp.

Referenced by getNextEvent().

00457                                                                         {
00458 
00459     int curPos = ftell(inputFile);
00460     unsigned int result = getData(inputFile, nBytes);
00461     fseek(inputFile,curPos,SEEK_SET);
00462     return result;
00463 }

int CalibHR1Parser::getLine ( FILE *  file,
std::string &  line 
) [private]

Referenced by getNextEvent(), and initParsing().

int CalibHR1Parser::getDacValue ( std::string  line  )  [private]

Referenced by getNextEvent().

void CalibHR1Parser::setMotifValue ( std::string  line  )  [private]

Referenced by initParsing().

void CalibHR1Parser::initParsing ( FILE *  inputFile  )  [private]

Definition at line 133 of file CalibHR1Parser.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("nb acquisitions" );
00144 
00145        line.clear();
00146     }
00147     while  (found==string::npos);
00148 
00149     getLine ( inputFile, line);
00150         // saute la ligne de la date
00151 
00152     // get motifCTest
00153     if ( getLine ( inputFile, line) == EOF ) { return ;}
00154     found = line.find("motif Ctest" );
00155     if  (found!=string::npos)
00156     {
00157       setMotifValue(line);
00158     }
00159 }

unsigned int CalibHR1Parser::grayToBinary ( unsigned int  gray  )  [private]

Reimplemented from AcquisitionParser.

int CalibHR1Parser::newHit ( Event event,
const Detector detector,
int  data,
const int  chNum,
const int  chipId,
const int  difId 
) [private]

Definition at line 497 of file CalibHR1Parser.cpp.

Referenced by getNextEvent().

00498 {
00499   // cannot be binary pattern 10
00500 //  if (data == 0x2) {
00501     //FILE_LOG(logERROR) << "      CHANNEL DATA = 0x02" << endl;
00502 //    return(0);
00503  // }
00504 
00505   const ChamberMap_t &chambers = detector.getChambers();
00506   for (ChamberMap_t::const_iterator it = chambers.begin(); it != chambers.end(); ++it) {
00507     try {
00508       Chamber& chamber = *(it->second);
00509       const BoardMap_t& boards = chamber.getBoardsByDifId(difId);
00510       // look for type of chamber
00511       //if (chamber.getType() != HARDROC1CHAMBER)
00512       //  continue;
00513       // store new event data
00514       try {
00515         const Channel& channel = chamber.getChannelById(chNum, chipId, difId);
00516         i16 analogValue = 0;
00517         //ChannelHit *hit = new ChannelHit(channel, data, analogValue, dac);
00518         ChannelHit *hit = new ChannelHit(channel, data, analogValue);
00519 //        hit->setHardrocTime(globalTime, bcId_Abs, bcId_Dif, bcId_Hit);
00520         event.insertHit(chamber, hit);
00521         FILE_LOG(logDEBUG1) << "      new Hit : ch " << chNum << ", chip " << chipId << ", dif " << difId
00522                            << " Data=" << data << " , x:" << channel.getX() << ", y:" << channel.getY() << endl;
00523         return(1);
00524       }
00525       catch (MicroException &e) {
00526         FILE_LOG(logERROR) << "ch " << chNum << ", chip " << chipId << ", dif " << difId << " : " << e.getMessage() << endl;
00527         return(0);
00528       }
00529     }
00530     catch (...) {
00531       continue;
00532     }
00533 
00534   } // for
00535   return(0);
00536 } 

string CalibHR1Parser::binaire ( unsigned int  nombre  )  [private]

Definition at line 542 of file CalibHR1Parser.cpp.

00543 {
00544 string res = "";
00545 unsigned int val = nombre;
00546 
00547 while (val != 0) {
00548 /* Invariant de boucle : code_binaire(val) + res = code_binaire(nombre) */
00549 
00550    if (val & 1 == 1) {
00551 res = string("1") + res;
00552 }
00553     else {
00554 /* val & 1 == 0 */
00555 res = string("0") + res;
00556 }
00557 
00558 val = val >> 1;
00559 }
00560 return res;
00561 }

void CalibHR1Parser::reset (  )  [private]

Definition at line 70 of file CalibHR1Parser.cpp.

Referenced by CalibHR1Parser(), 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 CalibHR1Parser::checkNextLine ( FILE *  inputFile,
std::string  target 
) [private]

Referenced by getNextEvent().


Member Data Documentation

bool CalibHR1Parser::init [private]

Definition at line 54 of file CalibHR1Parser.hh.

Referenced by getNextEvent(), and reset().

bool CalibHR1Parser::motif[MOTIFNB] [private]

Definition at line 55 of file CalibHR1Parser.hh.

Referenced by getNextEvent().

bool CalibHR1Parser::newCalibration [private]

Definition at line 56 of file CalibHR1Parser.hh.

Referenced by getNextEvent(), and reset().

bool CalibHR1Parser::newDif [private]

Definition at line 57 of file CalibHR1Parser.hh.

Referenced by getNextEvent(), and reset().

bool CalibHR1Parser::newHR [private]

Definition at line 58 of file CalibHR1Parser.hh.

Referenced by getNextEvent(), and reset().

int CalibHR1Parser::difId [private]

Definition at line 59 of file CalibHR1Parser.hh.

Referenced by getNextEvent(), and reset().

int CalibHR1Parser::dac[3] [private]

Definition at line 60 of file CalibHR1Parser.hh.

Referenced by getNextEvent(), and reset().


The documentation for this class was generated from the following files:
Generated on Mon Jan 7 13:18:00 2013 for MicromegasFramework by  doxygen 1.4.7