Changeset 11381
- Timestamp:
- 07/13/11 18:39:52 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilderWrapper.h
r11376 r11381 28 28 using namespace std; 29 29 30 class DataFileImp 30 class DataFileImp : public MessageImp 31 31 { 32 32 uint32_t fRunId; 33 33 34 int Write(const Time &time, const std::string &txt, int qos) 35 { 36 return fMsg.Write(time, txt, qos); 37 } 38 34 39 protected: 35 MessageImp &f Log;40 MessageImp &fMsg; 36 41 string fFileName; 37 42 38 43 public: 39 DataFileImp(uint32_t id, MessageImp &imp) : fRunId(id), f Log(imp) { }44 DataFileImp(uint32_t id, MessageImp &imp) : fRunId(id), fMsg(imp) { } 40 45 virtual ~DataFileImp() { } 41 46 42 47 virtual bool OpenFile(RUN_HEAD* h) = 0; 43 virtual bool Write (EVENT *) = 0;48 virtual bool WriteEvt(EVENT *) = 0; 44 49 virtual bool Close(RUN_TAIL * = 0) = 0; 45 50 … … 55 60 //! @param extension a string containing the extension to be appened to the file name 56 61 // 57 string FormFileName(uint32_t runType, string extension) 58 { 59 //TODO where am I supposed to get the base directory from ? 60 //TODO also, for creating subsequent directories, should I use the functions from the dataLogger ? 61 string baseDirectory = "./Run"; 62 63 ostringstream result; 64 // result << baseDirectory; 65 // result << Time::fmt("/%Y/%m/%d/") << (Time() - boost::posix_time::time_duration(12,0,0)); 66 result << setfill('0') << setw(8) << fRunId; 67 result << ".001_"; 68 switch (runType) 69 { 70 case -1: 71 result << 'T'; 72 break; 73 case 0: 74 result << 'D'; 75 break; 76 case 1: 77 result << 'P'; 78 break; 79 case 2: 80 result << 'C'; 81 break; 82 case 3: 83 result << 'N'; 84 break; 85 default: 86 result << runType; 87 }; 88 result << "." << extension; 89 90 return result.str(); 62 static string FormFileName(uint32_t runid, string extension) 63 { 64 ostringstream name; 65 name << Time().NightAsInt() << '.' << setfill('0') << setw(3) << runid << '.' << extension; 66 return name.str(); 91 67 } 92 68 }; … … 97 73 DataFileNone(uint32_t id, MessageImp &imp) : DataFileImp(id, imp) { } 98 74 75 Time fTime; 76 99 77 bool OpenFile(RUN_HEAD* h) 100 78 { 101 79 fFileName = "/dev/null"; 102 cout << "OPEN_FILE #" << GetRunId() << " (" << this << ")" << endl; 103 cout << " Ver= " << h->Version << endl; 104 cout << " Typ= " << h->RunType << endl; 105 cout << " Nb = " << h->NBoard << endl; 106 cout << " Np = " << h->NPix << endl; 107 cout << " NTm= " << h->NTm << endl; 108 cout << " roi= " << h->Nroi << endl; 80 81 ostringstream str; 82 str << this << " - " 83 << "OPEN_FILE #" << GetRunId() << ":" 84 << " Ver=" << h->Version 85 << " Typ=" << h->RunType 86 << " Nb=" << h->NBoard 87 << " Np=" << h->NPix 88 << " NTm=" << h->NTm 89 << " roi=" << h->Nroi; 90 91 Debug(str); 92 93 fTime = Time(); 109 94 110 95 return true; 111 96 } 112 bool Write(EVENT *) 113 { 97 bool WriteEvt(EVENT *e) 98 { 99 const Time now; 100 if (now-fTime<boost::posix_time::seconds(5)) 101 return true; 102 103 fTime = now; 104 105 ostringstream str; 106 str << this << " - EVENT #" << e->EventNum; 107 Debug(str); 108 114 109 return true; 115 110 } 116 111 bool Close(RUN_TAIL * = 0) 117 112 { 118 cout << "CLOSE FILE #" << GetRunId() << " (" << this << ")" << endl; 113 ostringstream str; 114 str << this << " - CLOSE FILE #" << GetRunId(); 115 116 Debug(str); 117 119 118 return true; 120 119 } … … 126 125 DataFileDebug(uint32_t id, MessageImp &imp) : DataFileNone(id, imp) { } 127 126 128 bool Write (EVENT *e)127 bool WriteEvt(EVENT *e) 129 128 { 130 129 cout << "WRITE_EVENT #" << GetRunId() << " (" << e->EventNum << ")" << endl; … … 226 225 bool OpenFile(RUN_HEAD *h) 227 226 { 228 const string name = FormFileName( h->RunType, "bin");227 const string name = FormFileName(GetRunId(), "bin"); 229 228 if (access(name.c_str(), F_OK)==0) 230 229 { 231 fLog.Error("File '"+name+"' already exists.");230 Error("File '"+name+"' already exists."); 232 231 return false; 233 232 } … … 241 240 ostringstream str; 242 241 str << "Open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")"; 243 fLog.Error(str);242 Error(str); 244 243 245 244 return false; … … 276 275 ostringstream str; 277 276 str << "Open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")"; 278 fLog.Error(str);277 Error(str); 279 278 280 279 return false; … … 283 282 return true; 284 283 } 285 bool Write (EVENT *evt)284 bool WriteEvt(EVENT *evt) 286 285 { 287 286 const int sh = sizeof(EVENT)-2 + NPIX*evt->Roi*2; … … 307 306 ostringstream str; 308 307 str << " Writing footer: " << strerror(errno) << " (errno=" << errno << ")"; 309 fLog.Error(str);308 Error(str); 310 309 311 310 return false; … … 318 317 ostringstream str; 319 318 str << "Closing file: " << strerror(errno) << " (errno=" << errno << ")"; 320 fLog.Error(str);319 Error(str); 321 320 322 321 return false; … … 390 389 ostringstream str; 391 390 str << "Could not add header key " << name; 392 fLog.Error(str);391 Error(str); 393 392 } 394 393 } … … 412 411 { 413 412 //Form filename, based on runid and run-type 414 const string fileName = FormFileName( h->RunType, "fits");413 const string fileName = FormFileName(GetRunId(), "fits"); 415 414 if (access(fileName.c_str(), F_OK)==0) 416 415 { 417 fLog.Error("File '"+fileName+"' already exists.");416 Error("File '"+fileName+"' already exists."); 418 417 return false; 419 418 } … … 443 442 ostringstream str; 444 443 str << "Could not open FITS file " << fileName << ": " << e.message(); 445 fLog.Error(str);444 Error(str); 446 445 return false; 447 446 } … … 476 475 ostringstream str; 477 476 str << "Could not create FITS table 'Events' in file " << fileName << " reason: " << e.message(); 478 fLog.Error(str);477 Error(str); 479 478 return false; 480 479 } … … 482 481 if (fTable->rows() != 0) 483 482 { 484 fLog.Error("FITS table created on the fly looks non-empty.");483 Error("FITS table created on the fly looks non-empty."); 485 484 return false; 486 485 } … … 588 587 ostringstream str; 589 588 str << "Writing FITS row " << fNumRows << ": " << text << " (file_write_tblbytes, rc=" << status << ")"; 590 fLog.Error(str);589 Error(str); 591 590 } 592 591 … … 600 599 //! @param e the pointer to the EVENT 601 600 // 602 virtual bool Write (EVENT *e)601 virtual bool WriteEvt(EVENT *e) 603 602 { 604 603 //FIXME As discussed earlier, we do not swap the bytes yet. … … 614 613 ostringstream str; 615 614 str << "Inserting row " << fNumRows << " into " << fFileName << ": " << text << " (fits_insert_rows, rc=" << status << ")"; 616 fLog.Error(str);615 Error(str); 617 616 618 617 return false; … … 779 778 bool fDebugLog; 780 779 781 int Write(const Time &time, const std::string &txt, int qos)782 {783 return fMsg.Write(time, txt, qos);784 }785 786 787 780 uint32_t fRunNumber; 788 781 789 782 void InitRunNumber() 790 783 { 784 // FIXME: Add a check that we are not too close to noon! 791 785 const int night = Time().NightAsInt(); 792 786 … … 795 789 while (--fRunNumber>0) 796 790 { 797 ostringstream name; 798 name << night << '.' << setfill('0') << setw(3) << fRunNumber; 799 800 if (access((name.str()+".bin").c_str(), F_OK) == 0) 791 const string name = DataFileImp::FormFileName(fRunNumber, ""); 792 793 if (access((name+"bin").c_str(), F_OK) == 0) 801 794 break; 802 if (access((name .str()+".fits").c_str(), F_OK) == 0)795 if (access((name+"fits").c_str(), F_OK) == 0) 803 796 break; 804 797 } … … 806 799 fRunNumber++; 807 800 808 cout << "FOUND: " << night << '.' << setfill('0') << setw(3) << fRunNumber << endl; 801 ostringstream str; 802 str << "Starting with run number " << fRunNumber; 803 fMsg.Message(str); 804 805 fMsg.Fatal("Run-number detection doesn't work when noon passes!"); 806 fMsg.Error("Crosscheck with database!"); 809 807 } 810 808 … … 858 856 } 859 857 858 uint32_t GetRunNumber() const { return fRunNumber; } 860 859 861 860 bool IsThreadRunning() … … 1148 1147 DataFileImp *file = reinterpret_cast<DataFileImp*>(handler); 1149 1148 1150 if (!file->Write (e))1149 if (!file->WriteEvt(e)) 1151 1150 return -1; 1152 1151
Note:
See TracChangeset
for help on using the changeset viewer.