Changeset 14715 for trunk/FACT++/src/Fits.cc
- Timestamp:
- 12/03/12 14:40:26 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Fits.cc
r14238 r14715 125 125 {//if we arrived here, this means that the columns descriptions could not be parsed 126 126 ostringstream str; 127 str << "Expected " << dataFormat.size() << " descriptions of columns, got " << desc.size()-1 << " for service: ";127 str << "Expected " << dataFormat.size() << " descriptions of columns, got " << (int)(desc.size())-1 << " for service: "; 128 128 if (desc.size() > 0) 129 129 str << desc[0].name; … … 208 208 { 209 209 Close(); 210 return false; 210 //if the file already exist, then the column names must have changed 211 //let's move the file and try to open it again. 212 string fileNameWithoutFits = fFileName.substr(0, fileName.size()-4); 213 int counter = 0; 214 while (counter < 100) 215 { 216 ostringstream newFileName; 217 newFileName << fileNameWithoutFits << counter << ".fits"; 218 ifstream testStream(newFileName.str().c_str()); 219 if (!testStream) 220 { 221 if (rename(fFileName.c_str(), newFileName.str().c_str())) 222 return false; 223 break; 224 } 225 counter++; 226 } 227 if (counter == 100) 228 return false; 229 //now we open it again. 230 fFile = new FitsFile(*fMess); 231 if (file == NULL) 232 { 233 if (!fFile->OpenFile(fileName, true)) 234 return false; 235 fNumOpenFitsFiles = fitsCounter; 236 (*fNumOpenFitsFiles)++; 237 } 238 else 239 { 240 if (!fFile->SetFile(file)) 241 return false; 242 } 243 //YES, we must also redo that thing here... 244 //concatenate the standard and data columns 245 //do it the inneficient way first: its easier and faster to code. 246 for (unsigned int i=0;i<fStandardColDesc.size();i++) 247 { 248 fFile->AddColumn(fStandardColDesc[i].name, fStandardFormats[i], 249 fStandardColDesc[i].unit); 250 } 251 252 for (unsigned int i=0; i<fDataColDesc.size(); i++) 253 { 254 string name = fDataColDesc[i].name; 255 if (name.empty()) 256 { 257 ostringstream stt; 258 stt << "Data" << i; 259 name = stt.str(); 260 } 261 //cout << endl << "#####adding column: " << name << " " << fDataFormats[i] << " " << fDataColDesc[i].unit << endl << endl; 262 fFile->AddColumn(name, fDataFormats[i], fDataColDesc[i].unit); 263 } 264 if (!fFile->OpenNewTable(tableName, 100)) 265 { 266 Close(); 267 return false; 268 } 211 269 } 212 270 213 271 fCopyBuffer.resize(fFile->GetDataSize()); 214 272 //write header comments 273 215 274 ostringstream str; 216 275 for (unsigned int i=0;i<fStandardColDesc.size();i++) … … 240 299 fFile->WriteKeyNT(str.str(), fDataColDesc[i].comment, ""); 241 300 } 301 242 302 fFile->WriteKeyNT("COMMENT", fTableDesc, ""); 243 303 … … 250 310 fEndMjD = Time().Mjd(); 251 311 } 312 252 313 return fFile->GetNumRows()==0 ? WriteHeaderKeys() : true; 253 314 } 254 315 catch (const CCfits::FitsException &e) 255 316 { 317 cout << "Exception !" << endl; 256 318 fMess->Error("Opening or creating table '"+tableName+"' in '"+fileName+"': "+e.message()); 257 319 … … 323 385 shift += fStandardNumBytes[i]; 324 386 } 325 326 387 try 327 388 { … … 339 400 // This is not necessary, is it? 340 401 // fFile->fTable->makeThisCurrent(); 341 342 402 if (!fFile->AddRow()) 343 403 { … … 346 406 return false; 347 407 } 348 349 408 if (!fFile->WriteData(fCopyBuffer)) 350 409 { … … 352 411 return false; 353 412 } 354 355 413 const double tm = *reinterpret_cast<double*>(fStandardPointers[0]); 356 414 … … 385 443 if (!fFile) 386 444 return; 387 388 445 if (fFile->IsOpen() && fFile->IsOwner()) 389 446 { … … 395 452 "Time when last event received"); 396 453 } 397 398 454 if (fFile->IsOwner()) 399 455 { … … 401 457 (*fNumOpenFitsFiles)--; 402 458 } 403 404 459 const string name = fFile->GetName(); 405 406 460 delete fFile; 407 461 fFile = NULL; 408 409 462 fMess->Info("Closed: "+name); 410 411 463 // fMess = NULL; 412 464 }
Note:
See TracChangeset
for help on using the changeset viewer.