Changeset 11535
- Timestamp:
- 07/22/11 08:53:05 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/datalogger.cc
r11500 r11535 314 314 void CreateFitsGrouping(map<string, vector<string> >& filesToGroup, int runNumber); 315 315 316 bool OpenStreamImp(ofstream &stream, const string &filename, bool mightbeopen); 316 317 bool OpenStream(shared_ptr<ofstream> stream, const string &filename); 317 318 ///Open the relevant text files related to a particular run … … 437 438 { 438 439 ostringstream str; 439 str << " Could not create directory " << path << " mkdir error code: " << errno;440 str << "mkdir() failed for '" << path << "': " << strerror(errno) << " [errno=" << errno << "]"; 440 441 Error(str.str()); 441 442 return false; … … 524 525 return; 525 526 526 ostringstream str; 527 str << "Subscription " << server << "/" << service << " could not be removed as it is not present"; 528 Error(str.str()); 527 Error("Subscription "+server+"/"+service+" could not be removed as it is not present"); 529 528 return; 530 529 } … … 572 571 } 573 572 573 bool DataLogger::OpenStreamImp(ofstream &stream, const string &filename, bool mightbeopen) 574 { 575 if (stream.is_open()) 576 { 577 if (!mightbeopen) 578 Error(filename+" was already open when trying to open it."); 579 return mightbeopen; 580 } 581 582 errno = 0; 583 stream.open(filename.c_str(), ios_base::out | ios_base::app); 584 if (!stream /*|| errno!=0*/) 585 { 586 ostringstream str; 587 str << "ofstream::open() failed for '" << filename << "': " << strerror(errno) << " [errno=" << errno << "]"; 588 Error(str); 589 return false; 590 } 591 592 if (!stream.is_open()) 593 { 594 Error("File "+filename+" not open as it ought to be."); 595 return false; 596 } 597 598 Info("Opened: "+filename); 599 600 return true; 601 } 602 603 bool DataLogger::OpenStream(shared_ptr<ofstream> stream, const string &filename) 604 { 605 return OpenStreamImp(*stream, filename, false); 606 } 607 574 608 // -------------------------------------------------------------------------- 575 609 // … … 580 614 bool DataLogger::OpenTextFilePlease(ofstream& stream, const string& name) 581 615 { 582 if (stream.is_open()) 583 return true; 584 585 errno = 0; 586 stream.open(name.c_str(), ios_base::out | ios_base::app); 587 if (!stream.is_open()) 588 { 589 ostringstream str; 590 str << "Trying to open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")"; 591 Error(str); 592 return false; 593 } 594 595 Info("Opened: "+name); 596 597 return true; 616 return OpenStreamImp(stream, name, true); 598 617 } 599 618 … … 607 626 { 608 627 if (fDebugIsOn) 609 { 610 ostringstream str; 611 str << "Subscribing to service " << server << "/" << service; 612 Debug(str); 613 } 628 Debug("Subscribing to service "+server+"/"+service); 629 614 630 return new DimStampedInfo((server + "/" + service).c_str(), (void*)NULL, 0, this); 615 631 } … … 737 753 off_t DataLogger::GetFileSize(const string& fileName) 738 754 { 739 errno = 0; 740 struct stat st; 741 if (!stat(fileName.c_str(), &st)) 742 return st.st_size; 743 744 if (errno != 0 && errno != 2)//ignoring error #2: no such file or directory is not an error for new files 745 { 746 ostringstream str; 747 str << "Unable to stat " << fileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 748 Error(str); 749 } 750 751 return 0; 752 } 755 return DimWriteStatistics::GetFileSizeOnDisk(fileName, *this); 756 } 757 753 758 // -------------------------------------------------------------------------- 754 759 // … … 1034 1039 { 1035 1040 ostringstream str; 1036 str << "Format of " << I->getName() << " is empty . Ignoring it";1041 str << "Format of " << I->getName() << " is empty (ptr=" << I->getData() << ", size=" << I->getSize() << ")... ignoring it."; 1037 1042 Error(str); 1038 1043 return; … … 1055 1060 //remove old run numbers 1056 1061 TrimOldRunNumbers(); 1057 }1058 1059 bool DataLogger::OpenStream(shared_ptr<ofstream> stream, const string &filename)1060 {1061 if (stream->is_open())1062 {1063 ostringstream str;1064 str << filename << " was already open when trying to open it.";1065 Error(str);1066 return false;1067 }1068 1069 errno = 0;1070 stream->open(filename.c_str(), ios_base::out | ios_base::app);1071 if (errno != 0)1072 {1073 ostringstream str;1074 str << "Unable to open " << filename << ": " << strerror(errno) << " (errno=" << errno << ")";1075 Error(str);1076 return false;1077 }1078 1079 if (!stream->is_open())1080 {1081 ostringstream str;1082 str << "File " << filename << " not open as it ought to be.";1083 Error(str);1084 return false;1085 }1086 1087 Info("Opened: "+filename);1088 1089 return true;1090 1062 } 1091 1063 … … 1146 1118 { 1147 1119 ostringstream str; 1148 str << "Adding new run number " << newRun << " that was issued on" << time;1120 str << "Adding new run number " << newRun << " issued at " << time; 1149 1121 Debug(str); 1150 1122 } … … 1218 1190 { 1219 1191 ostringstream str; 1220 str << "Logging " << 1192 str << "Logging " << I->getName() << " [" << I->getFormat() << "] (" << I->getSize() << ")"; 1221 1193 Debug(str); 1222 1194 } … … 1264 1236 1265 1237 //create the converter for that service 1266 if (!sub.fConv .get())1238 if (!sub.fConv) 1267 1239 { 1268 1240 sub.fConv = shared_ptr<Converter>(new Converter(Out(), I->getFormat())); 1269 if (!sub.fConv )1241 if (!sub.fConv->valid()) 1270 1242 { 1271 1243 ostringstream str; … … 1304 1276 if (rit == fRunNumber.rend() && fRunNumber.size() != 0) 1305 1277 { 1306 ostringstream str; 1307 str << "Could not find an appropriate run number for info coming at time: " << cTime; 1308 Error(str); 1278 Error("Could not find an appropriate run number for info coming at time "+cTime.GetAsStr()); 1309 1279 Error("Active run numbers: "); 1310 1280 for (rit=fRunNumber.rbegin(); rit != fRunNumber.rend(); rit++) 1311 1281 { 1312 str.str("");1313 str << rit->runNumber;1282 ostringstream str; 1283 str << " -> " << rit->runNumber; 1314 1284 Error(str); 1315 1285 } … … 2006 1976 if (sub.nightlyFile.IsOpen()) 2007 1977 { 2008 if (!sub.nightlyFile.Write(sub.fConv.get())) 1978 const shared_ptr<Converter> ptr(sub.fConv); 1979 if (!sub.nightlyFile.Write(*ptr)) 2009 1980 { 2010 1981 sub.nightlyFile.Close(); … … 2017 1988 if (sub.runFile.IsOpen()) 2018 1989 { 2019 if (!sub.runFile.Write(sub.fConv.get())) 1990 const shared_ptr<Converter> ptr(sub.fConv); 1991 if (!sub.runFile.Write(*ptr)) 2020 1992 { 2021 1993 sub.runFile.Close(); … … 2391 2363 fFullNightlyLogFileName = CompileFileNameWithPath(fNightlyFilePath, "", "log"); 2392 2364 if (!OpenTextFilePlease(fNightlyLogFile, fFullNightlyLogFileName)) 2393 SetCurrentState(kSM_BadNightlyConfig); 2394 else 2395 { 2396 fNightlyLogFile << endl; 2397 NotifyOpenedFile(fFullNightlyLogFileName, 1, fOpenedNightlyFiles); 2398 for (vector<string>::iterator it=backLogBuffer.begin();it!=backLogBuffer.end();it++) 2399 { 2400 fNightlyLogFile << *it; 2401 } 2402 } 2403 } 2365 return 3; 2366 2367 fNightlyLogFile << endl; 2368 NotifyOpenedFile(fFullNightlyLogFileName, 1, fOpenedNightlyFiles); 2369 for (vector<string>::iterator it=backLogBuffer.begin();it!=backLogBuffer.end();it++) 2370 fNightlyLogFile << *it; 2371 } 2404 2372 2405 2373 shouldBackLog = false;
Note:
See TracChangeset
for help on using the changeset viewer.