Changeset 11893
- Timestamp:
- 08/11/11 23:09:13 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/DataCalib.cc
r11885 r11893 221 221 file.AddColumn('F', "TriggerOffsetRms", 1024*1440, "V"); 222 222 223 fFileName = FormFileName( GetRunId(),"drs.fits");223 fFileName = FormFileName("drs.fits"); 224 224 225 225 if (!file.OpenFile(fFileName)) -
trunk/FACT++/src/DataCalib.h
r11844 r11893 31 31 32 32 public: 33 DataCalib( uint32_t id, DimDescribedService &dim, MessageImp &imp) : DataProcessorImp(id, imp), fDim(dim)33 DataCalib(const std::string &path, uint32_t id, DimDescribedService &dim, MessageImp &imp) : DataProcessorImp(path, id, imp), fDim(dim) 34 34 { 35 35 } -
trunk/FACT++/src/DataProcessorImp.cc
r11726 r11893 2 2 3 3 #include "FAD.h" 4 5 #include "DimWriteStatistics.h" // weird dependency 4 6 5 7 using namespace std; … … 13 15 //! @param extension a string containing the extension to be appened to the file name 14 16 // 15 string DataProcessorImp::FormFileName( uint32_t runid, const string &extension)17 string DataProcessorImp::FormFileName(const string &path, uint32_t runid, const string &extension) 16 18 { 17 19 ostringstream name; 18 name << Time().NightAsInt() << '_' << setfill('0') << setw(3) << runid << '.' << extension; 20 21 if (!path.empty()) 22 { 23 name << path; 24 if (path[path.length()-1] != '/') 25 name << '/'; 26 } 27 28 const Time time; 29 name << time.GetAsStr("%Y/%m/%d/"); 30 31 try 32 { 33 DimWriteStatistics::CreateDirectory(name.str()); 34 } 35 catch (const runtime_error &) 36 { 37 // File creation will fail anyway 38 //Error(e.what()); 39 } 40 41 name << time.NightAsInt() << '_' << setfill('0') << setw(3) << runid << '.' << extension; 19 42 return name.str(); 20 43 } -
trunk/FACT++/src/DataProcessorImp.h
r11726 r11893 14 14 class DataProcessorImp : public MessageImp 15 15 { 16 uint32_t fRunId; 16 std::string fPath; 17 uint32_t fRunId; 17 18 18 19 int Write(const Time &time, const std::string &txt, int qos) … … 26 27 27 28 public: 28 DataProcessorImp( uint32_t id, MessageImp &imp) :fRunId(id), fMsg(imp) { }29 DataProcessorImp(const std::string &path, uint32_t id, MessageImp &imp) : fPath(path), fRunId(id), fMsg(imp) { } 29 30 virtual ~DataProcessorImp() { } 30 31 … … 35 36 const std::string &GetFileName() const { return fFileName; } 36 37 37 uint32_t GetRunId() const { return fRunId; } 38 std::string GetPath() const { return fPath; } 39 uint32_t GetRunId() const { return fRunId; } 38 40 39 static std::string FormFileName(uint32_t runid, const std::string &extension); 41 static std::string FormFileName(const std::string &path, uint32_t runid, const std::string &extension); 42 std::string FormFileName(const std::string &extension) 43 { 44 return FormFileName(fPath, fRunId, extension); 45 } 40 46 }; 41 47 … … 47 53 48 54 public: 49 DataDump( uint32_t id, MessageImp &imp) : DataProcessorImp(id, imp) { }55 DataDump(const std::string &path, uint32_t id, MessageImp &imp) : DataProcessorImp(path, id, imp) { } 50 56 51 57 bool Open(RUN_HEAD* h); … … 57 63 { 58 64 public: 59 DataDebug( uint32_t id, MessageImp &imp) : DataDump(id, imp) { }65 DataDebug(const std::string &path, uint32_t id, MessageImp &imp) : DataDump(path, id, imp) { } 60 66 61 67 bool WriteEvt(EVENT *e); -
trunk/FACT++/src/DataWriteFits.cc
r11886 r11893 66 66 67 67 //Form filename, based on runid and run-type 68 fFileName = FormFileName( GetRunId(),"fits");68 fFileName = FormFileName("fits"); 69 69 70 70 if (!fFile.OpenFile(fFileName)) -
trunk/FACT++/src/DataWriteFits.h
r11743 r11893 19 19 20 20 public: 21 DataWriteFits( uint32_t runid, MessageImp &imp) :22 DataProcessorImp( runid, imp), fConv(0), fFile(imp)21 DataWriteFits(const std::string path, uint32_t runid, MessageImp &imp) : 22 DataProcessorImp(path, runid, imp), fConv(0), fFile(imp) 23 23 { 24 24 } -
trunk/FACT++/src/DataWriteRaw.cc
r11726 r11893 20 20 bool DataWriteRaw::Open(RUN_HEAD *h) 21 21 { 22 const string name = FormFileName( GetRunId(),"bin");22 const string name = FormFileName("bin"); 23 23 if (access(name.c_str(), F_OK)==0) 24 24 { -
trunk/FACT++/src/DataWriteRaw.h
r11726 r11893 68 68 69 69 public: 70 DataWriteRaw( uint32_t id, MessageImp &imp) : DataProcessorImp(id, imp), fPosTail(0) { }70 DataWriteRaw(const std::string &path, uint32_t id, MessageImp &imp) : DataProcessorImp(path, id, imp), fPosTail(0) { } 71 71 ~DataWriteRaw() { if (fOut.is_open()) Close(); } 72 72 -
trunk/FACT++/src/DimWriteStatistics.cc
r11534 r11893 10 10 #include <sys/statvfs.h> //for getting disk free space 11 11 #include <sys/stat.h> //for getting files sizes 12 13 #include <boost/filesystem.hpp> 12 14 13 15 #include "Time.h" … … 88 90 89 91 return -1; 92 } 93 94 // -------------------------------------------------------------------------- 95 // 96 //! Check if a given path exists 97 //! @param path the path to be checked 98 //! @return whether or not the given path exists 99 // 100 bool DimWriteStatistics::DoesPathExist(const string &path, MessageImp &log) 101 { 102 namespace fs = boost::filesystem; 103 104 const fs::path fullPath = fs::system_complete(fs::path(path)); 105 106 if (!fs::exists(fullPath)) 107 return false; 108 109 if (!fs::is_directory(fullPath)) 110 { 111 log.Error("Path given for checking '" + path + "' designate a file name. Please provide a path name only"); 112 return false; 113 } 114 115 if (access(path.c_str(), R_OK|W_OK|X_OK) != 0) 116 { 117 log.Error("Missing read, write or execute permissions on directory '" + path + "'"); 118 return false; 119 } 120 121 return true; 122 } 123 124 // -------------------------------------------------------------------------- 125 // 126 //! Check if a given path exists 127 //! @param path the path to be checked 128 //! @return whether or not the creation has been successfull 129 // 130 void DimWriteStatistics::CreateDirectory(string path) 131 { 132 namespace fs = boost::filesystem; 133 134 //remove last '/', if present 135 if (path[path.size()-1] == '/') 136 path = path.substr(0, path.size()-1); 137 138 //create boost path 139 const fs::path fullPath = fs::system_complete(fs::path(path)); 140 141 //if path does not exist, check if upper levels exist already 142 if (fs::exists(fullPath)) 143 { 144 //if path already exist, make sure it does not designate a file (filenames cannot be checked if they do not exist) 145 if (fs::is_directory(fullPath)) 146 return; 147 148 throw runtime_error("Path to be created is a file '" + path + "'"); 149 } 150 151 // we're hitting "/", which SHOULD have existed... 152 if (path.size() <= 1) 153 throw runtime_error("Path to be created looks suspicious '"+path+"'"); 154 155 CreateDirectory(path.substr(0, path.find_last_of('/'))); 156 157 //path does not exist, and upper level have been created already by recusrion. 158 const mode_t rightsMask = S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH; //everybody read, owner writes 159 160 if (mkdir(path.c_str(), rightsMask)==0) 161 return; 162 163 ostringstream str; 164 str << "mkdir() failed for '" << path << "': " << strerror(errno) << " [errno=" << errno << "]"; 165 throw runtime_error(str.str()); 90 166 } 91 167 -
trunk/FACT++/src/DimWriteStatistics.h
r11534 r11893 80 80 ///Returns the size on disk of a given file 81 81 static int64_t GetFileSizeOnDisk(const std::string& file, MessageImp &imp); 82 83 static bool DoesPathExist(const std::string &path, MessageImp &log); 84 85 static void CreateDirectory(std::string path); 82 86 }; 83 87 -
trunk/FACT++/src/EventBuilderWrapper.h
r11889 r11893 10 10 #endif 11 11 #include <boost/thread.hpp> 12 #include <boost/filesystem.hpp> 12 13 #include <boost/date_time/posix_time/posix_time_types.hpp> 13 14 … … 25 26 namespace ba = boost::asio; 26 27 namespace bs = boost::system; 28 namespace fs = boost::filesystem; 27 29 28 30 using ba::ip::tcp; … … 112 114 bool fDebugLog; 113 115 116 string fPath; 114 117 uint32_t fRunNumber; 115 118 116 void InitRunNumber() 117 { 118 // FIXME: Add a check that we are not too close to noon! 119 //const int night = Time().NightAsInt(); 120 119 protected: 120 int64_t InitRunNumber() 121 { 121 122 fRunNumber = 1000; 122 123 124 // Ensure that the night doesn't change during our check 125 const int check = Time().NightAsInt(); 126 123 127 while (--fRunNumber>0) 124 128 { 125 const string name = DataProcessorImp::FormFileName(f RunNumber, "");129 const string name = DataProcessorImp::FormFileName(fPath, fRunNumber, ""); 126 130 127 131 if (access((name+"bin").c_str(), F_OK) == 0) … … 133 137 } 134 138 139 if (check != Time().NightAsInt()) 140 return InitRunNumber(); 141 135 142 fRunNumber++; 136 143 144 if (fRunNumber==1000) 145 { 146 fMsg.Error("You have a file with run-number 1000 in "+fPath); 147 return -1; 148 } 149 137 150 ostringstream str; 138 str << "S tarting with run number " << fRunNumber;151 str << "Set next run-number to " << fRunNumber << " determined from " << fPath; 139 152 fMsg.Message(str); 140 153 141 fMsg.Info(" ==> TODO: Run-number detection doesn't work when noon passes!");142 154 fMsg.Info(" ==> TODO: Crosscheck with database!"); 155 156 return check; 157 } 158 159 int64_t InitRunNumber(const string &path) 160 { 161 if (!DimWriteStatistics::DoesPathExist(path, fMsg)) 162 return -1; 163 164 //const fs::path fullPath = fs::system_complete(fs::path(path)); 165 166 fPath = path; 167 168 return InitRunNumber(); 143 169 } 144 170 … … 176 202 for (size_t i=0; i<40; i++) 177 203 ConnectSlot(i, tcp::endpoint()); 178 179 InitRunNumber();180 204 } 181 205 virtual ~EventBuilderWrapper() … … 499 523 switch (fFileFormat) 500 524 { 501 case kNone: file = new DataDump( runid, fMsg); break;502 case kDebug: file = new DataDebug( runid, fMsg); break;503 case kFits: file = new DataWriteFits( runid, fMsg); break;504 case kRaw: file = new DataWriteRaw( runid, fMsg); break;505 case kCalib: file = new DataCalib( runid, fDimDrsCalibration, fMsg); break;525 case kNone: file = new DataDump(fPath, runid, fMsg); break; 526 case kDebug: file = new DataDebug(fPath, runid, fMsg); break; 527 case kFits: file = new DataWriteFits(fPath, runid, fMsg); break; 528 case kRaw: file = new DataWriteRaw(fPath, runid, fMsg); break; 529 case kCalib: file = new DataCalib(fPath, runid, fDimDrsCalibration, fMsg); break; 506 530 } 507 531 -
trunk/FACT++/src/datalogger.cc
r11837 r11893 414 414 bool DataLogger::CreateDirectory(string path) 415 415 { 416 //remove last '/', if present 417 if (path[path.size()-1] == '/') 418 path = path.substr(0, path.size()-1); 419 420 //create boost path 421 const boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path)); 422 423 //if path does not exist, check if upper levels exist already 424 if (boost::filesystem::exists(fullPath)) 425 { 426 //if path already exist, make sure it does not designate a file (filenames cannot be checked if they do not exist) 427 if (boost::filesystem::is_directory(fullPath)) 428 return true; 429 430 Error("Path to be created contains a file name: '" + path + "'"); 416 try 417 { 418 DimWriteStatistics::CreateDirectory(path); 419 return true; 420 } 421 catch (const runtime_error &e) 422 { 423 Error(e.what()); 431 424 return false; 432 425 } 433 434 if (path.size() <= 1)435 {//we're hitting "/", which SHOULD have existed...436 Error("Something unexpected happened while creating a path");437 }438 CreateDirectory(path.substr(0, path.find_last_of('/')));439 440 //path does not exist, and upper level have been created already by recusrion.441 const mode_t rightsMask = S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH; //everybody read, owner writes442 443 const int returnValue = mkdir(path.c_str(), rightsMask);444 445 if (returnValue != 0)446 {447 ostringstream str;448 str << "mkdir() failed for '" << path << "': " << strerror(errno) << " [errno=" << errno << "]";449 Error(str.str());450 return false;451 }452 453 return true;454 426 } 455 427 // -------------------------------------------------------------------------- … … 461 433 bool DataLogger::DoesPathExist(string path) 462 434 { 463 const boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path)); 464 465 if (!boost::filesystem::exists(fullPath)) 466 return false; 467 468 if (!boost::filesystem::is_directory(fullPath)) 469 { 470 Error("Path given for checking '" + path + "' designate a file name. Please provide a path name only"); 471 return false; 472 } 473 474 if (access(path.c_str(), R_OK|W_OK|X_OK) != 0) 475 { 476 Error("Missing read, write or execute permissions on directory '" + path + "'"); 477 return false; 478 } 479 480 return true; 481 } 435 return DimWriteStatistics::DoesPathExist(path, *this); 436 } 437 482 438 // -------------------------------------------------------------------------- 483 439 // -
trunk/FACT++/src/fadctrl.cc
r11892 r11893 1021 1021 } 1022 1022 1023 if (fNightAsInt!=Time().NightAsInt()) 1024 { 1025 ostringstream out; 1026 out << "Night changed from " << fNightAsInt << " to " << Time().NightAsInt() << "... determining new run-number."; 1027 T::Info(out); 1028 1029 // FIXME: What about an error state? 1030 fNightAsInt = InitRunNumber(); 1031 if (fNightAsInt<0) 1032 return FAD::kConnected; 1033 } 1034 1023 1035 const uint32_t runno = StartNewRun(evt.Get<uint64_t>(), evt.Get<uint64_t>(8), *fTargetConfig); 1024 1036 … … 1026 1038 str << "Starting configuration for run " << runno << " (" << name << ")"; 1027 1039 T::Message(str.str()); 1040 1041 if (runno>=1000) 1042 T::Warn("Run number exceeds logical maximum of 999 - this is no problem for writing but might give raise to problems in the analysis."); 1028 1043 1029 1044 const FAD::Configuration &conf = fTargetConfig->second; … … 1813 1828 } 1814 1829 1830 int64_t fNightAsInt; 1831 1815 1832 int EvalOptions(Configuration &conf) 1816 1833 { … … 1823 1840 // ---------- Setup event builder --------- 1824 1841 SetMaxMemory(conf.Get<unsigned int>("max-mem")); 1842 1843 fNightAsInt = InitRunNumber(conf.Get<string>("destination-folder")); 1844 if (fNightAsInt<0) 1845 return 1; 1825 1846 1826 1847 // ---------- Setup run types --------- … … 1838 1859 { 1839 1860 T::Error("Run-type "+*it+" defined twice."); 1840 return 1;1861 return 2; 1841 1862 } 1842 1863 … … 1846 1867 !CheckConfigVal<bool>(conf, true, "enable-dwrite.", *it) || 1847 1868 !CheckConfigVal<bool>(conf, true, "enable-continous-trigger.", *it)) 1848 return 2;1869 return 3; 1849 1870 1850 1871 target.fDenable = conf.GetDef<bool>("enable-drs.", *it); … … 1856 1877 { 1857 1878 if (!CheckConfigVal<uint16_t>(conf, 0xffff, "trigger-rate.", *it)) 1858 return 3;1879 return 4; 1859 1880 1860 1881 target.fTriggerRate = conf.GetDef<uint16_t>("trigger-rate.", *it); … … 1868 1889 if (!CheckConfigVal<uint16_t>(conf, FAD::kMaxRoiValue, "roi.", *it) && 1869 1890 !CheckConfigVal<uint16_t>(conf, FAD::kMaxRoiValue, str.str(), *it)) 1870 return 4;1891 return 5; 1871 1892 1872 1893 target.fRoi[i] = conf.HasDef(str.str(), *it) ? … … 1882 1903 if (!CheckConfigVal<uint16_t>(conf, FAD::kMaxDacValue, "dac.", *it) && 1883 1904 !CheckConfigVal<uint16_t>(conf, FAD::kMaxDacValue, str.str(), *it)) 1884 return 5;1905 return 6; 1885 1906 1886 1907 target.fDac[i] = conf.HasDef(str.str(), *it) ? … … 1903 1924 const tcp::endpoint endpoint = GetEndpoint(addr); 1904 1925 if (endpoint==tcp::endpoint()) 1905 return 1;1926 return 7; 1906 1927 1907 1928 for (int i=0; i<num; i++) … … 1923 1944 const tcp::endpoint endpoint = GetEndpoint(base); 1924 1945 if (endpoint==tcp::endpoint()) 1925 return 10;1946 return 8; 1926 1947 1927 1948 const ba::ip::address_v4::bytes_type ip = endpoint.address().to_v4().to_bytes(); … … 1930 1951 { 1931 1952 T::Out() << kRed << "EvalConfiguration - IP address given by --base-addr out-of-range." << endl; 1932 return 11;1953 return 9; 1933 1954 } 1934 1955 … … 1957 1978 const tcp::endpoint endpoint = GetEndpoint(*i); 1958 1979 if (endpoint==tcp::endpoint()) 1959 return 1 2;1980 return 10; 1960 1981 1961 1982 AddEndpoint(endpoint);
Note:
See TracChangeset
for help on using the changeset viewer.