00001 /* @version $Revision: 1328 $ * @modifiedby $Author: jacquem $ * @lastmodified $Date: 2011-10-03 17:04:17 +0200 (Mon, 03 Oct 2011) $ */ 00002 00003 ////////////////////////////////////////////////////////////////////////// 00004 // // 00005 // Crossdaq for MICROMEGAS READOUT // 00006 // // 00007 ////////////////////////////////////////////////////////////////////////// 00008 // 20091109 - 00009 // - The absolute bcId is always counted at 5MHz, 00010 // other bcId depend on the bunch crossing period 00011 ////////////////////////////////////////////////////////////////////////// 00012 00013 #ifndef DIRAC_READER_HH 00014 #define DIRAC_READER_HH 00015 00016 #include <stdlib.h> 00017 #include "mTypes.h" 00018 #include "DifReader.hh" 00019 00020 #define LABVIEW_DIRAC_READER "labviewDirac" 00021 00022 class Run; 00023 class Event; 00024 class Detector; 00025 class ChannelHit; 00026 00027 #include <vector> 00028 00029 ////////////////////////////////////////////////////////////////////////// 00030 class DiracChannelConfig { 00031 public: 00032 // ------ data members -------// 00033 bool test; // bit 1 00034 bool enable; // bit 0 00035 }; // class DiracChannelConfig 00036 00037 ////////////////////////////////////////////////////////////////////////// 00038 // Configuration Chip 00039 class DiracChipConfig { 00040 public: 00041 bool read(unsigned char *buf); 00042 public: 00043 // ------ data members -------// 00044 ui16 gain; // 3 bits (0-2) 00045 bool analogData; // bit 3 00046 // all data are shifted by 4 bits... 00047 ui16 bHiThreshold; // 8 bits for channels 32-63 00048 ui16 bMidThreshold; // 8 bits 00049 ui16 bLoThreshold; // 8 bits 00050 ui16 aHiThreshold; // 8 bits for channels 0-31 00051 ui16 aMidThreshold; // 8 bits 00052 ui16 aLoThreshold; // 8 bits 00053 DiracChannelConfig chConfig[64]; // 64 * 2 bits 00054 }; // class DiracChipConfig 00055 00056 ////////////////////////////////////////////////////////////////////////// 00057 // Configuration DIF 00058 class DiracDifConfig { 00059 public: 00060 bool read(unsigned char *buf); 00061 public: 00062 // ------ data members -------// 00063 i32 id; // difId 00064 ui32 bcPeriod; // the BC period in nanoseconds 00065 // --- configuration data for the DIF 00066 bool powerPulsing; // bit 6 00067 bool analogReading; // bit 5 00068 bool digitalReading; // bit 4 00069 ui16 acqMode; // 4 bits (0-3) / 8 00070 ui16 lowState; // 12 bits (0-11 / 16) 00071 ui16 highState; // 12 bits (0-11 / 16) 00072 ui16 afterState; // 6 bits (0-5) / 8 00073 ui16 beforeState; // 6 bits (0-5) / 8 00074 bool inverted; // bit 11 00075 bool ctestEnable; // bit 10 00076 ui16 ctestPeriod; // 10 bits (0-9 / 16) 00077 ui16 ctestDelay; // 10 bits (0-9 / 16) 00078 ui16 ctestWidth; // 10 bits (0-9 / 16) 00079 ui16 triggerDelay; // 10 bits (0-9 / 16) 00080 ui32 charge; // 32 bits 00081 // --- configuration data for each chip 00082 i32 nbChips; // number of Dirac chips 00083 std::vector<DiracChipConfig> chipConfigs; // config for each chip 00084 }; // class DiracDifConfig 00085 00086 ////////////////////////////////////////////////////////////////////////// 00087 // 8 trigger infos for each DIF which sends data 00088 class DiracTriggerInfo { 00089 public: 00090 DiracTriggerInfo(); 00091 bool read(unsigned char *buf); 00092 public: 00093 // ------ data members -------// 00094 // --- data acquisition 00095 ui16 bcId; // 12-bit bcId from dirac chip 00096 ui16 data[64]; // the data 00097 // --- configuration 00098 bool reject; // bit 0 00099 ui16 pileUp; // 5 bits (1-5) 00100 ui16 trigger; // 10 bits (6-15) 00101 i64 bcIdAbs; // 48 bits (16-63) 00102 ui32 bcIdFpga; // 16 bits (64-79) 00103 }; // class DiracTriggerInfo 00104 00105 ////////////////////////////////////////////////////////////////////////// 00106 /// CLASS DATAREADER // 00107 ////////////////////////////////////////////////////////////////////////// 00108 class DiracReader : public DifReader { 00109 00110 // public methods 00111 public: 00112 DiracReader(Run& aRun, FILE *aFile, ui32 firstEventId); 00113 ~DiracReader(); 00114 int getNextEvent(Event& eventToFill); 00115 static const char *type(const int subtype = 0) { return LABVIEW_DIRAC_READER; }; 00116 00117 //------ methods --------// 00118 private: 00119 void reset(); 00120 int getConfigData(); 00121 int getAcqData(); 00122 int storeHits(Event& event); 00123 ChannelHit *newHit(Event& event, const DiracDifConfig& difConfig, const DiracTriggerInfo& trigInfo, const int chipNum, const int chNum); 00124 void storeDifInfo(const int difId); 00125 00126 // ------ data members -------// 00127 protected: 00128 unsigned short CRC; // current CRC for the whole file 00129 00130 // DIFs and chips 00131 int nbDifs; // number of Difs which sent data 00132 std::vector<DiracDifConfig> difConfigs; // 00133 00134 // data reconstruction 00135 i64 bcId_AbsOrg; // the bcId origin, at 5MHz, for the whole file 00136 int acqDifId; // Id of the current DIF board 00137 DiracTriggerInfo trigInfos[8]; 00138 }; // class DiracReader 00139 00140 #endif // DIRAC_READER_HH