Changeset 15060 for trunk/FACT++/src
- Timestamp:
- 03/13/13 15:36:40 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/datalogger.cc
r14992 r15060 145 145 //shared_ptr<DimStampedInfo> dimInfo; 146 146 unsigned int index; 147 ///counter to know if format has changed during operations 148 unsigned int increment; 147 149 148 150 ///Dim info constructor … … 160 162 //dimInfo = shared_ptr<DimStampedInfo>(info); 161 163 index = 0; 164 increment = 0; 162 165 } 163 166 ///default destructor … … 282 285 NumSubAndFitsType fNumSubAndFitsData; 283 286 287 ///Service for broadcasting subscription status 288 DimDescribedService* fCurrentSubscription; 289 ///Number of seconds since the last update of the subscribed list 290 int fCurrentSubscriptionUpdateRate; 291 ///The last time in seconds of the day when the service was update 292 Time fLastSubscriptionUpdate; 293 ///update the service 294 void updateSubscriptionList(); 295 ///set the duration between two updates. a zero or negative value disables the service updates 296 int setSubscriptionListUpdateTimeLapse(const Event& evt); 284 297 /*************************************************** 285 298 * DATA LOGGER's CONFIGURATION STUFF … … 405 418 return GetCurrentState(); 406 419 } 420 /** 421 * UPDATE SUBSCRIPTION LIST. Updates the subscription list service if enough time has passed. 422 * Otherwise does nothing 423 */ 424 void DataLogger::updateSubscriptionList() 425 { 426 if (fCurrentSubscriptionUpdateRate <= 0) return; 427 Time timeNow; 428 //if less than the update rate time has passed, just return 429 if (timeNow - fLastSubscriptionUpdate < boost::posix_time::seconds(fCurrentSubscriptionUpdateRate)) 430 return; 431 //TODO remove me ! 432 // cout << "Updating subscription list with: " << endl; 433 434 fLastSubscriptionUpdate = timeNow; 435 436 //update service ! 437 ostringstream output; 438 for (auto serverIt=fServiceSubscriptions.begin();serverIt!=fServiceSubscriptions.end(); serverIt++) 439 { 440 if (serverIt->first == "DATA_LOGGER") 441 continue; 442 for (auto serviceIt=serverIt->second.begin(); serviceIt!=serverIt->second.end(); serviceIt++) 443 { 444 output << serverIt->first << "/" << serviceIt->first << ","; 445 if (serviceIt->second.lastReceivedEvent != Time::None) 446 output << (timeNow - serviceIt->second.lastReceivedEvent).total_seconds(); 447 else 448 output << "-1"; 449 output << "\n"; 450 } 451 } 452 //TODO remove me ! 453 //cout << output.str(); 454 fCurrentSubscription->setData(output.str().c_str(), output.str().size()+1); 455 fCurrentSubscription->setQuality(0); 456 fCurrentSubscription->Update(); 457 } 458 int DataLogger::setSubscriptionListUpdateTimeLapse(const Event& evt) 459 { 460 fCurrentSubscriptionUpdateRate = evt.GetInt(); 461 462 return GetCurrentState(); 463 } 407 464 vector<Description> DataLogger::GetDescription(const string& server, const string& service) 408 465 { … … 540 597 } 541 598 list[service].nightlyFile.Close(); 542 string fileNameWithoutFits = fileName.substr(0, fileName.size()-4); 599 list[service].increment++; 600 Warn("Format of "+server+"/"+service+" has changed. Closing "+fileName); 601 /* string fileNameWithoutFits = fileName.substr(0, fileName.size()-4); 543 602 int counter=0; 544 603 while (counter < 100) … … 549 608 if (!testStream) //fileName available 550 609 { 551 Warn("Format of "+server+"/"+service+" has changed. Closing "+fileName+" and renaming it to "+newFileName.str());552 610 rename(fileName.c_str(), newFileName.str().c_str()); 553 611 break; … … 557 615 if (counter==100) 558 616 Error("Could not rename "+fileName+" after 100 trials (because of format change). Aborting"); 617 */ 559 618 //reallocate the fits buffer... 560 619 list[service].fitsBufferAllocated = false; … … 895 954 ("Print information about the internal status of the data logger."); 896 955 956 897 957 OpenFileToDim fToDim; 898 958 fToDim.code = 0; … … 920 980 fNumSubAndFitsIsOn = true; 921 981 982 string emptyString=""; 983 //Subscription list service 984 fCurrentSubscription = new DimDescribedService(GetName() + "/SUBSCRIPTIONS", "C", emptyString.c_str(), 985 "List of all the services subscribed by datalogger, except the ones provided by itself." 986 "|Liste[string]:list of logged services and the delay in seconds since last update"); 987 fCurrentSubscriptionUpdateRate = 60; //by default, 1 minute between each update 988 fLastSubscriptionUpdate = timeNow; 989 922 990 // provide services control commands 923 991 AddEvent("SET_DEBUG_MODE", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready) … … 945 1013 ("Set the timeout delay for old run numbers." 946 1014 "|timeout[min]:Time out in minutes after which files for expired runs are closed."); 1015 //Provide access to the duration between two updates of the service list 1016 AddEvent("SET_SERVICE_LIST_UPDATE_INTERVAL", "I:1", kSM_Ready, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun) 1017 (bind(&DataLogger::setSubscriptionListUpdateTimeLapse, this, placeholders::_1)) 1018 ("Set the min interval between two services-list updates." 1019 "|duration[sec]:The interval between two updates, in seconds."); 947 1020 948 1021 fDestructing = false; … … 1000 1073 delete fOpenedRunFiles; 1001 1074 delete fNumSubAndFits; 1075 delete fCurrentSubscription; 1002 1076 1003 1077 if (fNightlyLogFile.is_open())//this file is the only one that has not been closed by GoToReady … … 1291 1365 fQuality = evt.GetQoS(); 1292 1366 1367 //update subscription last received time 1368 sub.lastReceivedEvent = cTime; 1369 //update subscription list service if required 1370 updateSubscriptionList(); 1371 1293 1372 fMjD = cTime.Mjd() ? cTime.Mjd()-40587 : 0; 1294 1373 … … 1309 1388 ostringstream str; 1310 1389 str << "Parsing service " << evt.GetName(); 1311 str << " failed: " << e.what() << " removing the subscription for now.";1312 Error(str);1390 str << " failed: " << e.what() << " removing the subscription to " << sub.server << "/" << sub.service; 1391 Warn(str); 1313 1392 //remove this subscription from the list. 1314 1393 //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 ! … … 1338 1417 //check if the last received event was before noon and if current one is after noon. 1339 1418 //if so, close the file so that it gets reopened. 1340 sub.lastReceivedEvent = cTime;1419 // sub.lastReceivedEvent = cTime; 1341 1420 if (!sub.nightlyFile.IsOpen()) 1342 1421 if (GetCurrentState() != kSM_Ready) … … 1380 1459 } 1381 1460 1382 sub.lastReceivedEvent = cTime;1461 // sub.lastReceivedEvent = cTime; 1383 1462 if (!sub.nightlyFile.IsOpen()) 1384 1463 if (GetCurrentState() != kSM_Ready) … … 1386 1465 WriteToFITS(sub, evt.GetData()); 1387 1466 } 1388 1389 1467 } 1390 1468 … … 1704 1782 if (!sub.nightlyFile.IsOpen()) 1705 1783 { 1706 const string partialName = CompileFileNameWithPath(fFilePath, serviceName, "fits"); 1784 string incrementedServiceName = serviceName; 1785 if (sub.increment != 0) 1786 { 1787 ostringstream str; 1788 str << "." << sub.increment; 1789 incrementedServiceName += str.str(); 1790 } 1791 const string partialName = CompileFileNameWithPath(fFilePath, incrementedServiceName, "fits"); 1707 1792 1708 1793 const string fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
Note:
See TracChangeset
for help on using the changeset viewer.