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

Go to the documentation of this file.
00001 /* @version $Revision: 1328 $ * @modifiedby $Author: jacquem $ * @lastmodified $Date: 2011-10-03 17:04:17 +0200 (Mon, 03 Oct 2011) $ */
00002 
00003 ////////////////////////////////////////////////////////////////////////
00004 // MICROMEGAS
00005 //
00006 //       EVENT RECONSTRUCTION SOFTWARE FOR DIF Synchro
00007 //
00008 ////////////////////////////////////////////////////////////////////////
00009 ////////////////////////////////////////////////////////////////////////
00010 
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <errno.h>
00014 
00015 #include "parser/DifSynchroReader.hh"
00016 
00017 #include "event/Event.hh"
00018 
00019 #include "geometry/Chamber.hh"
00020 #include "geometry/Dif.hh"
00021 #include "geometry/Hardroc2Chip.hh"
00022 #include "geometry/Detector.hh"
00023 
00024 #include "tools/Toolbox.hh"
00025 #include "tools/SteerDesc.hh"
00026 #include "tools/Log.hh"
00027 #include "tools/MicroException.hh"
00028 #include "parser/AcquisitionParser.hh"
00029 
00030 #include <iostream>
00031 #include <iomanip>
00032 
00033 using namespace std;
00034 
00035 
00036 
00037 /*
00038 Pour les données des SLAB du M2: pas de changement:
00039 - même numéro de format (10)
00040 - numero de version du soft d'acquistion mise a jour (4.0)
00041 
00042 Pour les données de la DIF synchro:
00043 - entete raccourci par rapport a l'entete des donnée d'un SLAB
00044     - data format (10)   = idem fichier SLAB
00045     - daq version (4)     = idem fichier SLAB
00046     - daq sous-version (0) = idem fichier SLAB
00047     - CC firmware version = idem fichier SLAB
00048     - Slow-control Header (B1) = idem fichier SLAB
00049     - DIF ID = idem fichier SLAB
00050     - DIF firmware version = idem fichier SLAB
00051     - c'est tout pour le slow-control = changement par rapport au fichier SLAB
00052     - Slow-control Trealer (A1) = idem fichier SLAB
00053 - donnée de la DIF_Synchro mots de 32 bits (compteur)
00054 */
00055 
00056 
00057 ////////////////////////////////////////////////////////////////////////
00058 DifSynchroReader::DifSynchroReader(Run& aRun, FILE *aFile, ui32 lastEventId) : Hardroc2Reader(aRun, aFile, lastEventId)
00059 {
00060   FILE_LOG(logDEBUG1) << "--DifSynchroReader constructor()"<< endl;
00061   scFound = false;
00062   reset();
00063 }
00064 
00065 //--------------- Destructeur -------------//
00066 DifSynchroReader::~DifSynchroReader()
00067 {
00068   FILE_LOG(logDEBUG1)<< "----DifSynchroReader destructor"<< endl;
00069 }
00070 
00071 //-------------------------------------------------------------------
00072 // read slow control data
00073 // Les 872 bits du slow control sont inverses dans le fihier de donnee.
00074 //1er  octet lu -> bit 872 871 870 869 868 867 866 865
00075 //2eme octet lu -> bit 864 863 862 861 860 859 858 857
00076 
00077 int DifSynchroReader::getScData() {
00078      unsigned int data;
00079      display(+1);
00080      FILE_LOG(logDEBUG) << " Slow Control data header B1 found" << endl;
00081 
00082      ui16 dataFormat = run.getDataFormat();
00083      bool findA1 = false;
00084      difId = getData(1);
00085      display(+1);
00086      FILE_LOG(logDEBUG) << "--- difId[" << difId << "] config ---" << endl;
00087  
00088           Dif& dif = run.getDetector().getDifById(difId);
00089           dif.setDifFirmware(getData(2));
00090           display(+1);
00091           FILE_LOG(logINFO) << "-------- difFirmware[0x" << hex << dif.getDifFirmware() << "]" << endl;
00092 
00093    // Verify A1 Header
00094         unsigned char *buf = initGetBits(1, false);
00095     if ( !buf)
00096     {
00097         FILE_LOG(logERROR) << "  malloc error while getting SC buffer" << endl;
00098         exit ( -1);
00099     }
00100 
00101       int foo = getBits(8);
00102       finishGetBits();
00103 
00104       FILE_LOG(logDEBUG) << "Hreader[" << hex << foo <<"]" << endl;
00105       if ( foo != 0xa1)
00106       {
00107           FILE_LOG(logERROR) << "  Header A1 not found" << endl;
00108           exit (-1);
00109       }
00110       FILE_LOG(logDEBUG1) << "Header A1 found" << endl;
00111 
00112     return(1);
00113 } // DifSynchroReader.getScData
00114 
00115 //-------------------------------------------------------------------
00116 // read acq  data
00117 int DifSynchroReader::getAcqData(Event& event) {
00118 
00119         bool eventFound = false;
00120 
00121         
00122         while ( ! eventFound  &&  fileError != EOF )
00123         {
00124         i32     foo = getData(4);
00125                 FILE_LOG(logDEBUG) << hex << "foo[" << foo << "]"  << endl;
00126 
00127                 if ( foo == 0xfffffffa )
00128                 {
00129                         // Header Run number (  synchromizsed with previous Run ) 
00130                         i32 runNumber = getData(4); 
00131                         FILE_LOG(logINFO) << "Run number[" << runNumber << "]"  << endl;
00132                         foo = getData(4);
00133                         if ( foo != 0xfffffffb )
00134                         {
00135                                 FILE_LOG(logERROR) << " Trailer Run numbers  (  synchromizsed with previous Run ) not FOUND !" << endl;
00136                                 exit(-1);
00137                         }
00138                         else FILE_LOG(logDEBUG) << " Trailer Run numbers[0x" << hex << foo <<"]" << endl;
00139                 }
00140                 else if ( foo == 0xfffffff0 )
00141                 {
00142                         // Header Run number (  DEsynchromizsed with previous Run ) 
00143                         i32 runNumber = getData(4); 
00144                         FILE_LOG(logINFO) << "Run number[" << runNumber << "]"  << endl;
00145                         foo = getData(4);
00146                         if ( foo != 0xfffffff1 )
00147                         {
00148                                 FILE_LOG(logERROR) << " Trailer Run numbers  (  DEsynchromizsed with previous Run ) not FOUND !" << endl;
00149                                 exit(-1);
00150                         }
00151                         else FILE_LOG(logDEBUG) << hex << " Trailer Run numbers[0x" << foo <<"]" << endl;
00152                 }
00153         
00154                 else if ( foo == 0xffffffff )
00155                 {
00156                         FILE_LOG(logINFO) << "COMMAND MODE : end of data buffer flags"  << endl;
00157                         // end of data buffer flags
00158                 }
00159         
00160                 else  // it 's an event 
00161                 {
00162                         event.setDifSyncrho(foo);
00163                         FILE_LOG(logDEBUG) << "Dif Synchro[0x"<<  hex <<  foo << " ]"  << endl;
00164                         event.setId(++lastEventId);
00165                         eventFound = true;
00166                 }
00167         }
00168         return 0;
00169 /*
00170 unsigned int nbHits = 0;
00171     i32 foo = getData(4);
00172   
00173  
00174         FILE_LOG(logINFO)  << hex<< "foo [" << foo << "]"  << endl;
00175         if ( foo == 0xfffffffa )
00176         {
00177                 // Header Run number (  synchromizsed with previous Run ) 
00178                 i32 runNumber = getData(4); 
00179                 FILE_LOG(logINFO) << "Run number[" << runNumber << "]"  << endl;
00180                 foo = getData(4);
00181                 if ( foo == 0xfffffffb )
00182                 {
00183                         // Trailer Run numbers  (  synchromizsed with previous Run )
00184                         foo = getData(4);
00185                 }
00186                 else
00187                 {
00188                         FILE_LOG(logERROR) << " Trailer Run numbers  (  synchromizsed with previous Run ) not FOUND !" << endl;
00189                         exit(-1);
00190                 }
00191         }
00192         else if ( foo == 0xfffffff0 )
00193         {
00194                 // Header Run number (  DEsynchromizsed with previous Run ) 
00195                 i32 runNumber = getData(4); 
00196                 FILE_LOG(logINFO) << "Run number[" << runNumber << "]"  << endl;
00197                 foo = getData(4);
00198                 if ( foo == 0xfffffff1 )
00199                 {
00200                         // Trailer Run numbers  (  DEsynchromizsed with previous Run )
00201                         exit(-1);
00202                 }
00203                 else
00204                 {
00205                         FILE_LOG(logERROR) << " Trailer Run numbers  (  DEsynchromizsed with previous Run ) not FOUND !" << endl;
00206                         exit(-1);
00207                 }
00208         }
00209 
00210         else if ( foo == 0xffffffff )
00211         {
00212                 FILE_LOG(logINFO) << "COMMAND MODE : end of data buffer flags"  << endl;
00213                 foo = getData(4);
00214                 // end of data buffer flags
00215         }
00216 
00217         event.setDifSyncrho(foo);
00218         FILE_LOG(logINFO) << "Dif Synchro[0x"<<  hex <<  foo << " ]"  << endl;
00219         event.setId(++lastEventId);
00220         return 32;
00221 
00222 */
00223 } // DifSynchroReader.getAcqData
00224 
00225 //-------------------------------------------------------------------
00226 // LOOP over the data Files, returns after each event
00227 //      called for every dif found in the data file.
00228 int DifSynchroReader::getNextEvent(Event& event) {
00229   // Start data reconstruction
00230   Level(0);
00231 
00232         ui16 dataFormat = run.getDataFormat();
00233 
00234   if (dataFormat == 0) {
00235     // first read of the file
00236     bcIdDifAbsOrgMap.clear();
00237     // read file header
00238     dataFormat = getData(1);
00239     if ( dataFormat == 0x10  ) { dataFormat = 0xa; }
00240                 run.setDataFormat(dataFormat);
00241 
00242 
00243     if (fileError == EOF) {
00244       FILE_LOG(logERROR) << "parsing file[" << inputFile << "]  - error " << errno << ":" << strerror(errno) << endl;
00245       reset();
00246       return(LAST_FILE_EVENT);
00247     }
00248     display(+1);
00249     FILE_LOG(logINFO) << "  DIF SYNCHRO LABVIEW DATA FORMAT  : " << dataFormat << endl;
00250 
00251     if (dataFormat != 7 && dataFormat != 1 && dataFormat != 10) {
00252       // unknown format
00253       FILE_LOG(logERROR) << " DIF SYNCHRO LABVIEW data format  " << dataFormat << " is not implemented" << endl;
00254       reset();
00255       return(LAST_FILE_EVENT);
00256     }
00257 
00258         if ( dataFormat == 10)
00259         {
00260                 run.setDaqSoftware( getData(1));
00261                 display(+1);
00262                 FILE_LOG(logINFO) << "  DAQ software version  : " << run.getDaqSoftware() << endl;
00263 
00264                 run.setCccFirmware(getData(1));
00265                 display(+1);
00266         FILE_LOG(logINFO) << "  ccc firware  : " << run.getCccFirmware() << endl;
00267 
00268                 globalTime = getData(4)    ; // labview time is second since 1 janv 1970 and globalTime milli second
00269         FILE_LOG(logDEBUG1) << "globalTime in second:[" << globalTime << "]" <<  endl;
00270         globalTime *= 1000;
00271         FILE_LOG(logDEBUG1) << "globalTime in millisecond:[" << globalTime << "]" <<  endl;
00272         FILE_LOG(logDEBUG) << "  Global timestamp(hex) [" << hex << globalTime << "]" << endl;
00273 
00274         }
00275 
00276 
00277    if (fileError == EOF) 
00278    {
00279      FILE_LOG(logDEBUG) << "  END OF DATA FILE" << endl;
00280      reset();
00281      return(LAST_FILE_EVENT);
00282    }
00283    FILE_LOG(logDEBUG) << run.getDetector() << endl;
00284    display(-1);
00285    return NEW_CONFIG;
00286   }
00287 
00288 
00289   if ( !scFound ) // slow control has nott been readed yet
00290   {
00291 
00292     // look for a global data header and process corresponding data
00293     unsigned int globalHeader = getData(1);
00294     if (fileError == EOF) 
00295     {
00296         FILE_LOG(logDEBUG) << "  END OF DATA FILE" << endl;
00297         reset();
00298         return(LAST_FILE_EVENT);
00299     }
00300     FILE_LOG(logDEBUG) << "globalHeader:["<< hex  << globalHeader << "]" << endl;
00301     if (globalHeader == 0xB1) 
00302     {
00303       // slow control data
00304       getScData();
00305           scFound = true;
00306         }
00307   }
00308 
00309   if (fileError == EOF) 
00310   {
00311       FILE_LOG(logINFO) << "  END OF DATA FILE" << endl;
00312       reset();
00313       return(LAST_FILE_EVENT);
00314   }
00315 
00316   getAcqData(event);
00317 
00318   if ( fileError == EOF)
00319   {
00320        FILE_LOG(logINFO) << "  END OF DATA FILE" << endl;
00321        reset();
00322        return(LAST_FILE_EVENT);
00323   }
00324 
00325   return EVENT_CORRECT;
00326 }

Generated on Mon Jan 7 13:15:22 2013 for MicromegasFramework by  doxygen 1.4.7