Changeset 17263
- Timestamp:
- 10/18/13 17:08:49 (11 years ago)
- Location:
- trunk/Mars/mcore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/factofits.h
r17253 r17263 15 15 namespace std 16 16 { 17 #else18 using namespace std;19 17 #endif 20 18 … … 25 23 26 24 /// constructors 27 factofits(uint32_t numTiles= 1000,28 uint32_t rowPerTile=100,29 uint64_t maxUsableMem=0) : zofits(numTiles, rowPerTile, maxUsableMem)25 factofits(uint32_t numTiles=DefaultMaxNumTiles(), uint32_t rowPerTile=DefaultNumRowsPerTile(), 26 uint32_t maxMem=DefaultMaxMemory()) 27 : zofits(numTiles, rowPerTile, maxMem) 30 28 { 31 29 fStartCellsOffset = -1; … … 33 31 } 34 32 35 factofits(const char* fname, 36 uint32_t numTiles=1000, 37 uint32_t rowPerTile=100, 38 uint64_t maxUsableMem=0) : zofits(fname, numTiles, rowPerTile, maxUsableMem) 33 factofits(const char *fname, uint32_t numTiles=DefaultMaxNumTiles(), 34 uint32_t rowPerTile=DefaultNumRowsPerTile(), uint32_t maxMem=DefaultMaxMemory()) 35 : zofits(fname, numTiles, rowPerTile, maxMem) 39 36 { 40 37 fStartCellsOffset = -1; … … 97 94 return false; 98 95 99 if (IsOffsetCalibration()) 100 {//retrieve the column storing the start cell offsets, if required. 101 102 for (auto it=fRealColumns.begin(); it!=fRealColumns.end(); it++)//Table.cols.begin(); it!= fTable.cols.end(); it++) 96 if (!IsOffsetCalibration()) 97 return true; 98 99 //retrieve the column storing the start cell offsets, if required. 100 for (auto it=fRealColumns.cbegin(); it!=fRealColumns.cend(); it++) 101 { 102 if (it->col.name == "StartCellData") 103 fStartCellsOffset = it->col.offset; 104 105 if (it->col.name == "Data") 103 106 { 104 if (it->col.name == "StartCellData") 105 fStartCellsOffset = it->col.offset; 106 107 if (it->col.name == "Data") 107 fNumSlices = it->col.num; 108 fDataOffset = it->col.offset; 109 if (fNumSlices % 1440 != 0) 108 110 { 109 fNumSlices = it->col.num;110 fDataOffset = it->col.offset;111 if (fNumSlices % 1440 != 0)112 {113 111 #ifdef __EXCEPTIONS 114 112 throw runtime_error("Number of data samples not a multiple of 1440."); 115 113 #else 116 gLog << ___err___ << "ERROR - Number of data samples not a multiple of 1440. Doing it uncalibrated." << endl; 117 #endif 118 fOffsetCalibration.resize(0); 119 } 120 fNumSlices /= 1440; 114 gLog << ___warn___ << "WARNING - Number of data samples not a multiple of 1440. Doing it uncalibrated." << endl; 115 #endif 116 fOffsetCalibration.resize(0); 121 117 } 118 fNumSlices /= 1440; 122 119 } 123 124 if (fStartCellsOffset < 0) 125 { 120 } 121 122 if (fStartCellsOffset < 0) 123 { 126 124 #ifdef __EXCEPTIONS 127 125 throw runtime_error("FACT Calibration requested, but \"StartCellData\" column not found."); 128 126 #else 129 gLog << ___err___ << "ERROR - FACT Calibration requested, but \"StartCellData\" column not found. Doing it uncalibrated." << endl; 127 gLog << ___warn___ << "WARNING - FACT Calibration requested, but \"StartCellData\" column not found. Doing it uncalibrated." << endl; 128 #endif 129 //throw away the calibration data 130 fOffsetCalibration.resize(0); 131 } 132 133 if (fDataOffset < 0) 134 { 135 #ifdef __EXCEPTIONS 136 throw runtime_error("FACT Calibration requested, but \"Data\" column not found."); 137 #else 138 gLog << ___warn___ << "WARNING - FACT Calibration requested, but \"Data\" column not found. Doing it uncalibrated." << endl; 130 139 #endif 131 140 //throw away the calibration data 132 fOffsetCalibration.resize(0); 133 } 134 135 if (fDataOffset < 0) 136 { 137 #ifdef __EXCEPTIONS 138 throw runtime_error("FACT Calibration requested, but \"Data\" column not found."); 139 #else 140 gLog << ___err___ << "ERROR - FACT Calibration requested, but \"Data\" column not found. Doing it uncalibrated." << endl; 141 #endif 142 //throw away the calibration data 143 fOffsetCalibration.resize(0); 144 } 141 fOffsetCalibration.resize(0); 145 142 } 146 143 … … 196 193 return good(); 197 194 }*/ 195 198 196 ///Actually write the drs calibration table 199 197 virtual bool WriteDrsOffsetsTable() … … 243 241 Checksum rawsum; 244 242 rawsum.add((char*)(fOffsetCalibration.data()), 1024*1440*sizeof(int16_t)); 245 ostringstream sum_str; 246 sum_str << rawsum.val(); 247 c.SetStr("RAWSUM", sum_str.str()); 243 c.SetStr("RAWSUM", to_string(rawsum.val())); 248 244 249 245 //compress data and calculate final, compressed size 250 const uint32_t compressed_header_size = sizeof( TileHeader) + sizeof(BlockHeader) + 1*sizeof(uint16_t);251 vector<char> compressed_calib(1024*1440*2 + compressed_header_size + 8); //+8 for checksum;246 const uint32_t compressed_header_size = sizeof(FITS::TileHeader) + sizeof(FITS::BlockHeader) + 1*sizeof(uint16_t); 247 std::vector<char> compressed_calib(1024*1440*2 + compressed_header_size + 8); //+8 for checksum; 252 248 char* data_start = compressed_calib.data() + compressed_header_size; 253 249 uint32_t compressed_size = compressHUFFMAN16(data_start, (char*)(fOffsetCalibration.data()), 1024*1440, 2, 1);; … … 255 251 256 252 //Write tile header 257 TileHeader th;258 vector<uint16_t> seq(1,kFactHuffman16);259 Compression bh(seq,kOrderByRow);253 FITS::TileHeader th; 254 std::vector<uint16_t> seq(1, FITS::kFactHuffman16); 255 FITS::Compression bh(seq, FITS::kOrderByRow); 260 256 th.numRows = 1; 261 257 th.size = compressed_size; 262 bh.SetBlockSize(compressed_size-sizeof( TileHeader));263 memcpy(compressed_calib.data(), &(th), sizeof( TileHeader));264 bh.Memcpy(compressed_calib.data()+sizeof( TileHeader));258 bh.SetBlockSize(compressed_size-sizeof(FITS::TileHeader)); 259 memcpy(compressed_calib.data(), &(th), sizeof(FITS::TileHeader)); 260 bh.Memcpy(compressed_calib.data()+sizeof(FITS::TileHeader)); 265 261 266 262 //calculate resulting compressed datasum … … 272 268 seekp(here_I_am); 273 269 274 vector<uint64_t> catalog(2,0);275 catalog[0] = compressed_size-sizeof( TileHeader);276 catalog[1] = sizeof( TileHeader);277 278 vector<char> swappedCatalog(catalog_size);270 std::vector<uint64_t> catalog(2,0); 271 catalog[0] = compressed_size-sizeof(FITS::TileHeader); 272 catalog[1] = sizeof(FITS::TileHeader); 273 274 std::vector<char> swappedCatalog(catalog_size); 279 275 revcpy<sizeof(int64_t)>(swappedCatalog.data(), (char*)(catalog.data()), 2);//catalog_size); 280 276 datasum.add(swappedCatalog.data(), catalog_size); … … 285 281 c.SetFloat("ZRATIO", (float)(1024*1440*2)/(float)(compressed_size)); 286 282 c.SetInt("PCOUNT", compressed_size + catalog_size); 287 288 sum_str.str(""); 289 sum_str << datasum.val(); 290 c.SetStr("DATASUM", sum_str.str()); 283 c.SetStr("DATASUM", to_string(datasum.val())); 291 284 292 285 datasum += c.WriteHeader(*this); … … 307 300 virtual void DrsOffsetCalibrate(char* target_location) 308 301 { 309 if (IsOffsetCalibration()) 302 if (!IsOffsetCalibration()) 303 return; 304 305 const int16_t* startCell = reinterpret_cast<int16_t*>(target_location + fStartCellsOffset); 306 int16_t* data = reinterpret_cast<int16_t*>(target_location + fDataOffset); 307 308 for (uint32_t ch=0; ch<1440; ch++) 310 309 { 311 const int16_t* startCell = reinterpret_cast<int16_t*>(target_location + fStartCellsOffset); 312 int16_t* data = reinterpret_cast<int16_t*>(target_location + fDataOffset); 313 314 for (uint32_t ch=0; ch<1440; ch++) 310 if (startCell[ch] < 0) 315 311 { 316 if (startCell[ch] < 0) 317 { 318 data += fNumSlices; 319 continue; 320 } 321 322 const int16_t modStart = startCell[ch]%1024; 323 const int16_t *off = fOffsetCalibration.data() + ch*1024; 324 325 const int16_t* cal = off+modStart; 326 const int16_t* end_stride = data+fNumSlices; 327 328 if (modStart+fNumSlices > 1024) 329 { 330 while (cal < off+1024) 331 *data++ -= *cal++; 332 cal = off; 333 } 334 335 while (data<end_stride) 312 data += fNumSlices; 313 continue; 314 } 315 316 const int16_t modStart = startCell[ch]%1024; 317 const int16_t *off = fOffsetCalibration.data() + ch*1024; 318 319 const int16_t* cal = off+modStart; 320 const int16_t* end_stride = data+fNumSlices; 321 322 if (modStart+fNumSlices > 1024) 323 { 324 while (cal < off+1024) 336 325 *data++ -= *cal++; 326 cal = off; 337 327 } 328 329 while (data<end_stride) 330 *data++ -= *cal++; 338 331 } 339 332 } … … 341 334 private: 342 335 /// Checks if the size of the input calibration is ok 343 void VerifyCalibrationSize(uint32_t size) 344 { 345 if (size != 1440*1024) 346 { 347 ostringstream str; 348 str << "Cannot load calibration with anything else than 1440 pixels and 1024 samples per pixel. Got a total size of " << size; 336 bool VerifyCalibrationSize(uint32_t size) 337 { 338 if (size == 1440*1024) 339 return true; 340 341 ostringstream str; 342 str << "Cannot load calibration with anything else than 1440 pixels and 1024 samples per pixel. Got a total size of " << size; 349 343 #ifdef __EXCEPTIONS 350 344 throw runtime_error(str.str()); 351 345 #else 352 346 gLog << ___err___ << "ERROR - " << str.str() << endl; 353 #endif 354 } 347 return false; 348 #endif 355 349 } 356 350 357 351 //Offsets calibration stuff. 358 vector<int16_t> fOffsetCalibration; 359 int32_t fStartCellsOffset; ///<Offset in bytes for the startcell data360 int32_t fDataOffset; ///< 361 int32_t fNumSlices; ///<Number of samples per pixel per event352 vector<int16_t> fOffsetCalibration; ///< The calibration itself 353 int32_t fStartCellsOffset; ///< Offset in bytes for the startcell data 354 int32_t fDataOffset; ///< Offset in bytes for the data 355 int32_t fNumSlices; ///< Number of samples per pixel per event 362 356 363 357 }; //class factofits -
trunk/Mars/mcore/ofits.h
r17240 r17263 36 36 namespace std 37 37 { 38 #else39 using namespace std;40 38 #endif 41 39 … … 50 48 struct Key 51 49 { 52 st ring key;53 bool delim;54 st ring value;55 st ring comment;56 st ring fitsString;50 std::string key; 51 bool delim; 52 std::string value; 53 std::string comment; 54 std::string fitsString; 57 55 58 56 off_t offset; // offset in file … … 60 58 bool changed; // For closing the file 61 59 62 Key(const st ring &k="") : key(k), delim(false), fitsString(""), offset(0), changed(true) { }63 64 st ring Trim(conststring &str)60 Key(const std::string &k="") : key(k), delim(false), fitsString(""), offset(0), changed(true) { } 61 62 std::string Trim(const std::string &str) 65 63 { 66 64 // Trim Both leading and trailing spaces … … 69 67 70 68 // if all spaces or empty return an empty string 71 if (st ring::npos==first ||string::npos==last)72 return st ring();69 if (std::string::npos==first || std::string::npos==last) 70 return std::string(); 73 71 74 72 return str.substr(first, last-first+1); … … 81 79 { 82 80 #ifdef __EXCEPTIONS 83 throw runtime_error("Key name empty.");81 throw std::runtime_error("Key name empty."); 84 82 #else 85 83 gLog << ___err___ << "ERROR - Key name empty." << endl; … … 89 87 if (key.size()>8) 90 88 { 91 ostringstream sout;89 std::ostringstream sout; 92 90 sout << "Key '" << key << "' exceeds 8 bytes."; 93 91 #ifdef __EXCEPTIONS 94 throw runtime_error(sout.str());92 throw std::runtime_error(sout.str()); 95 93 #else 96 94 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 101 99 //transform(key.begin(), key.end(), key.begin(), toupper); 102 100 103 for (st ring::const_iterator c=key.begin(); c<key.end(); c++)101 for (std::string::const_iterator c=key.cbegin(); c<key.cend(); c++) 104 102 if ((*c<'A' || *c>'Z') && (*c<'0' || *c>'9') && *c!='-' && *c!='_') 105 103 { 106 ostringstream sout;104 std::ostringstream sout; 107 105 sout << "Invalid character '" << *c << "' found in key '" << key << "'"; 108 106 #ifdef __EXCEPTIONS 109 throw runtime_error(sout.str());107 throw std::runtime_error(sout.str()); 110 108 #else 111 109 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 121 119 comment = Trim(comment); 122 120 123 for (st ring::const_iterator c=key.begin(); c<key.end(); c++)121 for (std::string::const_iterator c=key.cbegin(); c<key.cend(); c++) 124 122 if (*c<32 || *c>126) 125 123 { 126 ostringstream sout;124 std::ostringstream sout; 127 125 sout << "Invalid character '" << *c << "' [" << int(*c) << "] found in comment '" << comment << "'"; 128 126 #ifdef __EXCEPTIONS 129 throw runtime_error(sout.str());127 throw std::runtime_error(sout.str()); 130 128 #else 131 129 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 151 149 if (!trim) 152 150 { 153 ostringstream sout;151 std::ostringstream sout; 154 152 sout << "Size " << sz << " of entry for key '" << key << "' exceeds 80 characters."; 155 153 #ifdef __EXCEPTIONS 156 throw runtime_error(sout.str());154 throw std::runtime_error(sout.str()); 157 155 #else 158 156 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 169 167 { 170 168 #ifndef __EXCEPTIONS 171 ostringstream sout;169 std::ostringstream sout; 172 170 sout << "Size " << sz << " of entry for key '" << key << "' exceeds 80 characters... removed comment."; 173 171 gLog << ___warn___ << "WARNING - " << sout.str() << endl; … … 176 174 } 177 175 178 ostringstream sout;176 std::ostringstream sout; 179 177 sout << "Size " << sz << " of entry for key '" << key << "' exceeds 80 characters even without comment."; 180 178 #ifdef __EXCEPTIONS 181 throw runtime_error(sout.str());179 throw std::runtime_error(sout.str()); 182 180 #else 183 181 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 194 192 } 195 193 196 st ring Compile()194 std::string Compile() 197 195 { 198 196 … … 200 198 return fitsString; 201 199 202 ostringstream sout;200 std::ostringstream sout; 203 201 sout << std::left << setw(8) << key; 204 202 … … 226 224 return; 227 225 228 st ring str = Compile();226 std::string str = Compile(); 229 227 str.insert(str.end(), 80-str.size(), ' '); 230 228 … … 245 243 void Out(ostream &out) 246 244 { 247 st ring str = Compile();245 std::string str = Compile(); 248 246 249 247 str.insert(str.end(), 80-str.size(), ' '); … … 255 253 256 254 private: 257 vector<Key> fKeys;258 259 vector<Key>::iterator findkey(conststring &key)255 std::vector<Key> fKeys; 256 257 std::vector<Key>::iterator findkey(const std::string &key) 260 258 { 261 259 for (auto it=fKeys.begin(); it!=fKeys.end(); it++) … … 266 264 } 267 265 268 bool Set(const st ring &key="", bool delim=false, const string &value="", conststring &comment="")266 bool Set(const std::string &key="", bool delim=false, const std::string &value="", const std::string &comment="") 269 267 { 270 268 // If no delimit add the row no matter if it alread exists … … 283 281 if (fTable.num_rows>0) 284 282 { 285 ostringstream sout;283 std::ostringstream sout; 286 284 sout << "No new header key can be defined, rows were already written to the file... ignoring new key '" << key << "'"; 287 285 #ifdef __EXCEPTIONS 288 throw runtime_error(sout.str());286 throw std::runtime_error(sout.str()); 289 287 #else 290 288 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 320 318 struct Column 321 319 { 322 st ring name;320 std::string name; 323 321 size_t offset; 324 322 size_t num; … … 327 325 }; 328 326 329 vector<Column> cols;327 std::vector<Column> cols; 330 328 331 329 Table() : offset(0), bytes_per_row(0), num_rows(0), num_cols(0) … … 337 335 Table fTable; 338 336 339 vector<char> fOutputBuffer;340 341 vector<Table::Column>::iterator findcol(conststring &name)342 { 343 for (auto it=fTable.cols. begin(); it!=fTable.cols.end(); it++)337 std::vector<char> fOutputBuffer; 338 339 std::vector<Table::Column>::const_iterator findcol(const std::string &name) 340 { 341 for (auto it=fTable.cols.cbegin(); it!=fTable.cols.cend(); it++) 344 342 if (name==it->name) 345 343 return it; 346 344 347 return fTable.cols. end();345 return fTable.cols.cend(); 348 346 } 349 347 … … 398 396 } 399 397 //Etienne: required to enable 1 to 1 reconstruction of files 400 bool SetKeyComment(const st ring& key, conststring& comment)398 bool SetKeyComment(const std::string& key, const std::string& comment) 401 399 { 402 400 auto it = findkey(key); … … 407 405 return true; 408 406 } 409 bool SetKeyFromFitsString(const st ring& fitsString)407 bool SetKeyFromFitsString(const std::string& fitsString) 410 408 { 411 409 if (fTable.num_rows>0) 412 410 { 413 ostringstream sout;411 std::ostringstream sout; 414 412 sout << "No new header key can be defined, rows were already written to the file... ignoring new key '" << fitsString << "'"; 415 413 #ifdef __EXCEPTIONS 416 throwruntime_error(sout.str());417 #else 418 419 414 throw std::runtime_error(sout.str()); 415 #else 416 gLog << ___err___ << "ERROR - " << sout.str() << endl; 417 return false; 420 418 #endif 421 419 } … … 427 425 return true; 428 426 } 429 bool SetRaw(const st ring &key, const string &val, conststring &comment)427 bool SetRaw(const std::string &key, const std::string &val, const std::string &comment) 430 428 { 431 429 return Set(key, true, val, comment); 432 430 } 433 431 434 bool SetBool(const st ring &key, bool b, conststring &comment="")432 bool SetBool(const std::string &key, bool b, const std::string &comment="") 435 433 { 436 434 return Set(key, true, b?"T":"F", comment); 437 435 } 438 436 439 bool AddEmpty(const st ring &key, conststring &comment="")437 bool AddEmpty(const std::string &key, const std::string &comment="") 440 438 { 441 439 return Set(key, true, "", comment); 442 440 } 443 441 444 bool SetStr(const st ring &key, string s, conststring &comment="")442 bool SetStr(const std::string &key, std::string s, const std::string &comment="") 445 443 { 446 444 for (uint i=0; i<s.length(); i++) … … 451 449 } 452 450 453 bool SetInt(const st ring &key, int64_t i, conststring &comment="")454 { 455 ostringstream sout;451 bool SetInt(const std::string &key, int64_t i, const std::string &comment="") 452 { 453 std::ostringstream sout; 456 454 sout << i; 457 455 … … 459 457 } 460 458 461 bool SetFloat(const st ring &key, double f, int p, conststring &comment="")462 { 463 ostringstream sout;459 bool SetFloat(const std::string &key, double f, int p, const std::string &comment="") 460 { 461 std::ostringstream sout; 464 462 465 463 if (p<0) … … 472 470 sout << f; 473 471 474 st ring str = sout.str();472 std::string str = sout.str(); 475 473 476 474 replace(str.begin(), str.end(), 'e', 'E'); 477 475 478 if (str.find_first_of('E')==st ring::npos && str.find_first_of('.')==string::npos)476 if (str.find_first_of('E')==std::string::npos && str.find_first_of('.')==std::string::npos) 479 477 str += "."; 480 478 … … 482 480 } 483 481 484 bool SetFloat(const st ring &key, double f, conststring &comment="")482 bool SetFloat(const std::string &key, double f, const std::string &comment="") 485 483 { 486 484 return SetFloat(key, f, 0, comment); 487 485 } 488 486 489 bool SetHex(const st ring &key, uint64_t i, conststring &comment="")490 { 491 ostringstream sout;487 bool SetHex(const std::string &key, uint64_t i, const std::string &comment="") 488 { 489 std::ostringstream sout; 492 490 sout << std::hex << "0x" << i; 493 491 return SetStr(key, sout.str(), comment); 494 492 } 495 493 496 bool AddComment(const st ring &comment)494 bool AddComment(const std::string &comment) 497 495 { 498 496 return Set("COMMENT", false, "", comment); 499 497 } 500 498 501 bool AddHistory(const st ring &comment)499 bool AddHistory(const std::string &comment) 502 500 { 503 501 return Set("HISTORY", false, "", comment); … … 511 509 } 512 510 513 st ring CommentFromType(char type)514 { 515 st ring comment;511 std::string CommentFromType(char type) 512 { 513 std::string comment; 516 514 517 515 switch (type) 518 516 { 519 case 'L': comment = " 1-byte BOOL]"; break;520 case 'A': comment = " 1-byte CHAR]"; break;521 case 'B': comment = " 1-byte BOOL]"; break;522 case 'I': comment = " 2-byte INT]"; break;523 case 'J': comment = " 4-byte INT]"; break;524 case 'K': comment = " 8-byte INT]"; break;525 case 'E': comment = " 4-byte FLOAT]"; break;526 case 'D': comment = " 8-byte FLOAT]"; break;527 case 'Q': comment = " var. Length]"; break;517 case 'L': comment = "[1-byte BOOL]"; break; 518 case 'A': comment = "[1-byte CHAR]"; break; 519 case 'B': comment = "[1-byte BOOL]"; break; 520 case 'I': comment = "[2-byte INT]"; break; 521 case 'J': comment = "[4-byte INT]"; break; 522 case 'K': comment = "[8-byte INT]"; break; 523 case 'E': comment = "[4-byte FLOAT]"; break; 524 case 'D': comment = "[8-byte FLOAT]"; break; 525 case 'Q': comment = "[var. Length]"; break; 528 526 } 529 527 … … 551 549 } 552 550 //ETIENNE to be able to restore the file 1 to 1, I must restore the header keys myself 553 virtual bool AddColumn(uint32_t cnt, char typechar, const st ring &name, const string &unit, conststring &comment="", bool addHeaderKeys=true)551 virtual bool AddColumn(uint32_t cnt, char typechar, const std::string &name, const std::string &unit, const std::string &comment="", bool addHeaderKeys=true) 554 552 { 555 553 if (tellp()<0) 556 554 { 557 ostringstream sout;555 std::ostringstream sout; 558 556 sout << "File not open... ignoring column '" << name << "'"; 559 557 #ifdef __EXCEPTIONS 560 throw runtime_error(sout.str());558 throw std::runtime_error(sout.str()); 561 559 #else 562 560 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 567 565 if (tellp()>0) 568 566 { 569 ostringstream sout;567 std::ostringstream sout; 570 568 sout << "Header already written, no new column can be defined... ignoring column '" << name << "'"; 571 569 #ifdef __EXCEPTIONS 572 throw runtime_error(sout.str());570 throw std::runtime_error(sout.str()); 573 571 #else 574 572 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 577 575 } 578 576 579 if (findcol(name)!=fTable.cols. end())580 { 581 ostringstream sout;577 if (findcol(name)!=fTable.cols.cend()) 578 { 579 std::ostringstream sout; 582 580 sout << "A column with the name '" << name << "' already exists."; 583 581 #ifdef __EXCEPTIONS 584 throw runtime_error(sout.str());582 throw std::runtime_error(sout.str()); 585 583 #else 586 584 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 591 589 typechar = toupper(typechar); 592 590 593 static const st ring allow("LABIJKEDQ");594 if (std::find(allow. begin(), allow.end(), typechar)==allow.end())595 { 596 ostringstream sout;591 static const std::string allow("LABIJKEDQ"); 592 if (std::find(allow.cbegin(), allow.cend(), typechar)==allow.end()) 593 { 594 std::ostringstream sout; 597 595 sout << "Column type '" << typechar << "' not supported."; 598 596 #ifdef __EXCEPTIONS 599 throw runtime_error(sout.str());597 throw std::runtime_error(sout.str()); 600 598 #else 601 599 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 604 602 } 605 603 606 ostringstream type;604 std::ostringstream type; 607 605 type << cnt; 608 606 if (typechar=='Q') … … 613 611 fTable.num_cols++; 614 612 615 ostringstream typekey, formkey, unitkey, unitcom, typecom;616 typekey << "TTYPE" << fTable.num_cols;617 formkey << "TFORM" << fTable.num_cols;618 unitkey << "TUNIT" << fTable.num_cols;619 unitcom << "unit of " << name;620 621 typecom << "format of " << name << " [";622 623 typecom << CommentFromType(typechar);624 625 613 if (addHeaderKeys) 626 614 { 627 SetStr(formkey.str(), type.str(), typecom.str()); 628 SetStr(typekey.str(), name, comment); 615 const std::string nc = std::to_string(fTable.num_cols); 616 617 SetStr("TFORM"+nc, type.str(), "format of "+name+" "+CommentFromType(typechar)); 618 SetStr("TTYPE"+nc, name, comment); 629 619 if (!unit.empty()) 630 SetStr( unitkey.str(), unit, unitcom.str());620 SetStr("TUNIT"+nc, unit, "unit of "+name); 631 621 } 632 622 size_t size = SizeFromType(typechar); … … 650 640 } 651 641 652 virtual bool AddColumn(const FITS::Compression&, uint32_t cnt, char typechar, const st ring& name, const string& unit, conststring& comment="", bool addHeaderKeys=true)642 virtual bool AddColumn(const FITS::Compression&, uint32_t cnt, char typechar, const std::string& name, const std::string& unit, const std::string& comment="", bool addHeaderKeys=true) 653 643 { 654 644 return AddColumn(cnt, typechar, name, unit, comment, addHeaderKeys); 655 645 } 656 646 657 bool AddColumnShort(uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")647 bool AddColumnShort(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 658 648 { return AddColumn(cnt, 'I', name, unit, comment); } 659 bool AddColumnInt(uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")649 bool AddColumnInt(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 660 650 { return AddColumn(cnt, 'J', name, unit, comment); } 661 bool AddColumnLong(uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")651 bool AddColumnLong(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 662 652 { return AddColumn(cnt, 'K', name, unit, comment); } 663 bool AddColumnFloat(uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")653 bool AddColumnFloat(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 664 654 { return AddColumn(cnt, 'E', name, unit, comment); } 665 bool AddColumnDouble(uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")655 bool AddColumnDouble(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 666 656 { return AddColumn(cnt, 'D', name, unit, comment); } 667 bool AddColumnChar(uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")657 bool AddColumnChar(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 668 658 { return AddColumn(cnt, 'A', name, unit, comment); } 669 bool AddColumnByte(uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")659 bool AddColumnByte(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 670 660 { return AddColumn(cnt, 'B', name, unit, comment); } 671 bool AddColumnBool(uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")661 bool AddColumnBool(uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 672 662 { return AddColumn(cnt, 'L', name, unit, comment); } 673 663 674 bool AddColumnShort(const st ring &name, const string &unit="", conststring &comment="")664 bool AddColumnShort(const std::string &name, const std::string &unit="", const std::string &comment="") 675 665 { return AddColumn(1, 'I', name, unit, comment); } 676 bool AddColumnInt(const st ring &name, const string &unit="", conststring &comment="")666 bool AddColumnInt(const std::string &name, const std::string &unit="", const std::string &comment="") 677 667 { return AddColumn(1, 'J', name, unit, comment); } 678 bool AddColumnLong(const st ring &name, const string &unit="", conststring &comment="")668 bool AddColumnLong(const std::string &name, const std::string &unit="", const std::string &comment="") 679 669 { return AddColumn(1, 'K', name, unit, comment); } 680 bool AddColumnFloat(const st ring &name, const string &unit="", conststring &comment="")670 bool AddColumnFloat(const std::string &name, const std::string &unit="", const std::string &comment="") 681 671 { return AddColumn(1, 'E', name, unit, comment); } 682 bool AddColumnDouble(const st ring &name, const string &unit="", conststring &comment="")672 bool AddColumnDouble(const std::string &name, const std::string &unit="", const std::string &comment="") 683 673 { return AddColumn(1, 'D', name, unit, comment); } 684 bool AddColumnChar(const st ring &name, const string &unit="", conststring &comment="")674 bool AddColumnChar(const std::string &name, const std::string &unit="", const std::string &comment="") 685 675 { return AddColumn(1, 'A', name, unit, comment); } 686 bool AddColumnByte(const st ring &name, const string &unit="", conststring &comment="")676 bool AddColumnByte(const std::string &name, const std::string &unit="", const std::string &comment="") 687 677 { return AddColumn(1, 'B', name, unit, comment); } 688 bool AddColumnBool(const st ring &name, const string &unit="", conststring &comment="")678 bool AddColumnBool(const std::string &name, const std::string &unit="", const std::string &comment="") 689 679 { return AddColumn(1, 'L', name, unit, comment); } 690 680 691 bool AddColumnShort(const FITS::Compression &comp, uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")681 bool AddColumnShort(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 692 682 { return AddColumn(comp, cnt, 'I', name, unit, comment); } 693 bool AddColumnInt(const FITS::Compression &comp, uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")683 bool AddColumnInt(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 694 684 { return AddColumn(comp, cnt, 'J', name, unit, comment); } 695 bool AddColumnLong(const FITS::Compression &comp, uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")685 bool AddColumnLong(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 696 686 { return AddColumn(comp, cnt, 'K', name, unit, comment); } 697 bool AddColumnFloat(const FITS::Compression &comp, uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")687 bool AddColumnFloat(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 698 688 { return AddColumn(comp, cnt, 'E', name, unit, comment); } 699 bool AddColumnDouble(const FITS::Compression &comp, uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")689 bool AddColumnDouble(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 700 690 { return AddColumn(comp, cnt, 'D', name, unit, comment); } 701 bool AddColumnChar(const FITS::Compression &comp, uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")691 bool AddColumnChar(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 702 692 { return AddColumn(comp, cnt, 'A', name, unit, comment); } 703 bool AddColumnByte(const FITS::Compression &comp, uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")693 bool AddColumnByte(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 704 694 { return AddColumn(comp, cnt, 'B', name, unit, comment); } 705 bool AddColumnBool(const FITS::Compression &comp, uint32_t cnt, const st ring &name, const string &unit="", conststring &comment="")695 bool AddColumnBool(const FITS::Compression &comp, uint32_t cnt, const std::string &name, const std::string &unit="", const std::string &comment="") 706 696 { return AddColumn(comp, cnt, 'L', name, unit, comment); } 707 697 708 bool AddColumnShort(const FITS::Compression &comp, const st ring &name, const string &unit="", conststring &comment="")698 bool AddColumnShort(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="") 709 699 { return AddColumn(comp, 1, 'I', name, unit, comment); } 710 bool AddColumnInt(const FITS::Compression &comp, const st ring &name, const string &unit="", conststring &comment="")700 bool AddColumnInt(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="") 711 701 { return AddColumn(comp, 1, 'J', name, unit, comment); } 712 bool AddColumnLong(const FITS::Compression &comp, const st ring &name, const string &unit="", conststring &comment="")702 bool AddColumnLong(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="") 713 703 { return AddColumn(comp, 1, 'K', name, unit, comment); } 714 bool AddColumnFloat(const FITS::Compression &comp, const st ring &name, const string &unit="", conststring &comment="")704 bool AddColumnFloat(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="") 715 705 { return AddColumn(comp, 1, 'E', name, unit, comment); } 716 bool AddColumnDouble(const FITS::Compression &comp, const st ring &name, const string &unit="", conststring &comment="")706 bool AddColumnDouble(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="") 717 707 { return AddColumn(comp, 1, 'D', name, unit, comment); } 718 bool AddColumnChar(const FITS::Compression &comp, const st ring &name, const string &unit="", conststring &comment="")708 bool AddColumnChar(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="") 719 709 { return AddColumn(comp, 1, 'A', name, unit, comment); } 720 bool AddColumnByte(const FITS::Compression &comp, const st ring &name, const string &unit="", conststring &comment="")710 bool AddColumnByte(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="") 721 711 { return AddColumn(comp, 1, 'B', name, unit, comment); } 722 bool AddColumnBool(const FITS::Compression &comp, const st ring &name, const string &unit="", conststring &comment="")712 bool AddColumnBool(const FITS::Compression &comp, const std::string &name, const std::string &unit="", const std::string &comment="") 723 713 { return AddColumn(comp, 1, 'L', name, unit, comment); } 724 714 725 715 /* 726 bool AddKey(string key, double d, const st ring &comment)716 bool AddKey(string key, double d, const std::string &comment) 727 717 { 728 718 ostringstream out; 729 719 out << d; 730 720 731 st ring s = out.str();721 std::string s = out.str(); 732 722 733 723 replace(s.begin(), s.end(), "e", "E"); … … 804 794 { 805 795 #ifdef __EXCEPTIONS 806 throw runtime_error("File not empty anymore.");796 throw std::runtime_error("File not empty anymore."); 807 797 #else 808 798 gLog << ___err___ << "ERROR - File not empty anymore." << endl; … … 848 838 sout << "WriteRow - Size " << cnt << " does not match expected size " << fTable.bytes_per_row; 849 839 #ifdef __EXCEPTIONS 850 throw runtime_error(sout.str());840 throw std::runtime_error(sout.str()); 851 841 #else 852 842 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 876 866 else 877 867 { 878 for (auto it=fTable.cols. begin(); it!=fTable.cols.end(); it++)868 for (auto it=fTable.cols.cbegin(); it!=fTable.cols.cend(); it++) 879 869 { 880 870 const char *src = reinterpret_cast<const char*>(ptr) + it->offset; … … 902 892 903 893 template<typename N> 904 bool WriteRow(const vector<N> &vec)894 bool WriteRow(const std::vector<N> &vec) 905 895 { 906 896 return WriteRow(vec.data(), vec.size()*sizeof(N)); … … 920 910 if (tellp()%(80*36)>0) 921 911 { 922 vector<char> filler(80*36-tellp()%(80*36));912 std::vector<char> filler(80*36-tellp()%(80*36)); 923 913 write(filler.data(), filler.size()); 924 914 } … … 961 951 sout << "Checksum (" << std::hex << chk.val() << ") invalid."; 962 952 #ifdef __EXCEPTIONS 963 throw runtime_error(sout.str());953 throw std::runtime_error(sout.str()); 964 954 #else 965 955 gLog << ___err___ << "ERROR - " << sout.str() << endl; … … 970 960 pair<string, int> GetChecksumData() 971 961 { 972 st ring datasum;973 st ring checksum;962 std::string datasum; 963 std::string checksum; 974 964 //cannot directly use the Get methods, because they are only in fits.h 975 for ( vector<Key>::const_iterator it=fKeys.begin(); it!= fKeys.end(); it++)965 for (std::vector<Key>::const_iterator it=fKeys.cbegin(); it!= fKeys.cend(); it++) 976 966 { 977 967 if (it->key == "CHECKSUM") checksum = it->value; … … 1002 992 const struct tm *tmp1 = gmtime(&t0); 1003 993 1004 st ring str(21, '\0');994 std::string str(21, '\0'); 1005 995 if (tmp1 && strftime(const_cast<char*>(str.data()), 20, "%Y-%m-%dT%H:%M:%S", tmp1)) 1006 996 SetStr("DATE", str, "File creation date"); … … 1061 1051 fits f("delme.fits"); 1062 1052 if (!f) 1063 throw runtime_error("xxx");1053 throw std::runtime_error("xxx"); 1064 1054 1065 1055 cout << "Header is valid: " << f.IsHeaderOk() << endl; -
trunk/Mars/mcore/zofits.h
r17262 r17263 559 559 fRealColumns.emplace_back(col, comp); 560 560 561 ostringstream str; 562 str << "format of " << name << " [" << CommentFromType(typechar); 563 564 SetStr("ZFORM"+to_string(fRealColumns.size()), to_string(cnt)+typechar, str.str()); 561 SetStr("ZFORM"+to_string(fRealColumns.size()), to_string(cnt)+typechar, "format of "+name+" "+CommentFromType(typechar)); 565 562 SetStr("ZCTYP"+to_string(fRealColumns.size()), "FACT", "Compression type: FACT"); 566 563
Note:
See TracChangeset
for help on using the changeset viewer.