Changeset 10489 for trunk/FACT++/src
- Timestamp:
- 04/29/11 10:19:46 (14 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Fits.cc
r10442 r10489 79 79 //! @param file a pointer to an existing FITS file. If NULL, file will be opened and managed internally 80 80 // 81 void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file )81 void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file, int* fitsCounter, std::ostream& out) 82 82 { 83 if (fMess) 84 delete fMess; 85 fMess = new MessageImp(out); 86 83 87 fFileName = fileName; 84 88 if (file == NULL) … … 88 92 fFile = new FITS(fileName, RWmode::Write); 89 93 } 90 catch (FITS::CantOpen) 91 { 92 std::ostringstream err; 93 err << "Could not open " << fileName << ".Skipping it."; 94 throw runtime_error(err.str()); 94 catch (CCfits::FitsError e) 95 { 96 std::stringstream str; 97 str << "Could not open FITS file " << fileName << " reason: " << e.message(); 98 fMess->Error(str); 99 fFile = NULL; 100 return; 95 101 } 96 102 fOwner = true; 103 fNumOpenFitsFiles = fitsCounter; 104 (*fNumOpenFitsFiles)++; 97 105 } 98 106 else … … 133 141 try 134 142 { 135 fTable = fFile->addTable(tableName, 0, allNames, allDataTypes, allUnits); 143 std::string factTableName = "FACT-" + tableName; 144 fTable = fFile->addTable(factTableName, 0, allNames, allDataTypes, allUnits); 136 145 fCopyBuffer = new unsigned char[fTotalNumBytes]; 137 146 fNumRows = fTable->rows(); … … 153 162 catch(CCfits::FitsError e) 154 163 { 155 std::ostringstream err; 156 err << "Error when adding table " << tableName << " : " << e.message(); 157 throw runtime_error(err.str()); 164 std::stringstream str; 165 str << "Could not open or create FITS table " << tableName << " in file " << fileName << " reason: " << e.message(); 166 fMess->Error(str); 167 fTable = NULL; 158 168 } 159 169 160 f EndMjD = * static_cast<double*>(fStandardPointers[0]);170 fRefMjD = * static_cast<double*>(fStandardPointers[0]); 161 171 if (!updating) 162 172 WriteHeaderKeys(); … … 168 178 void Fits::WriteHeaderKeys() 169 179 { 180 if (!fTable) 181 return; 170 182 std::string name; 171 183 std::string comment; … … 174 186 double doubleValue; 175 187 std::string stringValue; 188 try 189 { 190 name = "EXTREL"; 191 comment = "Release Number"; 192 floatValue = 1.0f; 193 fTable->addKey(name, floatValue, comment); 194 195 name = "BASETYPE"; 196 comment = "Base type of the data structure"; 197 stringValue = "??????"; 198 fTable->addKey(name, stringValue, comment); 199 200 name = "TELESCOP"; 201 comment = "Telescope that acquired this data"; 202 stringValue = "FACT"; 203 fTable->addKey(name, stringValue, comment); 204 205 name = "ORIGIN"; 206 comment = "Institution that wrote the file"; 207 stringValue = "ISDC"; 208 fTable->addKey(name, stringValue, comment); 209 210 name = "CREATOR"; 211 comment = "Program that wrote this file"; 212 stringValue = "FACT++_DataLogger"; 213 fTable->addKey(name, stringValue, comment); 214 215 name = "DATE"; 216 stringValue = Time().GetAsStr(); 217 stringValue[10] = 'T'; 218 comment = "File creation date"; 219 fTable->addKey(name, stringValue, comment); 220 221 name = "TIMESYS"; 222 stringValue = "TT"; 223 comment = "Time frame system"; 224 fTable->addKey(name, stringValue, comment); 225 226 name = "TIMEUNIT"; 227 stringValue = "d"; 228 comment = "Time unit"; 229 fTable->addKey(name, stringValue, comment); 230 231 name = "TIMEREF"; 232 stringValue = "UTC"; 233 comment = "Time reference frame"; 234 fTable->addKey(name, stringValue, comment); 176 235 177 name = "EXTREL"; 178 comment = "Release Number"; 179 floatValue = 1.0f; 180 fTable->addKey(name, floatValue, comment); 181 182 name = "BASETYPE"; 183 comment = "Base class that wrote this file"; 184 stringValue = "CCFits_table"; 185 fTable->addKey(name, stringValue, comment); 186 187 name = "TELESCOP"; 188 comment = "Telescope that acquired this data"; 189 stringValue = "FACT"; 190 fTable->addKey(name, stringValue, comment); 191 192 name = "ORIGIN"; 193 comment = "Institution that wrote the file"; 194 stringValue = "ISDC"; 195 fTable->addKey(name, stringValue, comment); 196 197 name = "CREATOR"; 198 comment = "Program that wrote this file"; 199 stringValue = "FACT++_DataLogger"; 200 fTable->addKey(name, stringValue, comment); 201 202 name = "DATE"; 203 stringValue = Time().GetAsStr(); 204 stringValue[10] = 'T'; 205 comment = "File creation date"; 206 fTable->addKey(name, stringValue, comment); 207 208 name = "TIMEREF"; 209 stringValue = "UTC"; 210 comment = "Time reference system"; 211 fTable->addKey(name, stringValue, comment); 212 213 name = "TSTART"; 214 doubleValue = fEndMjD; 215 comment = "Time of the first received data"; 216 fTable->addKey(name, doubleValue, comment); 217 236 name = "MJDREF"; 237 doubleValue = fRefMjD; 238 comment = "Modified Julian Date of origin"; 239 fTable->addKey(name, doubleValue, comment); 240 } 241 catch (CCfits::FitsError e) 242 { 243 std::stringstream str; 244 str << "Could not add header keys in file " << fFileName << " reason: " << e.message(); 245 fMess->Error(str); 246 } 218 247 //More ? 219 248 } … … 233 262 catch(CCfits::FitsError e) 234 263 { 235 std:: ostringstream err;236 err << "Error when inserting a row: " << e.message();237 throw runtime_error(err.str());264 std::stringstream str; 265 str << "Could not insert row in file " << fFileName << " reason: " << e.message(); 266 fMess->Error(str); 238 267 } 239 268 fNumRows++; 240 269 241 270 //the first standard variable is the current MjD 271 if (fEndMjD == 0) 272 { 273 std::string name = "TSTART"; 274 double doubleValue = *static_cast<double*>(fStandardPointers[0]) - fRefMjD; 275 std::string comment = "Time of the first received data"; 276 fTable->addKey(name, doubleValue, comment); 277 } 242 278 fEndMjD = * static_cast<double*>(fStandardPointers[0]); 243 279 … … 259 295 //TODO check the status after the write operation 260 296 fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status); 261 297 if (status) 298 { 299 char text[30];//max length of cfitsio error strings (from doc) 300 fits_get_errstatus(status, text); 301 std::stringstream str; 302 str << "Error while writing FITS row in " << fFileName << ". Message: " << text << " [" << status << "]"; 303 fMess->Error(str); 304 } 262 305 //This forces the writting of each row to the disk. Otherwise all rows are written when the file is closed. 263 306 ///TODO check whether this consumes too much resources or not. If it does, flush every N write operations instead 264 fFile->flush(); 307 try 308 { 309 fFile->flush(); 310 } 311 catch (CCfits::FitsError e) 312 { 313 std::stringstream str; 314 str << "Error while flushing bytes to disk. File: " << fFileName << " reason: " << e.message(); 315 fMess->Error(str); 316 } 265 317 } 266 318 // -------------------------------------------------------------------------- … … 274 326 // if (fTable != NULL) 275 327 // delete fTable; 276 277 328 std::string name = "TEND"; 278 double doubleValue = fEndMjD ;329 double doubleValue = fEndMjD - fRefMjD; 279 330 std::string comment = "Time of the last received data"; 280 331 fTable->addKey(name, doubleValue, comment); … … 286 337 delete [] fCopyBuffer; 287 338 fCopyBuffer = NULL; 339 if (fOwner && fNumOpenFitsFiles != NULL) 340 (*fNumOpenFitsFiles)--; 341 if (fMess) 342 delete fMess; 343 fMess = NULL; 288 344 } 289 345 -
trunk/FACT++/src/Fits.h
r10442 r10489 6 6 7 7 #include "Description.h" 8 8 #include "MessageImp.h" 9 9 using namespace CCfits; 10 10 … … 46 46 ///to keep track of the time of the latest written entry (to update the header when closing the file) 47 47 double fEndMjD; 48 ///to keep track of the reference MjD 49 double fRefMjD; 48 50 ///Write the FITS header keys 49 51 void WriteHeaderKeys(); 50 52 public: 53 ///Name of the openned file. For querying stats 54 std::string fFileName; 55 private: 56 ///Keep track of number of opened fits 57 int* fNumOpenFitsFiles; 58 ///were to log the errors 59 MessageImp* fMess; 51 60 public: 52 61 … … 60 69 fTotalNumBytes(0), 61 70 fEndMjD(0.0), 62 fFileName("") 71 fRefMjD(0.0), 72 fFileName(""), 73 fNumOpenFitsFiles(NULL), 74 fMess(NULL) 63 75 {} 64 76 … … 78 90 79 91 ///Opens a FITS file 80 void Open(const std::string& fileName, const std::string& tableName, FITS* file );92 void Open(const std::string& fileName, const std::string& tableName, FITS* file, int* fitsCounter, std::ostream& out); 81 93 82 94 ///Write one line of data. Use the given converter. … … 88 100 ///Get the size currently written on the disk 89 101 int GetWrittenSize(); 90 ///Name of the openned file. For querying stats91 std::string fFileName;92 102 93 103 };//Fits -
trunk/FACT++/src/dataLogger.cc
r10488 r10489 85 85 int numOpenFits; 86 86 }; 87 87 //For debugging DIM's services 88 class MyService 89 { 90 public: 91 MyService(){}; 92 MyService(std::string, std::string, void*, int){}; 93 MyService(std::string, const char*){}; 94 void updateService(){}; 95 void updateService(void*, int){}; 96 void setQuality(int){}; 97 }; 88 98 class DataLogger : public StateMachineDim, DimInfoHandler 89 99 { … … 136 146 static const char* fTransWait; 137 147 static const char* fRunNumberInfo; ///< This is the name of the dimInfo received to specify the run number. It must be updated once the final name will be defined 138 ///Inherited from state machine impl139 //int Execute();140 141 ///Inherited from state machine impl142 //int Transition(const Event& evt);143 144 ///Inherited from state machine impl145 //int Configure(const Event& evt);146 148 147 149 //overloading of DIM's infoHandler function … … 293 295 long long fBaseSizeRun; 294 296 ///Service for opened files 295 Dim Service* fOpenedDailyFiles;296 Dim Service* fOpenedRunFiles;297 Dim Service* fNumSubAndFits;297 DimDescribedService* fOpenedDailyFiles; 298 DimDescribedService* fOpenedRunFiles; 299 DimDescribedService* fNumSubAndFits; 298 300 NumSubAndFitsType fNumSubAndFitsData; 299 301 // char* fDimBuffer; 300 302 inline void NotifyOpenedFile(std::string name, int type, DimService* service); 303 inline void NotifyOpenedFile(std::string , int , MyService* ){} 301 304 302 305 }; //DataLogger … … 334 337 // DimDescribedService srvc((GetName()+"/STATS").c_str(), "x:2;l:1", &statVar, dataSize,//static_cast<void*>(data), dataSize, 335 338 // "Add description here"); 336 Dim Service srvc ("DATA_LOGGER/STATS", "x:2;l:1", &statVar, dataSize);339 DimDescribedService srvc ("DATA_LOGGER/STATS", "X:2;L:1", &statVar, dataSize, "Add description here"); 337 340 double deltaT = 1; 338 341 fPreviousSize = 0; 342 bool statWarning = false; 339 343 //loop-wait for broadcast 340 344 while (fContinueMonitoring) … … 384 388 385 389 if (!statvfs(fDailyFileName.c_str(), &vfs)) 390 { 386 391 statVar.freeSpace = vfs.f_bsize*vfs.f_bavail; 392 statWarning = false; 393 } 387 394 else 395 { 396 std::stringstream str; 397 str << "Unable to retrieve stats for " << fDailyFileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 398 if (!statWarning) 399 Error(str); 400 statWarning = true; 388 401 statVar.freeSpace = -1; 402 } 389 403 390 404 //sum up all the file sizes. past and present … … 416 430 { 417 431 //initialize member data 418 fDailyFileName = " /home/lyard/log";//".";419 fRunFileName = " /home/lyard/log";//".";432 fDailyFileName = ".";//"/home/lyard/log";// 433 fRunFileName = ".";//"/home/lyard/log"; 420 434 fRunNumber = 12345; 421 435 #ifdef HAS_FITS … … 433 447 /*Add the possible transitions for this machine*/ 434 448 AddTransition(kSM_DailyOpen, fTransStart, kSM_Ready, kSM_BadDailyConfig) 435 (boost::bind(&DataLogger::StartPlease, this)) ;436 //("start the daily logging. daily file location must be specified already");449 (boost::bind(&DataLogger::StartPlease, this)) 450 ("start the daily logging. daily file location must be specified already"); 437 451 438 452 AddTransition(kSM_Ready, fTransStop, kSM_DailyOpen, kSM_WaitingRun, kSM_Logging) 439 (boost::bind(&DataLogger::GoToReadyPlease, this)) ;440 //("stop the data logging");453 (boost::bind(&DataLogger::GoToReadyPlease, this)) 454 ("stop the data logging"); 441 455 442 456 AddTransition(kSM_Logging, fTransStartRun, kSM_WaitingRun, kSM_BadRunConfig) 443 (boost::bind(&DataLogger::StartRunPlease, this)) ;444 //("start the run logging. run file location must be specified already.");457 (boost::bind(&DataLogger::StartRunPlease, this)) 458 ("start the run logging. run file location must be specified already."); 445 459 446 460 AddTransition(kSM_WaitingRun, fTransStopRun, kSM_Logging) 447 (boost::bind(&DataLogger::StopRunPlease, this)) ;448 //("");461 (boost::bind(&DataLogger::StopRunPlease, this)) 462 (""); 449 463 450 464 AddTransition(kSM_Ready, fTransReset, kSM_Error, kSM_BadDailyConfig, kSM_BadRunConfig, kSM_Error) 451 (boost::bind(&DataLogger::GoToReadyPlease, this)) ;452 //("transition to exit error states. dunno if required or not, would close the daily file if already openned.");465 (boost::bind(&DataLogger::GoToReadyPlease, this)) 466 ("transition to exit error states. dunno if required or not, would close the daily file if already openned."); 453 467 454 468 AddTransition(kSM_WaitingRun, fTransWait, kSM_DailyOpen) … … 458 472 459 473 AddConfiguration(fConfigDay, "C", kSM_Ready, kSM_BadDailyConfig) 460 (boost::bind(&DataLogger::ConfigureDailyFileName, this, _1)) ;;461 //("configure the daily file location. cannot be done before the file is actually opened");474 (boost::bind(&DataLogger::ConfigureDailyFileName, this, _1)) 475 ("configure the daily file location. cannot be done before the file is actually opened"); 462 476 463 477 AddConfiguration(fConfigRun, "C", kSM_Ready, kSM_BadDailyConfig, kSM_DailyOpen, kSM_WaitingRun, kSM_BadRunConfig) 464 (boost::bind(&DataLogger::ConfigureRunFileName, this, _1)) ;465 //("configure the run file location. cannot be done before the file is actually opened, and not in a dailly related error.");478 (boost::bind(&DataLogger::ConfigureRunFileName, this, _1)) 479 ("configure the run file location. cannot be done before the file is actually opened, and not in a dailly related error."); 466 480 467 481 //Provide a logging command … … 481 495 fBaseSizeDaily = 0; 482 496 fBaseSizeRun = 0; 483 //start the open files service484 // fDimBuffer = new char[256];485 // memset(fDimBuffer, 0, sizeof(int));486 // fDimBuffer[sizeof(int)] = '\0';487 497 488 498 //gives the entire buffer size. Otherwise, dim overwrites memory at bizarre locations if smaller size is given at creation time. 489 499 // fOpenedFiles = new DimDescribedService((GetName()+"/FILENAME").c_str(), "i:1;C", static_cast<void*>(fDimBuffer), 256, "Add description here"); 490 fOpenedDailyFiles = new Dim Service((GetName() + "/FILENAME_DAILY").c_str(), const_cast<char*>(""));//"i:1;C", static_cast<void*>(fDimBuffer), 256);491 fOpenedRunFiles = new Dim Service((GetName() + "/FILENAME_RUN").c_str(), const_cast<char*>(""));500 fOpenedDailyFiles = new DimDescribedService((GetName() + "/FILENAME_DAILY").c_str(), const_cast<char*>(""), "Add description here");//"i:1;C", static_cast<void*>(fDimBuffer), 256); 501 fOpenedRunFiles = new DimDescribedService((GetName() + "/FILENAME_RUN").c_str(), const_cast<char*>(""), "Add description here"); 492 502 fOpenedDailyFiles->setQuality(0); 493 503 fOpenedRunFiles->setQuality(0); … … 496 506 fNumSubAndFitsData.numSubscriptions = 0; 497 507 fNumSubAndFitsData.numOpenFits = 0; 498 fNumSubAndFits = new Dim Service((GetName() + "/NUM_SUBS").c_str(), "i:2", &fNumSubAndFitsData, sizeof(NumSubAndFitsType));508 fNumSubAndFits = new DimDescribedService((GetName() + "/NUM_SUBS").c_str(), "I:2", &fNumSubAndFitsData, sizeof(NumSubAndFitsType), "Add description here"); 499 509 500 510 } … … 527 537 } 528 538 529 } 539 } 530 540 for (std::vector<std::string>::const_iterator it = toBeDeleted.begin(); it != toBeDeleted.end(); it++) 531 541 fServiceSubscriptions.erase(*it); … … 620 630 #endif 621 631 } 622 /* 623 // -------------------------------------------------------------------------- 624 // 625 //! Execute 626 //! Shouldn't be run as we use callbacks instead 627 // 628 int DataLogger::Execute() 629 { 630 //due to the callback mecanism, this function should never be called 631 return kSM_FatalError; 632 633 switch (GetCurrentState()) 634 { 635 case kSM_Error: 636 case kSM_Ready: 637 case kSM_DailyOpen: 638 case kSM_WaitingRun: 639 case kSM_Logging: 640 case kSM_BadDailyConfig: 641 case kSM_BadRunConfig: 642 return GetCurrentState(); 643 } 644 //this line below should never be hit. It here mainly to remove warnings at compilation 645 return kSM_FatalError; 646 } 647 // -------------------------------------------------------------------------- 648 // 649 //! Shouldn't be run as we use callbacks instead 650 // 651 int DataLogger::Transition(const Event& evt) 652 { 653 //due to the callback mecanism, this function should never be called 654 return kSM_FatalError; 655 656 switch (evt.GetTargetState()) 657 { 658 case kSM_Ready: 659 //here we must figure out whether the STOP or RESET command was sent 660 //close opened files and go back to ready state 661 switch (GetCurrentState()) 662 { 663 case kSM_BadDailyConfig: 664 case kSM_BadRunConfig: 665 case kSM_Error: 666 return GoToReadyPlease(); 667 668 case kSM_Logging: 669 case kSM_WaitingRun: 670 case kSM_DailyOpen: 671 return GoToReadyPlease(); 672 } 673 break; 674 675 case kSM_DailyOpen: 676 //Attempt to open the daily file 677 switch (GetCurrentState()) 678 { 679 case kSM_Ready: 680 case kSM_BadDailyConfig: 681 return StartPlease(); 682 } 683 break; 684 685 case kSM_WaitingRun: 686 //either close the run file, or just go to the waitingrun state (if coming from daily open 687 switch (GetCurrentState()) 688 { 689 case kSM_DailyOpen: 690 return kSM_WaitingRun; 691 692 case kSM_Logging: 693 return StopRunPlease(); 694 } 695 break; 696 697 case kSM_Logging: 698 //Attempt to open run file 699 switch (GetCurrentState()) 700 { 701 case kSM_WaitingRun: 702 case kSM_BadRunConfig: 703 return StartRunPlease(); 704 } 705 break; 706 } 707 //Getting here means that an invalid transition has been asked. 708 //TODO Log an error message 709 //and return the fatal error state 710 return kSM_FatalError; 711 } 712 // -------------------------------------------------------------------------- 713 // 714 //! Shouldn't be run as we use callbacks instead 715 // 716 int DataLogger::Configure(const Event& evt) 717 { 718 //due to the callback mecanism, this function should never be called 719 return kSM_FatalError; 720 721 switch (evt.GetTargetState()) 722 { 723 case kSM_Ready: 724 case kSM_BadDailyConfig: 725 return ConfigureDailyFileName(evt); 726 break; 727 728 case kSM_WaitingRun: 729 case kSM_BadRunConfig: 730 return ConfigureRunFileName(evt); 731 break; 732 733 case kSM_Logging: 734 case kSM_DailyOpen: 735 return 0; 736 break; 737 738 } 739 740 return kSM_FatalError; 741 } 742 */ 632 743 633 // -------------------------------------------------------------------------- 744 634 // … … 827 717 if (!sub.fConv) 828 718 { 829 Error("Couldn't properly parse the format... service ignored."); 719 std::stringstream str; 720 str << "Couldn't properly parse the format... service " << sub.dimInfo->getName() << " ignored."; 721 Error(str); 830 722 return; 831 723 } … … 854 746 { 855 747 Out() << kRed << e.what() << endl; 856 Error("Couldn't properly parse the data... ignored."); 748 std::stringstream str; 749 str << "Could not properly parse the data for service " << sub.dimInfo->getName(); 750 str << " reason: " << e.what() << ". Entry ignored"; 751 Error(str); 857 752 return; 858 753 } 859 754 860 755 if (text.empty()) 756 { 757 std::stringstream str; 758 str << "Service " << sub.dimInfo->getName() << " sent an empty string"; 759 Info(str); 861 760 return; 862 761 } 863 762 //replace bizarre characters by white space 864 763 replace(text.begin(), text.end(), '\n', '\\'); 865 764 replace_if(text.begin(), text.end(), std::ptr_fun<int, int>(&std::iscntrl), ' '); 866 867 if (fDailyReportFile.is_open()) 868 fDailyReportFile << header.str(); 869 if (fRunReportFile.is_open()) 870 fRunReportFile << header.str(); 871 872 if (fDailyReportFile.is_open()) 873 fDailyReportFile << text << std::endl; 874 if (fRunReportFile.is_open()) 875 fRunReportFile << text << std::endl; 765 766 //write entry to daily report 767 try 768 { 769 if (fDailyReportFile.is_open()) 770 fDailyReportFile << header.str() << text << std::endl; 771 } 772 catch (std::exception e) 773 { 774 std::stringstream str; 775 str << "Error while writing to daily report file: " << e.what(); 776 Error(str); 777 } 778 //write entry to run-report 779 try 780 { 781 if (fRunReportFile.is_open()) 782 fRunReportFile << header.str() << text << std::endl; 783 } 784 catch (std::exception e) 785 { 786 std::stringstream str; 787 str << "Error while writing to run report file: " << e.what(); 788 Error(str); 789 } 876 790 } 877 791 else 878 { 792 {//write entry to both daily and run logs 879 793 std::string n = I->getName(); 880 794 std::stringstream msg; 881 795 msg << n.substr(0, n.find_first_of('/')) << ": " << I->getString(); 882 MessageImp dailyMess(fDailyLogFile); 883 dailyMess.Write(cTime, msg.str().c_str(), fQuality); 796 try 797 { 798 MessageImp dailyMess(fDailyLogFile); 799 dailyMess.Write(cTime, msg.str().c_str(), fQuality); 800 } 801 catch (std::exception e) 802 { 803 std::stringstream str; 804 str << "Error while writing to daily log file: " << e.what(); 805 Error(str); 806 } 884 807 if (fRunLogFile.is_open()) 885 808 { 886 MessageImp runMess(fRunLogFile); 887 runMess.Write(cTime, msg.str().c_str(), fQuality); 809 try 810 { 811 MessageImp runMess(fRunLogFile); 812 runMess.Write(cTime, msg.str().c_str(), fQuality); 813 } 814 catch (std::exception e) 815 { 816 std::stringstream str; 817 str << "Error while writing to run log file: " << e.what(); 818 Error(str); 819 } 888 820 } 889 821 } … … 910 842 // 911 843 //TODO isn't that function not used any longer ? If so I guess that we should get rid of it... 844 //Otherwise re-write it properly with the MessageImp class 912 845 int DataLogger::LogMessagePlease(const Event& evt) 913 846 { … … 969 902 int DataLogger::ConfigureDailyFileName(const Event& evt) 970 903 { 971 std::cout << "Configure Daily File Name" << std::endl;972 904 if (evt.GetText() != NULL) 905 { 973 906 fDailyFileName = std::string(evt.GetText()); 907 Message("New daily folder specified: " + fDailyFileName); 908 } 974 909 else 975 Error("Empty daily folder ");910 Error("Empty daily folder given. Please specify a valid path."); 976 911 977 912 return GetCurrentState(); … … 986 921 int DataLogger::ConfigureRunFileName(const Event& evt) 987 922 { 988 std::cout << "Configure Run File Name" << std::endl;989 923 if (evt.GetText() != NULL) 924 { 990 925 fRunFileName = std::string(evt.GetText()); 926 Message("New Run folder specified: " + fRunFileName); 927 } 991 928 else 992 Error("Empty daily folder ");929 Error("Empty daily folder given. Please specify a valid path"); 993 930 994 931 return GetCurrentState(); … … 1001 938 //! @returns 1002 939 //! currently only the current state 940 //TODO remove this function as the run numbers will be distributed through a dedicated service 1003 941 int DataLogger::ConfigureRunNumber(const Event& evt) 1004 942 { 1005 943 fRunNumber = evt.GetInt(); 1006 1007 944 return GetCurrentState(); 1008 945 } … … 1016 953 inline void DataLogger::NotifyOpenedFile(std::string name, int type, DimService* service) 1017 954 { 1018 //std::cout << "name: " << name << " size: " << name.size() << std::endl;1019 // reinterpret_cast<int*>(fDimBuffer)[0] = type;1020 // strcpy(&fDimBuffer[sizeof(int)], name.c_str());1021 955 service->setQuality(type); 1022 956 service->updateService(const_cast<char*>(name.c_str())); 1023 // fOpenedFiles->updateService(static_cast<void*>(fDimBuffer), name.size() + 1 + sizeof(int));1024 957 } 1025 958 // -------------------------------------------------------------------------- … … 1033 966 { 1034 967 //TODO concatenate the dailyFileName and the formatted date and extension to obtain the full file name 1035 Time time; //(Time::utc);968 Time time; 1036 969 std::stringstream sTime; 1037 970 sTime << time.Y() << "_" << time.M() << "_" << time.D(); 971 1038 972 fFullDailyLogFileName = fDailyFileName + '/' + sTime.str() + ".log"; 1039 1040 fDailyLogFile.open(fFullDailyLogFileName.c_str(), std::ios_base::out | std::ios_base::app); //maybe should be "app" instead of "ate" ?? 973 fDailyLogFile.open(fFullDailyLogFileName.c_str(), std::ios_base::out | std::ios_base::app); 974 if (errno != 0) 975 { 976 std::stringstream str; 977 str << "Unable to open daily Log " << fFullDailyLogFileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 978 Error(str); 979 } 1041 980 fFullDailyReportFileName = fDailyFileName + '/' + sTime.str() + ".rep"; 1042 981 fDailyReportFile.open(fFullDailyReportFileName.c_str(), std::ios_base::out | std::ios_base::app); 1043 982 if (errno != 0) 983 { 984 std::stringstream str; 985 str << "Unable to open daily Report " << fFullDailyReportFileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 986 Error(str); 987 } 988 1044 989 if (!fDailyLogFile.is_open() || !fDailyReportFile.is_open()) 1045 990 { … … 1062 1007 char currentPath[FILENAME_MAX]; 1063 1008 getcwd(currentPath, sizeof(currentPath)); 1009 if (errno != 0) 1010 { 1011 std::stringstream str; 1012 str << "Unable retrieve current path" << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1013 Error(str); 1014 } 1064 1015 actualTargetDir = currentPath; 1065 1016 } … … 1068 1019 actualTargetDir = fDailyFileName; 1069 1020 } 1070 std::cout << actualTargetDir << '/' << sTime.str() << std::endl; 1021 1071 1022 NotifyOpenedFile(actualTargetDir + '/' + sTime.str(), 3, fOpenedDailyFiles); 1072 1023 … … 1108 1059 fFileSizesMap[partialName] = 0; 1109 1060 } 1110 sub.dailyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits );1061 sub.dailyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, Out()); 1111 1062 //notify the opening 1112 1063 std::string actualTargetDir; … … 1153 1104 catch (CCfits::FitsError e) 1154 1105 { 1155 std::ostringstream err; 1156 err << "Could not open run file " << partialName; 1157 throw runtime_error(err.str()); 1106 std::stringstream str; 1107 str << "Could not open FITS Run file " << partialName << " reason: " << e.message(); 1108 Error(str); 1109 fRunFitsFile = NULL; 1158 1110 } 1159 1111 #endif … … 1172 1124 #ifdef ONE_RUN_FITS_ONLY 1173 1125 } 1174 sub.runFile.Open(partialName, serviceName, fRunFitsFile, &fNumSubAndFitsData.numOpenFits );1126 sub.runFile.Open(partialName, serviceName, fRunFitsFile, &fNumSubAndFitsData.numOpenFits, Out()); 1175 1127 #else 1176 sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits );1128 sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, Out()); 1177 1129 #endif //one_run_fits_only 1178 1130 fNumSubAndFits->updateService(); … … 1281 1233 fFullRunLogFileName = fRunFileName + '/' + sRun.str() + ".log"; 1282 1234 fRunLogFile.open(fFullRunLogFileName.c_str(), std::ios_base::out | std::ios_base::app); //maybe should be app instead of ate 1283 1235 if (errno != 0) 1236 { 1237 std::stringstream str; 1238 str << "Unable to open run Log " << fFullRunLogFileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1239 Error(str); 1240 } 1284 1241 fFullRunReportFileName = fRunFileName + '/' + sRun.str() + ".rep"; 1285 1242 fRunReportFile.open(fFullRunReportFileName.c_str(), std::ios_base::out | std::ios_base::app); 1243 if (errno != 0) 1244 { 1245 std::stringstream str; 1246 str << "Unable to open run report " << fFullRunReportFileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1247 Error(str); 1248 } 1286 1249 1287 1250 if (!fRunLogFile.is_open() || !fRunReportFile.is_open()) … … 1296 1259 { 1297 1260 stat(fFullRunLogFileName.c_str(), &st); 1298 fBaseSizeRun += st.st_size; 1261 if (errno != 0) 1262 { 1263 std::stringstream str; 1264 str << "Unable to stat " << fFullRunLogFileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1265 Error(str); 1266 } 1267 else 1268 fBaseSizeRun += st.st_size; 1299 1269 fFileSizesMap[fFullRunLogFileName] = 0; 1300 1270 } … … 1302 1272 { 1303 1273 stat(fFullRunReportFileName.c_str(), &st); 1304 fBaseSizeRun += st.st_size; 1274 if (errno != 0) 1275 { 1276 std::stringstream str; 1277 str << "Unable to stat " << fFullRunReportFileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1278 Error(str); 1279 } 1280 else 1281 fBaseSizeRun += st.st_size; 1305 1282 fFileSizesMap[fFullRunReportFileName] = 0; 1306 1283 } … … 1310 1287 char currentPath[FILENAME_MAX]; 1311 1288 getcwd(currentPath, sizeof(currentPath)); 1289 if (errno != 0) 1290 { 1291 std::stringstream str; 1292 str << "Unable to retrieve the current path" << ". Reason: " << strerror(errno) << " [" << errno << "]"; 1293 Error(str); 1294 } 1312 1295 actualTargetDir = currentPath; 1313 1296 } … … 1345 1328 delete fRunFitsFile; 1346 1329 fRunFitsFile = NULL; 1347 std::cout << "FNumSub2: " << fNumSubAndFitsData.numOpenFits << std::endl;1348 1330 (fNumSubAndFitsData.numOpenFits)--; 1349 std::cout << "FNumSub3: " << fNumSubAndFitsData.numOpenFits << std::endl;1350 1331 } 1351 1332 #endif … … 1433 1414 } 1434 1415 1435 void RunThread(DataLogger *logger)1436 { 1437 // This is necessary so that the StateMachien Thread can signal the 1438 1439 1440 Readline::Stop(); 1416 void RunThread(DataLogger* logger) 1417 { 1418 // This is necessary so that the StateMachine Thread can signal the 1419 // Readline thread to exit 1420 logger->Run(true); 1421 Readline::Stop(); 1441 1422 } 1442 1423 … … 1454 1435 1455 1436 DataLogger logger(wout); 1437 1438 // if (conf.Has("black-list")) 1439 // logger.setBlackList(conf.Get<std::string>("black-list")); 1440 // else if (conf.Has("white-list")) 1441 // logger.setWhiteList(conf.Get<std::string>("white-list")); 1442 1456 1443 shell.SetReceiver(logger); 1457 1444 1458 1459 1460 shell.Run();// Run the shell1461 1462 logger.Stop(); // Signal Loop-thread to stop 1463 1464 //Wait until the StateMachine has finished its thread1465 // before returning and destroying the dim objects which might 1466 //still be in use.1467 1445 boost::thread t(boost::bind(RunThread, &logger)); 1446 1447 shell.Run(); // Run the shell 1448 1449 logger.Stop(); 1450 1451 //Wait until the StateMachine has finished its thread 1452 //before returning and destroyinng the dim objects which might 1453 //still be in use. 1454 t.join(); 1468 1455 1469 1456 return 0; … … 1505 1492 "help message about the usuage can be brought to the screen." 1506 1493 << endl; 1507 1508 /*1509 cout << "bla bla bla" << endl << endl;1510 cout << endl;1511 cout << "Environment:" << endl;1512 cout << "environment" << endl;1513 cout << endl;1514 cout << "Examples:" << endl;1515 cout << "test exam" << endl;1516 cout << endl;1517 cout << "Files:" << endl;1518 cout << "files" << endl;1519 cout << endl;1520 */1521 1494 } 1522 1495 … … 1564 1537 ("log,l", var<string>(n), "Write log-file") 1565 1538 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)") 1539 ("black-list,b", var<string>(""), "Black-list of services") 1540 ("white-list,w", var<string>(""), "White-list of services") 1566 1541 ; 1567 1542
Note:
See TracChangeset
for help on using the changeset viewer.