00001 #ifndef RAWDATAEVENT_H 00002 #define RAWDATAEVENT_H 00003 00004 #include <iostream> 00005 #include <vector> 00006 #include "bit_utility.h" 00007 #include "Conventions/Electronics.h" 00008 #include "Event/Readout.h" 00009 #include "RawDataFormat.h" 00010 00011 class RawDataEvent 00012 { 00013 public: 00015 class FileHeader 00016 { 00017 public: 00018 void print(); 00019 00020 // in file_start_record 00021 unsigned int m_version; 00022 unsigned int m_fileNumber; 00023 unsigned int m_date; // DDMMYYYY 00024 unsigned int m_time; // HHMMSS 00025 unsigned int m_sizeLimitBlocks; // file size limit in # of data blocks 00026 unsigned int m_sizeLimitMB; // ... in MBytes 00027 00028 // file_name_strings 00029 std::string m_appName; 00030 std::string m_fileNameTag; 00031 00032 // run_parameters_record 00033 unsigned int m_runNumber; 00034 unsigned int m_recEnable; 00035 unsigned int m_triggerType; 00036 unsigned int m_detectorMask; 00037 00038 // optional metadata strings 00039 std::vector<std::string> m_metadataString; 00040 00041 }; 00042 00043 00045 class FileFooter 00046 { 00047 public: 00048 unsigned int m_dateEnd; 00049 unsigned int m_timeEnd; 00050 unsigned int m_eventsInFile; // in this file 00051 unsigned int m_dataInFile; // in MB 00052 unsigned int m_eventsInRun; // in this run 00053 unsigned int m_dataInRun; // in MB 00054 unsigned int m_status; // non-zero for the last file 00055 00056 void print(); 00057 }; 00058 00059 00061 class PmtChannel 00062 { 00063 public: 00064 00065 int m_channel; // -1: no value 00066 std::vector<int> m_adc; 00067 std::vector<int> m_adcPeakingCycle; 00068 std::vector<int> m_adcRange; 00069 std::vector<int> m_tdc; 00070 std::vector<int> m_tdcHitCount; 00071 std::vector<int> m_pedestal; 00072 00073 PmtChannel() { 00074 m_channel = -1; 00075 } 00076 00077 bool filled() { 00078 return m_channel != -1; 00079 } 00080 00081 DayaBay::FeeGain::FeeGain_t feeGain() { return (DayaBay::FeeGain::FeeGain_t) (m_adc.size()==0 ? 0 : 1+m_adcRange[0]); } 00082 00083 void clear() { 00084 m_channel = -1; 00085 m_adc.clear(); 00086 m_adcPeakingCycle.clear(); 00087 m_adcRange.clear(); 00088 m_tdc.clear(); 00089 m_tdcHitCount.clear(); 00090 m_pedestal.clear(); 00091 } 00092 00093 void print(); 00094 }; 00095 00097 class Rom 00098 { 00099 public: 00100 // data members 00101 // information in ROM header 00102 int m_size; // total size of bytes including header 00103 int m_slot; // slot number 00104 int m_type; // module type 00105 00106 // information in CBLT header and footer 00107 int m_cbltGA; // VME module Geographic Address 00108 int m_cbltModuleType; 00109 int m_cbltDataLength; // bytes from CBLT head to foot 00110 00111 // function members 00112 Rom() {} 00113 virtual ~Rom() {} 00114 00115 virtual void print(); 00116 }; 00117 00118 00119 class RomFee : public Rom 00120 { 00121 public: 00122 // information in data header and footer 00123 int m_triggerNum; // 8-bit loop integers from 0 00124 int m_triggerType; // local:0000, cross:0001 00125 int m_version; // data format version 00126 int m_status; 00127 int m_dataLength; // bytes from data head to foot 00128 std::vector<PmtChannel> m_channels; 00129 00130 void print(); 00131 }; 00132 00133 class FadcChannel 00134 { 00135 public: 00136 00137 int m_channel; // -1: no value 00138 std::vector<int> m_adcData; 00139 00140 FadcChannel() { 00141 m_channel = -1; 00142 } 00143 00144 bool filled() { 00145 return m_channel != -1; 00146 } 00147 00148 void clear() { 00149 m_channel = -1; 00150 m_adcData.clear(); 00151 } 00152 00153 void print(); 00154 }; 00155 00156 class RomFadc : public Rom 00157 { 00158 public: 00159 // information in data header and footer 00160 int m_triggerNum; // 8-bit loop integers from 0 00161 int m_triggerType; // local:0000, cross:0001 00162 int m_version; // data format version 00163 int m_status; 00164 int m_dataLength; // bytes from data head to foot 00165 std::vector<FadcChannel> m_channels; 00166 00167 void print(); 00168 }; 00169 00170 class LtbFrame 00171 { 00172 public: 00173 bool m_accStat; // Accumulation status 00174 bool m_GPSValid; // GPS valid 00175 bool m_timestampType; // Timestamp type 1: UTC, 0: UNIX. 00176 bool m_clockSystemValid; // Clock system valid 00177 int m_iltSn; // Raw trigger sequence number 00178 int m_rot; // Read Out Type 00179 int m_triggerSrc; // status of 16 trigger sources 00180 unsigned int m_nanoSecondLow; 00181 unsigned int m_nanoSecondHigh; // Number of 0.5ns 00182 int m_accumulationLow; 00183 int m_accumulationHigh; // Number of 0.5ns 00184 int m_hsum; // sum of hits 00185 int m_esumComp; 00186 int m_esumADC; 00187 int m_blockedValidTrigger; // the number of local trigger which is blocked by 00188 // buffer full between two packeged local trigger 00189 int m_crossTriggerSrc; 00190 bool m_feeBufferStat; // FEE buffer status 00191 bool m_ltbBufferStat; // LTB buffer status 00192 00193 virtual void print(); 00194 00195 virtual TimeStamp timeStamp() const = 0; 00196 virtual ~LtbFrame() {;} 00197 00198 }; 00199 00200 class LtbFrameUTC : public LtbFrame 00201 { 00202 public: 00203 int m_day; // the number of day from Jan 1 of current year in binary code 00204 int m_hour; // the hour of current day in BCD code 00205 int m_minute; // the minute of current hour in BCD code 00206 int m_second; // the second of current minute in BCD code 00207 virtual TimeStamp timeStamp() const { 00208 time_t sec = m_day*86400 + bcd2dec(m_hour)*3600 + bcd2dec(m_minute)*60 + bcd2dec(m_second); 00209 int nsec = ((m_nanoSecondHigh<<4 | m_nanoSecondLow) + (m_accumulationHigh<<4 | m_accumulationLow))/2; 00210 return TimeStamp(sec,nsec); 00211 } 00212 virtual void print(); 00213 virtual ~LtbFrameUTC() {;} 00214 }; 00215 00216 class LtbFrameUnix : public LtbFrame 00217 { 00218 public: 00219 unsigned int m_unixSecLow; // the number of second since Jan 1th, 1970, low 16 bit 00220 unsigned int m_unixSecHigh; // the number of second since Jan 1th, 1970, high 16 bit 00221 virtual TimeStamp timeStamp() const { 00222 time_t sec = (m_unixSecHigh << 16) | m_unixSecLow; 00223 int nsec = ((m_nanoSecondHigh<<4 | m_nanoSecondLow) + (m_accumulationHigh<<4 | m_accumulationLow))/2; 00224 TimeStamp time(sec,nsec); 00225 return TimeStamp(sec,nsec); 00226 } 00227 virtual void print(); 00228 virtual ~LtbFrameUnix() {;} 00229 }; 00230 00231 class RomLtb : public Rom 00232 { 00233 public: 00234 std::vector<LtbFrame*> m_frames; 00235 00236 virtual ~RomLtb() {clear();} 00237 void print(); 00238 00240 void clear() { 00241 if (m_frames.empty()) return; 00242 for (unsigned int i = 0; i < m_frames.size(); i++) { 00243 delete m_frames[i]; 00244 } 00245 m_frames.clear(); 00246 } 00247 }; 00248 00250 00251 RawDataEvent() { 00252 m_fileHeader = new FileHeader(); 00253 m_fileFooter = new FileFooter(); 00254 } 00255 00256 virtual ~RawDataEvent() { 00257 delete m_fileHeader; 00258 delete m_fileFooter; 00259 m_rawBuffer.clear(); 00260 clear(); 00261 } 00262 00263 void print(); 00264 00266 void clear() { 00267 if (m_modules.empty()) return; 00268 for (unsigned int i = 0; i < m_modules.size(); i++) { 00269 delete m_modules[i]; 00270 } 00271 m_modules.clear(); 00272 } 00273 00274 00275 // data members 00276 //______________________________________________________________________ 00277 00279 FileHeader* m_fileHeader; 00280 FileFooter* m_fileFooter; 00281 00283 int m_dataBlockNum; // # of the block 00284 int m_dataBlockSize; // in bytes 00285 00287 int m_formatVersionMajor; 00288 int m_formatVersionMinor; 00289 int m_evtSize; // in bytes 00290 int m_detId; 00291 int m_siteId; // m_detId[4:7] 00292 int m_positionId; // m_detId[0:3] 00293 int m_runNum; 00294 int m_evtNum; 00295 int m_dataType; // 0:normal, 1:calib, 2:elec. calib. 00296 int m_dataTypeSpecific; // DAC for elec. calib. 00297 int m_dataStatus; 00298 std::vector<unsigned int> m_rawBuffer; 00299 00301 std::vector<Rom*> m_modules; 00302 00304 bool isInvalidData() { 00305 return test_bit(m_dataStatus, 0); 00306 } 00307 bool isNotMatchTriggerNumber() { 00308 return test_bit(m_dataStatus, 1); 00309 } 00310 bool isCBLTRawFormat() { 00311 return test_bit(m_dataStatus, 16); 00312 } 00313 bool isCBLTHeader() { 00314 return test_bit(m_dataStatus, 17); 00315 } 00316 00318 00319 //Trigger Type, need to be refined 00320 DayaBay::Trigger::TriggerType_t triggerType() { 00321 00322 unsigned int triType = 0; 00323 00324 for (unsigned int i = 0; i < m_modules.size(); i++) { 00325 if(m_modules[i]->m_type == dyb::kRomLtb) { 00326 RawDataEvent::RomLtb* romLtb; 00327 romLtb = dynamic_cast<RawDataEvent::RomLtb*>(m_modules[i]); 00328 00330 for (unsigned int j = 0; j < romLtb->m_frames.size(); j++) { 00331 //std::cout<<romLtb->m_frames[j].m_triggerSrc<<std::endl; 00332 if(romLtb->m_frames[j]->m_triggerSrc & (1<<0) ) { //MANUAL_TRIGGER 00333 triType = triType | DayaBay::Trigger::kManual; 00334 } 00335 if(romLtb->m_frames[j]->m_triggerSrc & (1<<1) ) { //CROSS_TRIGGER_IN 00336 triType = triType | DayaBay::Trigger::kExternal; 00337 } 00338 if(romLtb->m_frames[j]->m_triggerSrc & (1<<2) ) { //PERIODIC_TRIGGER 00339 triType = triType | DayaBay::Trigger::kPeriodic; 00340 } 00341 if(romLtb->m_frames[j]->m_triggerSrc & (1<<8) ) { //MULTIPLICITY_TRIGGER 00342 triType = triType | DayaBay::Trigger::kMult; 00343 } 00344 if(romLtb->m_frames[j]->m_triggerSrc & (1<<9) ) { //ESUM_ADC_TRG 00345 triType = triType | DayaBay::Trigger::kESumADC; 00346 } 00347 if(romLtb->m_frames[j]->m_triggerSrc & (1<<10) ) { //HIGH_ESUM_COMP_TRG 00348 triType = triType | DayaBay::Trigger::kESumHigh; 00349 } 00350 if(romLtb->m_frames[j]->m_triggerSrc & (1<<11) ) { //LOW_ESUM_COMP_TRG 00351 triType = triType | DayaBay::Trigger::kESumLow; 00352 } 00353 if(romLtb->m_frames[j]->m_triggerSrc & (1<<12) ) { //ALL_ESUM_COMP_TRG 00354 triType = triType | DayaBay::Trigger::kESumAll; 00355 } 00356 00357 break; // use the first ltb frame 00358 } 00359 00360 break; 00361 } 00362 } 00363 00364 return (DayaBay::Trigger::TriggerType_t)( triType | (detectorId() << 2)); 00365 } 00366 00367 00368 Site::Site_t siteId() { 00369 return (Site::Site_t)(m_siteId == 0 ? m_siteId : 1 << (m_siteId - 1)); 00370 } 00371 00372 DetectorId::DetectorId_t detectorId() { 00373 return (DetectorId::DetectorId_t)m_positionId; 00374 } 00375 00376 00377 private: 00378 }; 00379 00380 #endif