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

Go to the documentation of this file.
00001 /* @version $Revision: 1789 $ * @modifiedby $Author: lcdet $ * @lastmodified $Date: 2012-06-20 16:45:37 +0200 (Wed, 20 Jun 2012) $ */
00002 
00003 ////////////////////////////////////////////////////////////////////////
00004 // MICROMEGAS
00005 //
00006 //       EVENT RECONSTRUCTION SOFTWARE FOR HARDROC BOARDS
00007 //
00008 ////////////////////////////////////////////////////////////////////////
00009 // v7 8.6.2009
00010 //    29.6.2009 : added timestamps with Microroc data
00011 ////////////////////////////////////////////////////////////////////////
00012 // timestamp (v7) :
00013 //   t(hit) = t(lecture) - t2 + t3
00014 //   l(lecture) = t0 + (t1 - t10)
00015 //   avec
00016 //     t0 = timestamp unix (32 bits, avec ou sans millisecondes)
00017 //     t1 = BcId absolu (bcId_Abs, 48 bits)
00018 //     t10 = premiere lecture de t1
00019 //     t2 = BcId pour la DIF (bcId_HRHit, 24 bits)
00020 //     t3 = BCId pour la HR (bcId_Hit, 24 bits en CODE GRAY)
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 //--------------- Destructeur -------------//
00057 MicrorocReader::~MicrorocReader()
00058 {
00059   FILE_LOG(logDEBUG1)<< "----MicrorocReader destructor"<< endl;
00060 }
00061 
00062 //-------------------------------------------------------------------
00063 void MicrorocReader::reset() {
00064   bcId_AbsOrg = -1; // the bcId origin in milliseconds
00065   CRC = 0; // current CRC for the whole file
00066   SkippedBcId = 0;
00067 
00068   // following initializations are useless
00069   globalTime = 0;
00070   difId = -1;
00071   difTriggerCounter = usbBusyTrigger = globalTriggerCounter = informationCounter = 0;
00072   bcPeriod = 200;
00073   bcId_Abs = bcId_Dif = bcId_Hit = 0;
00074 } // MicrorocReader.reset
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   // cannot be binary pattern 10
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       // if failed continue throw cath
00087        const BoardMap_t& boards = chamber.getBoardsByDifId(difId);
00088       
00089       // store new event data
00090       try {
00091         const Channel& channel = chamber.getChannelById(chNum, chipId, difId);
00092         //i32 analogValue = 0;
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   } // for
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 } // MicrorocReader.newHit

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