00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024 #include <errno.h>
00025
00026 #include "mTypes.h"
00027
00028 #include "parser/MicrorocReader.hh"
00029 #include "parser/AcquisitionParser.hh"
00030
00031 #include "event/Event.hh"
00032
00033 #include "geometry/Chamber.hh"
00034 #include "geometry/Dif.hh"
00035 #include "geometry/MicrorocChip.hh"
00036 #include "geometry/Detector.hh"
00037
00038 #include "tools/Toolbox.hh"
00039 #include "tools/SteerDesc.hh"
00040 #include "tools/Log.hh"
00041 #include "tools/MicroException.hh"
00042
00043 #include <iostream>
00044 #include <iomanip>
00045
00046 using namespace std;
00047
00048
00049 MicrorocReader::MicrorocReader(Run& aRun, FILE *aFile, ui32 lastEventId) : DifReader(aRun, aFile, lastEventId)
00050 {
00051 FILE_LOG(logDEBUG1) << "--MicrorocReader constructor()"<< endl;
00052 FILE_LOG(logDEBUG) << "MicrorocReader Constructeur crc adr[" << crc << "]" << endl;
00053 reset();
00054 }
00055
00056
00057 MicrorocReader::~MicrorocReader()
00058 {
00059 FILE_LOG(logDEBUG1)<< "----MicrorocReader destructor"<< endl;
00060 }
00061
00062
00063 void MicrorocReader::reset() {
00064 bcId_AbsOrg = -1;
00065 CRC = 0;
00066 SkippedBcId = 0;
00067
00068
00069 globalTime = 0;
00070 difId = -1;
00071 difTriggerCounter = usbBusyTrigger = globalTriggerCounter = informationCounter = 0;
00072 bcPeriod = 200;
00073 bcId_Abs = bcId_Dif = bcId_Hit = 0;
00074 }
00075
00076
00077
00078 int MicrorocReader::newHit(Event& event, const Detector &detector, int digital, i16 analogValue, const int chNum, const int chipId, const int difId,const ui16 _memoryOrder )
00079 {
00080
00081
00082 const ChamberMap_t &chambers = detector.getChambers();
00083 for (ChamberMap_t::const_iterator it = chambers.begin(); it != chambers.end(); ++it) {
00084 try {
00085 Chamber& chamber = *(it->second);
00086
00087 const BoardMap_t& boards = chamber.getBoardsByDifId(difId);
00088
00089
00090 try {
00091 const Channel& channel = chamber.getChannelById(chNum, chipId, difId);
00092
00093 ChannelHit *hit = new ChannelHit(channel, digital, analogValue);
00094 hit->setMemoryOrder(_memoryOrder);
00095
00096 hit->setHardrocTime(globalTime, bcId_Abs, bcId_Dif, bcId_Hit,0);
00097 event.insertHit(chamber, hit);
00098 FILE_LOG(logDEBUG) << " new Hit : ch " << chNum << ", chip " << chipId << " ,dif " << difId
00099 << ", Time=" << globalTime << " abs=" << bcId_Abs << " dif=" << bcId_Dif << " hit=" << bcId_Hit << " Data=" << digital << " analogValue[" << analogValue << "] " << endl;
00100 return(1);
00101 }
00102 catch (MicroException &e) {
00103 FILE_LOG(logDEBUG) << "ch " << chNum << ", chip " << chipId << " chip 0x" << hex << chipId << dec << ", dif " << difId << " : " << e.getMessage() << endl;
00104 event.setValidFlag(BAD_CHIP_ID,false);
00105
00106 return(0);
00107 }
00108 }
00109 catch (...) {
00110 FILE_LOG(logDEBUG1) << " board list not found - try next" << endl;
00111 continue;
00112 }
00113
00114 }
00115 if (detector.getMonitoringId() == difId)
00116 {
00117 return 0;
00118 }
00119
00120 FILE_LOG(logDEBUG) << " ch " << chNum << ", chip " << chipId << ", dif " << difId << " : geometry element not found" << endl;
00121 return(0);
00122 }