Changeset 11405
- Timestamp:
- 07/14/11 11:42:42 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Fits.cc
r11373 r11405 73 73 fDataPointer = dataPointer; 74 74 fDataNumBytes = numDataBytes; 75 } 76 // -------------------------------------------------------------------------- 77 // 78 //! This looks for a suitable table in the fits file, i.e. that corresponds to the name and column names. (no format check yet) 79 //! @param tableName. the base table name to be obtained. If not suitable, numbers are appened to the name 80 //! @param allNames. the name of all columns 81 //! @param allDataTypes. the data types of all columns 82 //! @param allUnits. the units of the columns 83 //! @return a pointer to the newly retrieved/created table 84 // 85 CCfits::Table* Fits::findSuitableTableInFitsFile(const string& tableName,const vector<string>& allNames, const vector<string>& allDataTypes, const vector<string>& allUnits) 86 { 87 const multimap< string, CCfits::ExtHDU * >& extMap = fFile->extension(); 88 for (int i=0;i<100;i++) 89 { 90 if (i==10) 91 fMess->Error("Already 10 different tables with different formats exist in this file. Please consider re-creating the file entirely (i.e. delete it please)"); 92 ostringstream cTableName; 93 cTableName << tableName; 94 if (i != 0) 95 cTableName << "-" << i; 96 //current table name does not exist yet. return its associated fits table newly created 97 if (extMap.find(cTableName.str()) == extMap.end()) 98 { 99 for (multimap<string, CCfits::ExtHDU*>::const_iterator it=extMap.begin(); it!= extMap.end(); it++) 100 fMess->Debug(it->first); 101 return fFile->addTable(cTableName.str(), 0, allNames, allDataTypes, allUnits); 102 } 103 CCfits::Table* cTable; 104 cTable = dynamic_cast<CCfits::Table*>(extMap.find(cTableName.str())->second); 105 106 if (!cTable) 107 return NULL;//something wrong happened while getting the table pointer 108 109 //now check that the table columns are the same as the service columns 110 cTable->makeThisCurrent(); 111 const map<string, Column*> cMap = cTable->column(); 112 for (unsigned int j=0;j<allNames.size();j++) 113 if (cMap.find(allNames[j]) == cMap.end()) 114 continue; 115 116 return cTable; 117 } 118 fMess->Error("One hundred trials for new table format failed. aborting"); 119 return NULL; 75 120 } 76 121 // -------------------------------------------------------------------------- … … 152 197 fFile->read(tryToLoadName); 153 198 154 const multimap< string, CCfits::ExtHDU * >& extMap = fFile->extension(); 155 if (extMap.find(tableName) == extMap.end()) 156 { 157 for (multimap<string, CCfits::ExtHDU*>::const_iterator it=extMap.begin(); it!= extMap.end(); it++) 158 fMess->Debug(it->first); 159 fTable = fFile->addTable(tableName, 0, allNames, allDataTypes, allUnits); 160 } 161 else 162 { 163 fTable = dynamic_cast<CCfits::Table*>(extMap.find(tableName)->second); 164 } 199 // const multimap< string, CCfits::ExtHDU * >& extMap = fFile->extension(); 200 // if (extMap.find(tableName) == extMap.end()) 201 // { 202 // for (multimap<string, CCfits::ExtHDU*>::const_iterator it=extMap.begin(); it!= extMap.end(); it++) 203 // fMess->Debug(it->first); 204 // fTable = fFile->addTable(tableName, 0, allNames, allDataTypes, allUnits); 205 // } 206 // else 207 // { 208 // fTable = dynamic_cast<CCfits::Table*>(extMap.find(tableName)->second); 209 // } 210 fTable = findSuitableTableInFitsFile(tableName, allNames, allDataTypes, allUnits); 211 165 212 if (!fTable) 166 213 { … … 188 235 const map<string, Column*> cMap = fTable->column(); 189 236 190 237 for (map<string, Column*>::const_iterator cMapIt = cMap.begin(); cMapIt != cMap.end(); cMapIt++) 191 238 { 192 239 if (!cMapIt->second->isRead()) … … 349 396 delete fFile; 350 397 351 fMess->Info("Closed: "+fFileName); 398 fMess->Info("Closed: "+fFileName); 399 if (fNumOpenFitsFiles != NULL) 400 (*fNumOpenFitsFiles)--; 352 401 } 353 402 fFile = NULL; … … 355 404 delete [] fCopyBuffer; 356 405 fCopyBuffer = NULL; 357 if (fOwner && fNumOpenFitsFiles != NULL) 358 (*fNumOpenFitsFiles)--; 406 359 407 //fMess is the MessageImp part of the dataLogger itself. Thus it should NOT be deleted by the Fits files destructor. 360 408 // if (fMess) -
trunk/FACT++/src/Fits.h
r11015 r11405 107 107 template <typename T> 108 108 bool WriteSingleHeaderKey(const string &name, const T &value, const string &comment); 109 CCfits::Table* findSuitableTableInFitsFile(const string& tableName,const vector<string>& allNames, const vector<string>& allDataTypes, const vector<string>& allUnits); 109 110 110 111 };//Fits -
trunk/FACT++/src/datalogger.cc
r11347 r11405 506 506 void DataLogger::RemoveService(const string& server, const string& service, bool isCmd) 507 507 { 508 if (fDestructing)//this function is called by the super class, after the destructor has deleted its own subscriptions 509 return; 510 508 511 if (isCmd) 509 512 return; … … 1052 1055 { 1053 1056 if (fDebugIsOn) 1054 {1055 1057 Debug("DataLogger destruction starts"); 1056 } 1058 1059 //this boolean should not be required anymore, because it 1057 1060 fDestructing = true; 1058 //first let's go to the ready state 1059 GoToReadyPlease(); 1061 1062 //first, let's backup the datalogger/message service subscription 1063 shared_ptr<DimStampedInfo> messageBackup; 1064 bool dataloggerMessageFound = false; 1065 SubscriptionsListType::iterator x; 1066 map<string, SubscriptionType>::iterator y; 1067 x = fServiceSubscriptions.find("DATA_LOGGER"); 1068 if (x != fServiceSubscriptions.end()) 1069 { 1070 y = x->second.find("MESSAGE"); 1071 if (y != x->second.end()) 1072 { 1073 dataloggerMessageFound = true; 1074 messageBackup = y->second.dimInfo; 1075 } 1076 } 1077 1060 1078 dim_lock(); 1061 //release the services subscriptions 1079 1080 //now clear the services subscriptions 1062 1081 fServiceSubscriptions.clear(); 1063 1082 1064 1083 //clear any remaining run number (should remain only one) 1065 1084 while (fRunNumber.size() > 0) 1066 1085 { 1067 1086 RemoveOldestRunNumber(); 1068 } 1069 // dim_unlock(); 1087 } 1088 //go to the ready state. i.e. close all files, run-wise first 1089 GoToReadyPlease(); 1090 1091 dim_unlock(); 1092 1093 Info("Will soon close the daily log file"); 1094 1070 1095 delete fOpenedNightlyFiles; 1071 1096 delete fOpenedRunFiles; 1072 1097 delete fNumSubAndFits; 1073 // delete fStatsMonitoring; 1098 1099 //release message service before closing nightly log file 1100 if (dataloggerMessageFound) 1101 messageBackup.reset(); 1102 1103 if (fNightlyLogFile.is_open())//this file is the only one that has not been closed by GoToReadyPlease 1104 { 1105 dim_lock(); 1106 fNightlyLogFile.close(); 1107 dim_unlock(); 1108 } 1074 1109 1075 1110 if (fDebugIsOn) 1076 {1077 1111 Debug("DataLogger desctruction ends"); 1078 }1079 1112 } 1080 1113 // -------------------------------------------------------------------------- … … 1133 1166 void DataLogger::infoHandler() 1134 1167 { 1135 // Make sure getTimestamp is called _before_ getTimestampMillisecs1136 if (fDestructing)1137 return;1138 1139 1168 DimInfo* I = getInfo(); 1140 1169 … … 1360 1389 const bool isItaReport = fmt!="C"; 1361 1390 1362 if (!fNightly ReportFile.is_open())1391 if (!fNightlyLogFile.is_open()) 1363 1392 return; 1364 1393 … … 1481 1510 ostringstream str; 1482 1511 str << "Parsing service " << sub.dimInfo->getName(); 1483 str << " failed: " << e.what() ;1512 str << " failed: " << e.what() << " removing the subscription for now."; 1484 1513 Error(str); 1485 // if (fDebugIsOn) 1486 // { 1487 // ostringstream str2; 1488 // str2 << sub.dimInfo->getString() << "\n"; 1489 // Debug(str2); 1490 // } 1514 //remove this subscription from the list. 1515 //because these operators use references to elements, and because they're supposed here to erase these objects on the way, I'm not too sure... so duplicate the names ! 1516 string server = sub.server; 1517 string service = sub.service; 1518 fServiceSubscriptions.find(server)->second.erase(service); 1491 1519 return; 1492 1520 } … … 1533 1561 else 1534 1562 {//write entry to both Nightly and run logs 1535 vector<string> strings = sub.fConv->ToStrings(I->getData()); 1563 vector<string> strings; 1564 try 1565 { 1566 strings = sub.fConv->ToStrings(I->getData()); 1567 } 1568 catch (const runtime_error &e) 1569 { 1570 ostringstream str; 1571 str << "Parsing service " << sub.dimInfo->getName(); 1572 str << " failed: " << e.what() << " removing the subscription for now."; 1573 Error(str); 1574 //remove this subscription from the list. 1575 //because these operators use references to elements, and because they're supposed here to erase these objects on the way, I'm not too sure... so duplicate the names ! 1576 string server = sub.server; 1577 string service = sub.service; 1578 fServiceSubscriptions.find(server)->second.erase(service); 1579 return; 1580 } 1536 1581 if (strings.size() > 1) 1537 1582 { … … 2443 2488 // dim_lock(); 2444 2489 const string baseFileName = CompileFileNameWithPath(fNightlyFilePath, "", ""); 2445 if (fNightlyLogFile.is_open() )2490 if (fNightlyLogFile.is_open() && !fDestructing)//in case we're destructing the datalogger, wait before closing the log file. 2446 2491 { 2447 2492 fNightlyLogFile.close();
Note:
See TracChangeset
for help on using the changeset viewer.