00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <errno.h>
00013
00014 #include "parser/MicrorocLabviewReader.hh"
00015 #include "parser/AcquisitionParser.hh"
00016
00017 #include "event/Event.hh"
00018
00019 #include "geometry/Chamber.hh"
00020 #include "geometry/Board.hh"
00021 #include "geometry/Dif.hh"
00022 #include "geometry/MicrorocChip.hh"
00023 #include "geometry/Detector.hh"
00024
00025 #include "tools/Toolbox.hh"
00026 #include "tools/SteerDesc.hh"
00027 #include "tools/Log.hh"
00028 #include "tools/MicroException.hh"
00029
00030 #include <iostream>
00031 #include <iomanip>
00032
00033 using namespace std;
00034
00035
00036 MicrorocLabviewReader::MicrorocLabviewReader(Run& aRun, FILE *aFile, ui32 lastEventId,bool _forceAnalog, set<unsigned int>*_difList) : MicrorocMergeReader(aRun, aFile, lastEventId,_forceAnalog,_difList), nbBufferedData(0),bufferedData(0)
00037
00038 {
00039 FILE_LOG(logDEBUG1) << "--MicrorocLabviewReader constructor()"<< endl;
00040 FILE_LOG(logDEBUG) << "cwMixrorocLabview ReaderDifReader Constructeur crc adr[" << crc << "]" << endl;
00041
00042 run.setDataFormat(0);
00043 MicrorocMergeReader::localReset();
00044
00045 }
00046
00047
00048 MicrorocLabviewReader::~MicrorocLabviewReader()
00049 {
00050 FILE_LOG(logDEBUG1)<< "----MicrorocLabviewReader destructor"<< endl;
00051 }
00052
00053
00054
00055
00056
00057
00058
00059 int MicrorocLabviewReader::getNextEvent(Event& event) {
00060
00061 Level(0);
00062
00063 ui16 dataFormat = run.getDataFormat();
00064
00065 if (dataFormat == 0) {
00066
00067 bcIdDifAbsOrgMap.clear();
00068
00069 dataFormat = getData(1);
00070 if ( dataFormat == 0x10 ) { dataFormat = 0xa; }
00071 run.setDataFormat(dataFormat);
00072 if ( run.getDataFormat() != 15 && run.getDataFormat() != 14 )
00073 {
00074 FILE_LOG(logERROR) << "labview data format[" << dec << dataFormat << "] not implemented" << endl;
00075 return(LAST_FILE_EVENT);
00076 }
00077
00078
00079 if (fileError == EOF) {
00080 FILE_LOG(logERROR) << "parsing file[" << inputFile << "] - error " << errno << ":" << strerror(errno) << endl;
00081 reset();
00082 return(LAST_FILE_EVENT);
00083 }
00084 display(+1);
00085 FILE_LOG(logINFO) << " Microroc LABVIEW DATA FORMAT : " << dataFormat << endl;
00086
00087 if ( dataFormat != 15 && run.getDataFormat() != 14 ){
00088
00089 FILE_LOG(logERROR) << " Microroc LABVIEW data format " << dataFormat << " is not implemented" << endl;
00090 reset();
00091 return(LAST_FILE_EVENT);
00092 }
00093
00094 if ( dataFormat == 15 || dataFormat == 14 )
00095 {
00096
00097 run.setDaqSoftware(getData(2) );
00098 display(+1);
00099 FILE_LOG(logINFO) << hex << " DAQ software version : " << run.getDaqSoftware() <<endl;
00100
00101 run.setSDccFirmware(getData(2));
00102 display(+1);
00103 FILE_LOG(logINFO) << hex << " SDcc firware : 0x" << run.getSDccFirmware() << endl;
00104
00105 run.setDifFirmware(getData(2));
00106 display(+1);
00107 FILE_LOG(logINFO) << hex << " Dif firware : 0x" << run.getDifFirmware() << endl;
00108
00109 globalTime = getData(4) ;
00110 FILE_LOG(logDEBUG) << "globalTime in second:[0x" << hex << globalTime << "] decimal[" << dec << globalTime << "]" << endl;
00111 globalTime *= 1000;
00112 FILE_LOG(logDEBUG) << "globalTime in millisecond:[" << globalTime << "]" << endl;
00113
00114 globalTimeMilli = getData(4) ;
00115 FILE_LOG(logDEBUG) << "Plus globalTimeMilli in millisecond:[0x" << hex << globalTimeMilli << "] decimal [" << dec << globalTimeMilli << "]" << endl;
00116 }
00117
00118
00119 if (fileError == EOF) {
00120 FILE_LOG(logDEBUG) << " END OF DATA FILE" << endl;
00121 reset();
00122 return(LAST_FILE_EVENT);
00123 }
00124
00125 display(-1);
00126 return NEW_CONFIG;
00127 }
00128
00129 if ( skipNbEvent != 0 && debugEventId < skipNbEvent)
00130 {
00131 while ( debugEventId < skipNbEvent )
00132 {
00133 unsigned int globalHeader = getSpecificData(1);
00134 if (fileError == EOF) {
00135 FILE_LOG(logDEBUG) << " END OF DATA FILE" << endl;
00136 return(LAST_FILE_EVENT);
00137 }
00138 FILE_LOG(logDEBUG1) << "DEBUG 1 wait for 0xa0[0x " << hex << globalHeader << "]" << endl;
00139 while ( globalHeader != 0xa0 )
00140 {
00141 globalHeader = getSpecificData(1);
00142 FILE_LOG(logDEBUG1) << "wait for 0xa0[0x " << hex << globalHeader << "]" << endl;
00143 if (fileError == EOF) {
00144 FILE_LOG(logDEBUG) << " END OF DATA FILE" << endl;
00145 return(LAST_FILE_EVENT);
00146 }
00147 }
00148
00149 unsigned int crc = getSpecificData(2);
00150 globalHeader = getSpecificData(1);
00151 FILE_LOG(logDEBUG1) << "wait for 0xb0[0x " << hex << globalHeader << "]" << endl;
00152 if ( globalHeader == 0xb0 )
00153 {
00154 FILE_LOG(logINFO) << "skip event " << debugEventId << "\t\t\t\t \r" << flush;
00155
00156 debugEventId++;
00157 }
00158 }
00159
00160 FILE_LOG(logINFO) << debugEventId++ << " event(s) skipped " << endl;
00161 nbBufferedData = 1;
00162 bufferedData = 0xb0;
00163 }
00164
00165
00166
00167 bool eventFound = false;
00168 while (! eventFound)
00169 {
00170 eventFound = MicrorocMergeReader::decodeData(event);
00171 if (fileError == EOF)
00172 {
00173 FILE_LOG(logDEBUG) << " END OF DATA FILE" << endl;
00174 reset();
00175 return(LAST_FILE_EVENT);
00176 }
00177 }
00178
00179 if ( event.getChannelHitSize() > 0 )
00180 {
00181 event.setId(++lastEventId);
00182 return EVENT_CORRECT;
00183 }
00184 else
00185 {
00186 return EVENT_ERROR;
00187 }
00188 }
00189
00190
00191 unsigned int MicrorocLabviewReader::getSpecificData(const unsigned int nBytes)
00192 {
00193 if (nbBufferedData != 0 )
00194 {
00195 if ( nbBufferedData > 1 ) { FILE_LOG(logERROR) << " could only buffed 1 byte" << endl; exit(1); }
00196 nbBufferedData = 0;
00197 return bufferedData;
00198 }
00199
00200 else
00201 {
00202 return DifReader::getData(nBytes);
00203 }
00204 }
00205