Changeset 16417 for trunk/Mars/mcore/factfits.h
- Timestamp:
- 05/28/13 23:30:11 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/factfits.h
r16285 r16417 6 6 */ 7 7 8 #ifndef FACTFITS_H_9 #define FACTFITS_H_8 #ifndef MARS_FACTFITS 9 #define MARS_FACTFITS 10 10 11 11 #include "zfits.h" 12 13 12 14 13 #ifndef __MARS__ 15 14 namespace std 16 15 { 17 #else18 using namespace std;19 16 #endif 20 17 21 class fact Fits : public zfits18 class factfits : public zfits 22 19 { 23 20 public: 24 /* 25 * Default constructor 26 */ 27 factFits(const string& fname, 28 const string& tableName="", 29 bool force=false, 30 bool mightFail=false) : zfits(fname, tableName, force, mightFail), 31 fOffsetCalibration(0), 32 fStartCellOffset(0) 21 // Default constructor 22 factfits(const string& fname, const string& tableName="", bool force=false) : 23 zfits(fname, tableName, force) 33 24 { 34 readDrsCalib(fname);35 GetStartCellOffset();25 if (init()) 26 readDrsCalib(fname); 36 27 } 37 /* 38 * Alternative constructor 39 */ 40 factFits(const string& fname, 41 const string& fout, 42 const string& tableName="", 43 bool force=false, 44 bool mightFail=false): zfits(fname, fout, tableName, force, mightFail), 45 fOffsetCalibration(0), 46 fStartCellOffset(0) 28 29 // Alternative constructor 30 factfits(const string& fname, const string& fout, const string& tableName, bool force=false) : 31 zfits(fname, fout, tableName, force) 47 32 { 48 readDrsCalib(fname);49 GetStartCellOffset();33 if (init()) 34 readDrsCalib(fname); 50 35 } 51 /* 52 * Default destrctor 53 */ 54 ~factFits() 55 {} 56 /* 57 * Overload of zfits.h 58 */ 36 37 // 59 38 #if !defined(__MARS__) && !defined(__CINT__) 60 virtualbool GetRow(size_t row, bool check=true)39 bool GetRow(size_t row, bool check=true) 61 40 #else 62 virtualbool GetRowNum(size_t row, bool check=true)41 bool GetRowNum(size_t row, bool check=true) 63 42 #endif 64 43 { 65 44 #if !defined(__MARS__) && !defined(__CINT__) 66 const bool isGood = zfits::GetRow(row, check); 45 if (!zfits::GetRow(row, check)) 46 return false; 67 47 #else 68 const bool isGood = zfits::GetRowNum(row, check); 48 if (!zfits::GetRowNum(row, check)) 49 return false; 69 50 #endif 70 //row is loaded in internal memory. Should we un-apply the integer drs ? 71 if (!isGood) return false; 72 if (!fTable.isCompressed) return true; 73 if (fOffsetCalibration.size() == 0) return true; 74 75 //now Drs un-Calibrate, if required 76 const Pointers::iterator dtaIt = fPointers.find("Data"); 77 if (dtaIt == fPointers.end()) return true; 51 // This file does not contain fact data or no calibration to be applied 52 if (fOffsetCalibration.empty()) 53 return true; 78 54 79 55 //re-get the pointer to the data to access the offsets 80 56 const uint8_t offset = (row*fTable.bytes_per_row)%4; 81 const char* ptr = fBufferRow.data() + offset;82 57 83 //get column details for Data 84 const Table::Columns::const_iterator dataColIt = fTable.cols.find("Data"); 85 if (dataColIt == fTable.cols.end()) return false; 86 const Table::Column& dataColumn = dataColIt->second; 87 const uint32_t numSlices = dataColumn.num/1440; 58 int16_t *startCell = reinterpret_cast<int16_t*>(fBufferRow.data() + offset + fOffsetStartCellData); 59 int16_t *data = reinterpret_cast<int16_t*>(fBufferRow.data() + offset + fOffsetData); 88 60 89 //Drs un-calibrate ! 90 for (uint32_t i=0;i<1440;i++) 61 for (uint32_t i=0; i<1440*1024; i+=1024, startCell++) 91 62 { 92 const int32_t thisStartCell = reinterpret_cast<const int16_t*>(ptr+fStartCellOffset)[i]; 93 for (uint32_t j=0;j<numSlices;j++) 94 reinterpret_cast<int16_t*>(dtaIt->second)[numSlices*i+j] += fOffsetCalibration[1024*i + (thisStartCell+j)%1024]; 63 for (uint32_t j=0; j<fNumRoi; j++, data++) 64 *data += fOffsetCalibration[i + (*startCell+j)%1024]; 95 65 } 66 96 67 return true; 97 68 } … … 99 70 private: 100 71 101 /* 102 * Read the Drs calibration data 103 */ 72 bool init() 73 { 74 if (!HasKey("NPIX") || !HasKey("NROI")) 75 return false; 76 77 if (Get<uint16_t>("NPIX")!=1440) 78 return false; 79 80 fNumRoi = Get<uint16_t>("NROI"); 81 if (fNumRoi>1024) 82 return false; 83 84 // check column details for Data 85 const Table::Columns::const_iterator it = fTable.cols.find("Data"); 86 if (it==fTable.cols.end() || it->second.num!=1440*fNumRoi || it->second.type!='I') 87 return false; 88 89 // check column details for StartCellData 90 const Table::Columns::const_iterator is = fTable.cols.find("StartCellData"); 91 if (is==fTable.cols.end() || is->second.num!=1440 || is->second.type!='I') 92 return false; 93 94 fOffsetStartCellData = is->second.offset; 95 fOffsetData = it->second.offset; 96 97 return true; 98 } 99 100 // Read the Drs calibration data 104 101 void readDrsCalib(const string& fileName) 105 102 { 106 zfits calib(fileName, "DrsCalib", false, true); 103 zfits calib(fileName, "DrsCalib"); 104 if (calib.bad()) 105 { 106 clear(rdstate()|ios::badbit); 107 return; 108 } 107 109 108 const bool isDrsCalibTable = (bool)calib; 109 if (!isDrsCalibTable) return; 110 if (calib.eof()) 111 return; 112 110 113 // Check correct size and format of table 111 114 if (calib.GetNumRows() != 1) 112 115 { 116 clear(rdstate()|ios::badbit); 113 117 #ifdef __EXCEPTIONS 114 throw runtime_error(" ERROR: DrsCalib tablefound, but not with one row as expected");118 throw runtime_error("Table 'DrsCalib' found, but not with one row as expected"); 115 119 #else 116 gLog << ___err___ << "ERROR : DrsCalib tablefound, but not with one row as expected" << endl;120 gLog << ___err___ << "ERROR - Table 'DrsCalib' found, but not with one row as expected" << endl; 117 121 return; 118 122 #endif … … 120 124 if (calib.GetStr("TTYPE1") != "OffsetCalibration") 121 125 { 126 clear(rdstate()|ios::badbit); 122 127 #ifdef __EXCEPTIONS 123 throw runtime_error(" ERROR: DrsCalib tablefound, but first column is not the one expected");128 throw runtime_error("Table 'DrsCalib' found, but first column is not the one expected"); 124 129 #else 125 gLog << ___err___ << "ERROR : DrsCalib tablefound, but first column is not the one expected" << endl;130 gLog << ___err___ << "ERROR - Table 'DrsCalib' found, but first column is not the one expected" << endl; 126 131 return; 127 132 #endif 128 133 } 129 if (calib.GetStr("TFORM1") != "1474560I") 134 if (calib.GetStr("TFORM1") != "1474560I") // 1024*1440 130 135 { 136 clear(rdstate()|ios::badbit); 131 137 #ifdef __EXCEPTIONS 132 throw runtime_error(" ERROR: DrsCalib table found, but has wrong column format");138 throw runtime_error("Table 'DrsCalib' has wrong column format (TFROM1)"); 133 139 #else 134 gLog << ___err___ << "ERROR : DrsCalib table found, but has wrong column format" << endl;140 gLog << ___err___ << "ERROR - Table 'DrsCalib' has wrong column format (TFORM1)" << endl; 135 141 return; 136 142 #endif … … 138 144 139 145 fOffsetCalibration.resize(1024*1440); 140 calib.SetPtrAddress("OffsetCalibration",fOffsetCalibration.data());141 146 142 calib.GetNextRow(); 143 } 147 calib.SetPtrAddress("OffsetCalibration", fOffsetCalibration.data()); 148 if (calib.GetNextRow()) 149 return; 144 150 145 /* 146 * Get the offset of the StartCell column 147 */ 148 void GetStartCellOffset() 149 { 150 for (Table::Columns::const_iterator jt=fTable.cols.begin(); jt != fTable.cols.end(); jt++) 151 { 152 if (jt->first == "StartCellData") 153 { 154 fStartCellOffset = jt->second.offset; 155 break; 156 } 157 } 151 clear(rdstate()|ios::badbit); 152 153 #ifdef __EXCEPTIONS 154 throw runtime_error("Reading column 'OffsetCalibration' failed."); 155 #else 156 gLog << ___err___ << "ERROR - Reading column 'OffsetCalibration' failed." << endl; 157 #endif 158 158 159 } 159 160 160 161 vector<int16_t> fOffsetCalibration; ///< integer values of the drs calibration used for compression 161 size_t fStartCellOffset; ///< offset of the StartCellData column in the uncompressed data 162 163 size_t fOffsetData; 164 size_t fOffsetStartCellData; 165 166 uint16_t fNumRoi; 167 168 #warning Time marker channels currently unhandled 162 169 163 170 }; //class factfits … … 167 174 #endif 168 175 169 #endif /* FACTFITS_H_ */176 #endif
Note:
See TracChangeset
for help on using the changeset viewer.