00001
00002
00003 #include "parser/DiracLabview.hh"
00004 #include "parser/DifReader.hh"
00005
00006 #include "event/Event.hh"
00007
00008 #include "geometry/Detector.hh"
00009 #include "geometry/Chamber.hh"
00010 #include "geometry/Dif.hh"
00011 #include "geometry/Chip.hh"
00012 #include "geometry/DiracChip.hh"
00013
00014 #include "tools/Toolbox.hh"
00015 #include "tools/MicroException.hh"
00016 #include "tools/SteerDesc.hh"
00017 #include "tools/Log.hh"
00018
00019 #include <iostream>
00020 #include <cstdio>
00021
00022
00023
00024 #define bigTolittle Toolbox::bigTolittle
00025
00026
00027 using namespace std;
00028
00029
00030 DiracLabview::DiracLabview(Run& aRun, FILE* aFile, ui32 _firstEventId) : DifReader(aRun, aFile, _firstEventId)
00031 {
00032
00033 }
00034
00035
00036 DiracLabview::~DiracLabview()
00037 {
00038
00039 }
00040
00041
00042 int DiracLabview::getNextEvent(Event& event)
00043 {
00044 ui16 dataFormat = run.getDataFormat();
00045 if (dataFormat == 0)
00046 {
00047 dataFormat = 0;
00048 run.setDataFormat(dataFormat);
00049 return NEW_CONFIG;
00050 }
00051 char strReadLine[256];
00052 static short iNbEventInMemory = 0;
00053 static unsigned char fChannelValues[NB_EVENT_DUMP][NB_CHANNELS], fStimChannel;
00054 static short fDacLoA,fDacMidA,fDacHiA,fDacLoB,fDacMidB,fDacHiB;
00055 static int fNbDump, fBcid[NB_EVENT_DUMP];
00056 static double fCharge;
00057
00058 unsigned short fNbChannelHit;
00059 bool bFlagRun = true;
00060 bool bFlagReadEventHeader = true;
00061 Detector& aDet = run.getDetector();
00062
00063 if (iNbEventInMemory==0){
00064 while((feof(inputFile)==0) && bFlagRun){
00065 fgets(strReadLine,256,inputFile) ;
00066 if (!strncmp(strReadLine,"voie 0 = ",10)){
00067 bFlagReadEventHeader=0;
00068 }
00069 if (!strncmp(strReadLine,"voie 63 = ",10)){
00070 bFlagRun=0;
00071 }
00072
00073 if (bFlagReadEventHeader){
00074 if (!strncmp(strReadLine,"Fin de run",10)){
00075 return LAST_FILE_EVENT;
00076 }
00077 if (!strncmp(strReadLine,"Channel = ",10)){
00078 sscanf(&strReadLine[10],"%hhd",&fStimChannel);
00079 }
00080 if (!strncmp(strReadLine,"DAC_A (L-M-H) = ",16)){
00081 sscanf(&strReadLine[16],"%hd %hd %hd",&fDacLoA,&fDacMidA,&fDacHiA);
00082 }
00083 if (!strncmp(strReadLine,"DAC_B (L-M-H) = ",16)){
00084 sscanf(&strReadLine[16],"%hd %hd %hd",&fDacLoB,&fDacMidB,&fDacHiB);
00085 }
00086 if (!strncmp(strReadLine,"acquisition = ",14)){
00087 sscanf(&strReadLine[14],"%d",&fNbDump);
00088 }
00089 if (!strncmp(strReadLine,"Charge = ",9)){
00090 sscanf(&strReadLine[9],"%lE",&fCharge);
00091 }
00092 if (!strncmp(strReadLine,"BCID = ",7)){
00093 sscanf(&strReadLine[7],"%d %d %d %d %d %d %d %d",&fBcid[0],&fBcid[1],&fBcid[2],&fBcid[3],&fBcid[4],&fBcid[5],&fBcid[6],&fBcid[7]);
00094 }
00095 }
00096 if (!bFlagReadEventHeader){
00097
00098 short iChannel;
00099 sscanf(&strReadLine[5],"%hd",&iChannel);
00100 for (unsigned short iIndex=0;iIndex < NB_EVENT_DUMP;iIndex++){
00101 fChannelValues[iIndex][iChannel]=0;
00102 if (strReadLine[10+iIndex]=='1') fChannelValues[iIndex][iChannel]+=2;
00103 if (strReadLine[19+iIndex]=='1') fChannelValues[iIndex][iChannel]+=1;
00104 }
00105
00106 }
00107 }
00108 iNbEventInMemory=8;
00109 }
00110
00111 if (iNbEventInMemory!=0){
00112
00113 FILE_LOG(logDEBUG1) << endl;
00114 FILE_LOG(logDEBUG1) << "_________________________________________________________" << endl;
00115 FILE_LOG(logDEBUG1) << "Event ID : " << lastEventId << " - N° acq. : " << fNbDump << " - Stim' Channel : " << static_cast<int>(fStimChannel) << endl;
00116 FILE_LOG(logDEBUG1) << "Chip BCID : " << fBcid[8-iNbEventInMemory] << " - Dif BCID : " << "??" << endl;
00117 FILE_LOG(logDEBUG1) << "Hits :";
00118 for(unsigned char iIndex=0;iIndex<NB_CHANNELS;iIndex++){
00119 if (fChannelValues[8-iNbEventInMemory][iIndex]!=0){
00120 FILE_LOG(logDEBUG1) << " Ch"<<static_cast<int>(iIndex)<<"=>'"<<static_cast<int>(fChannelValues[8-iNbEventInMemory][iIndex])<<"'" << endl;
00121 fNbChannelHit++;
00122 }
00123 }
00124
00125 run.setInjectedCharge(fCharge);
00126 FILE_LOG(logDEBUG1) << "fCharge[" << fCharge << "]" << endl;
00127 try {
00128 Dif& dif = aDet.getDifById(1);
00129 DiracChip& diracChip = dynamic_cast<DiracChip &> (dif.getChipById(1));
00130
00131 FILE_LOG(logDEBUG1) << " Dirac slow control for chip configuration set: " << endl;
00132 diracChip.setBLoThreshold(fDacLoB);
00133 diracChip.setBMidThreshold(fDacMidB);
00134 diracChip.setBHiThreshold(fDacHiB);
00135
00136 diracChip.setALoThreshold(fDacLoA);
00137 diracChip.setAMidThreshold(fDacMidA);
00138 diracChip.setAHiThreshold(fDacHiA);
00139 diracChip.setConfigured(true);
00140
00141 FILE_LOG(logDEBUG1) << endl;
00142 FILE_LOG(logDEBUG1) << "Dac A : " << fDacLoA << " / " << fDacMidA << " / " << fDacHiA << endl;
00143 FILE_LOG(logDEBUG1) << "Dac B : " << fDacLoB << " / " << fDacMidB << " / " << fDacHiB << endl;
00144 FILE_LOG(logDEBUG1) << "Charge: " << fCharge << endl;
00145 }
00146 catch(...) {
00147 FILE_LOG(logDEBUG1) << "Ouh la la tu va avoir des gros problemes toi.: " << endl;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156 fNbChannelHit=0;
00157
00158 const ChamberMap_t &chambers = aDet.getChambers();
00159 for (ChamberMap_t::const_iterator iter=chambers.begin(); iter!=chambers.end(); iter++)
00160 {
00161 Chamber& chamber = *(*iter).second;
00162 FILE_LOG(logDEBUG1)<< "Chamber->id="<< chamber.getId() << " , descrition:" << chamber.getDescription() << endl;
00163
00164 for(unsigned char iIndex=0;iIndex<NB_CHANNELS;iIndex++){
00165 if (fChannelValues[8-iNbEventInMemory][iIndex]!=0){
00166 try{
00167
00168 const Channel& channel = chamber.getChannelById(iIndex,1,1);
00169 i16 analogValue = 0;
00170 FILE_LOG(logDEBUG1)<< "insertHit" << endl;
00171 event.insertHit(chamber,new ChannelHit(channel,fChannelValues[8-iNbEventInMemory][iIndex],analogValue));
00172 }
00173 catch ( MicroException &e){
00174 FILE_LOG(logERROR) << e.getMessage() << endl;
00175 }
00176
00177 fNbChannelHit++;
00178 }
00179 }
00180
00181 }
00182
00183 event.setId(++lastEventId);
00184 event.setTimeStamp(fBcid[8-iNbEventInMemory]);
00185 iNbEventInMemory--;
00186 }
00187 FILE_LOG(logDEBUG1)<< "event correct" << endl;
00188 return EVENT_CORRECT;
00189 }