Changeset 14715 for trunk/FACT++
- Timestamp:
- 12/03/12 14:40:26 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 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 } -
trunk/FACT++/src/FitsFile.cc
r14615 r14715 99 99 return false; 100 100 } 101 102 101 // fFileName = fileName; 103 102 if (!allow_open && access(filename.c_str(), F_OK)==0) … … 106 105 return false; 107 106 } 108 109 107 //create the FITS object 110 108 try … … 117 115 return false; 118 116 } 119 120 117 /* 121 118 "SIMPLE = T / file does conform to FITS standard " … … 299 296 // Go through the fTable instead as colName is empty (yes, it is !) 300 297 const map<string,CCfits::Column*> &cMap = table->column(); 298 299 //check that the existing columns are the same as the ones we want to write 300 for (map<string, CCfits::Column*>::const_iterator mapIt = cMap.begin(); mapIt != cMap.end(); mapIt++) 301 { 302 bool found = false; 303 for (unsigned int ii=0;ii<fColNames.size();ii++) 304 { 305 if (mapIt->first == fColNames[ii]) 306 { 307 found = true; 308 if (mapIt->second->format() != fColTypes[ii]) 309 { 310 Error("Column "+fColNames[ii]+" has wrong format ("+fColTypes[ii]+" vs "+mapIt->second->format()+" in file)"); 311 return false; 312 } 313 } 314 } 315 if (!found) 316 { 317 Error("Column "+mapIt->first+" only exist in written file"); 318 return false; 319 } 320 } 321 //now we know that all the file's columns are requested. Let's do it the other way around 322 for (unsigned int ii=0;ii<fColNames.size();ii++) 323 { 324 bool found = false; 325 for (map<string, CCfits::Column*>::const_iterator mapIt = cMap.begin(); mapIt != cMap.end(); mapIt++) 326 { 327 if (fColNames[ii] == mapIt->first) 328 { 329 found = true; 330 if (fColTypes[ii] != mapIt->second->format()) 331 { 332 Error("Column "+fColNames[ii]+" has wrong format ("+fColTypes[ii]+" vs "+mapIt->second->format()+" in file)"); 333 return false; 334 } 335 } 336 } 337 if (!found) 338 { 339 Error("Column "+fColNames[ii]+" only exist in requested description"); 340 return false; 341 } 342 } 301 343 302 344 for (map<string,CCfits::Column*>::const_iterator cMapIt = cMap.begin(); -
trunk/FACT++/src/datalogger.cc
r14574 r14715 131 131 ///the converter for outputting the data according to the format 132 132 shared_ptr<Converter> fConv; 133 ///the original format string. So that we can check if format is changing over time 134 string format; 133 135 ///the current run number used by this subscription 134 136 int32_t runNumber; … … 500 502 void DataLogger::AddService(const Service& svc) 501 503 { 502 const string& server = svc.server; 504 const string& serverr = svc.server; 505 //FIX in order to get rid of the '+' that sometimes makes it all the way to me 506 string server = serverr; 507 if (server.size() > 0 && server[0] == '+') 508 Error("Got a service beginning with +. This is not supposed to happen"); 503 509 const string& service = svc.service; 504 510 const bool isCmd = svc.iscmd; … … 518 524 if (list.find(service) != list.end()) 519 525 { 520 // Error("Service " + server + "/" + service + " is already in the dataLogger's list... ignoring update."); 526 if (list[service].format != svc.format) 527 { 528 cout << "Format has changed ! taking appropriate measures" << endl; 529 if (list[service].nightlyFile.IsOpen()) 530 { 531 string fileName = list[service].nightlyFile.GetName(); 532 if (fileName == "") 533 { 534 cout << "Something went wrong." << endl; 535 return; 536 } 537 list[service].nightlyFile.Close(); 538 string fileNameWithoutFits = fileName.substr(0, fileName.size()-4); 539 int counter=0; 540 while (counter < 100) 541 { 542 ostringstream newFileName; 543 newFileName << fileNameWithoutFits << counter << ".fits"; 544 ifstream testStream(newFileName.str()); 545 if (!testStream) //fileName available 546 { 547 rename(fileName.c_str(), newFileName.str().c_str()); 548 break; 549 } 550 counter++; 551 } 552 if (counter==100) 553 Error("Tried to find a replacement file for 100 trials. Aborting"); 554 //reallocate the fits buffer... 555 list[service].fitsBufferAllocated = false; 556 } 557 list[service].fConv = shared_ptr<Converter>(new Converter(Out(), svc.format)); 558 list[service].format = svc.format; 559 } 560 if (fDebugIsOn) 561 Debug("Service " + server + "/" + service + " is already in the dataLogger's list... ignoring update."); 521 562 return; 522 563 } … … 529 570 list[service].server = server; 530 571 list[service].service = service; 572 list[service].format = svc.format; 531 573 list[service].index = servicesCounter; 532 574 fNumSubAndFitsData.numSubscriptions++; … … 1106 1148 fRunNumber.back().time = time; 1107 1149 1108 ostringstream str; 1109 str << "The new run number is: " << fRunNumber.back().runNumber; 1110 Message(str); 1111 1150 if (fDebugIsOn) 1151 { 1152 ostringstream str; 1153 str << "The new run number is: " << fRunNumber.back().runNumber; 1154 Debug(str); 1155 } 1112 1156 if (GetCurrentState() != kSM_Logging && GetCurrentState() != kSM_WaitingRun ) 1113 1157 return; … … 1241 1285 const Time cTime(evt.GetTime()); 1242 1286 fQuality = evt.GetQoS(); 1243 /* //I had strange surprises with the quality from Dim before. Double check that the value is indeed valid. 1244 if (fQuality != kMessage && 1245 fQuality != kInfo && 1246 fQuality != kWarn && 1247 fQuality != kError && 1248 fQuality != kFatal && 1249 fQuality != kComment && 1250 fQuality != kDebug) 1251 fQuality = kError; 1252 */ 1287 1253 1288 fMjD = cTime.Mjd() ? cTime.Mjd()-40587 : 0; 1254 1289
Note:
See TracChangeset
for help on using the changeset viewer.