Changeset 11725
- Timestamp:
- 07/30/11 20:07:03 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilderWrapper.h
r11715 r11725 12 12 #include <boost/date_time/posix_time/posix_time_types.hpp> 13 13 14 #include "DimWriteStatistics.h" 15 16 #include "DataCalib.h" 17 #include "DataWriteRaw.h" 18 14 19 #ifdef HAVE_FITS 15 #include "FitsFile.h" 20 #include "DataWriteFits.h" 21 #else 22 #define DataWriteFits DataWriteRaw 16 23 #endif 24 25 namespace ba = boost::asio; 26 namespace bs = boost::system; 27 28 using ba::ip::tcp; 29 30 using namespace std; 31 32 // ======================================================================== 17 33 18 34 #include "EventBuilder.h" … … 23 39 } 24 40 25 namespace ba = boost::asio; 26 namespace bs = boost::system; 27 28 using ba::ip::tcp; 29 30 using namespace std; 31 32 class DataFileImp : public MessageImp 33 { 34 uint32_t fRunId; 35 36 int Write(const Time &time, const std::string &txt, int qos) 37 { 38 return fMsg.Write(time, txt, qos); 39 } 40 41 protected: 42 MessageImp &fMsg; 43 string fFileName; 44 45 public: 46 DataFileImp(uint32_t id, MessageImp &imp) : fRunId(id), fMsg(imp) { } 47 virtual ~DataFileImp() { } 48 49 virtual bool OpenFile(RUN_HEAD* h) = 0; 50 virtual bool WriteEvt(EVENT *) = 0; 51 virtual bool Close(RUN_TAIL * = 0) = 0; 52 53 const string &GetFileName() const { return fFileName; } 54 55 uint32_t GetRunId() const { return fRunId; } 56 57 // -------------------------------------------------------------------------- 58 // 59 //! This creates an appropriate file name for a particular run number and type 60 //! @param runNumber the run number for which a filename is to be created 61 //! @param runType an int describing the kind of run. 0=Data, 1=Pedestal, 2=Calibration, 3=Calibrated data 62 //! @param extension a string containing the extension to be appened to the file name 63 // 64 static string FormFileName(uint32_t runid, const string &extension) 65 { 66 ostringstream name; 67 name << Time().NightAsInt() << '_' << setfill('0') << setw(3) << runid << '.' << extension; 68 return name.str(); 69 } 70 }; 71 72 class DataFileNone : public DataFileImp 73 { 74 public: 75 DataFileNone(uint32_t id, MessageImp &imp) : DataFileImp(id, imp) { } 76 77 Time fTime; 78 79 bool OpenFile(RUN_HEAD* h) 80 { 81 fFileName = "/dev/null"; 82 83 ostringstream str; 84 str << this << " - " 85 << "OPEN_FILE #" << GetRunId() << ":" 86 << " Ver=" << h->Version 87 << " Typ=" << h->RunType 88 << " Nb=" << h->NBoard 89 << " Np=" << h->NPix 90 << " NTm=" << h->NTm 91 << " roi=" << h->Nroi; 92 93 Debug(str); 94 95 fTime = Time(); 96 97 return true; 98 } 99 bool WriteEvt(EVENT *e) 100 { 101 const Time now; 102 if (now-fTime<boost::posix_time::seconds(5)) 103 return true; 104 105 fTime = now; 106 107 ostringstream str; 108 str << this << " - EVENT #" << e->EventNum << " / " << e->TriggerNum; 109 Debug(str); 110 111 return true; 112 } 113 bool Close(RUN_TAIL * = 0) 114 { 115 ostringstream str; 116 str << this << " - CLOSE FILE #" << GetRunId(); 117 118 Debug(str); 119 120 return true; 121 } 122 }; 123 124 #include "DrsCalib.h" 125 126 class DataFileCalib : public DataFileImp, CalibData 127 { 128 static vector<int32_t> fOffset; 129 static vector<int32_t> fGain; 130 static vector<int32_t> fTrgOff; 131 132 static vector<float> fStats; 133 134 static uint64_t fNumOffset; 135 static uint64_t fNumGain; 136 static uint64_t fNumTrgOff; 137 138 static int fStep; 139 140 DimDescribedService &fDim; 141 142 public: 143 DataFileCalib(uint32_t id, DimDescribedService &dim, MessageImp &imp) : DataFileImp(id, imp), fDim(dim) 144 { 145 } 146 147 static void Restart() 148 { 149 // Default gain: 150 // 0.575*[45590]*2.5V / 2^16 = 0.99999 V 151 fOffset.assign(1440*1024, 0); 152 fGain.assign (1440*1024, 2); 153 fTrgOff.assign(1440*1024, 0); 154 155 fNumOffset = 1; 156 fNumGain = 1; 157 fNumTrgOff = 1; 158 159 reinterpret_cast<uint32_t*>(fStats.data())[0] = 0; 160 reinterpret_cast<uint32_t*>(fStats.data())[1] = 0; 161 reinterpret_cast<uint32_t*>(fStats.data())[2] = 0; 162 163 int i=0; 164 while (i<1024*1440*2+3) // Set mean and RMS to 0 165 fStats[i++] = 0; 166 while (i<1024*1440*3+3) 167 fStats[i++] = 0.5; // Set mean to 0.5 168 while (i<1024*1440*6+3) 169 fStats[i++] = 0; // Set everything else to 0 170 171 fStep = 0; 172 } 173 174 static void Update(DimDescribedService &dim) 175 { 176 dim.Update(fStats); 177 } 178 179 bool OpenFile(RUN_HEAD* h) 180 { 181 if (fStep==4) 182 { 183 fMsg.Warn("DRS Calibration already finished... please restart!"); 184 return false; 185 } 186 187 if (h->NPix != 1440) 188 { 189 fMsg.Error("Number of pixels in header not 1440."); 190 return false; 191 } 192 193 if (h->Nroi != 1024) 194 { 195 fMsg.Error("Region of interest not 1024."); 196 return false; 197 } 198 199 ostringstream name; 200 name << "drs-calib-" << fStep; 201 fFileName = name.str(); 202 203 Reset(); 204 InitSize(1440, 1024); 205 206 fFileName = FormFileName(GetRunId(), "drs.fits"); 207 208 return true; 209 } 210 bool WriteEvt(EVENT *e) 211 { 212 // FIXME: SET StartPix to 0 if StartPix is -1 213 214 if (fStep==0) 215 { 216 AddRel(e->Adc_Data, e->StartPix); 217 } 218 if (fStep==1) 219 { 220 AddRel(e->Adc_Data, e->StartPix, fOffset.data(), fNumOffset); 221 } 222 if (fStep==2) 223 { 224 AddAbs(e->Adc_Data, e->StartPix, fOffset.data(), fNumOffset); 225 } 226 227 return true; 228 } 229 230 void WriteFits() 231 { 232 #ifdef HAVE_FITS 233 FitsFile file(fMsg); 234 235 file.AddColumn('I', "RunNumberBaseline"); 236 file.AddColumn('I', "RunNumberGain"); 237 file.AddColumn('I', "RunNumberTriggerOffset"); 238 file.AddColumn('F', "BaselineMean", 1024*1440); 239 file.AddColumn('F', "BaselineRms", 1024*1440); 240 file.AddColumn('F', "GainMean", 1024*1440); 241 file.AddColumn('F', "GainRms", 1024*1440); 242 file.AddColumn('F', "TriggerOffsetMean", 1024*1440); 243 file.AddColumn('F', "TriggerOffsetRms", 1024*1440); 244 245 if (!file.OpenFile(fFileName)) 246 return; 247 248 if (!file.OpenTable("DrsCalibration")) 249 return; 250 251 if (!file.WriteDefaultKeys("fadctrl")) 252 return; 253 254 if (!file.WriteKeyNT("STEP", fStep, "")) 255 return; 256 257 vector<char> buf; 258 buf.reserve(fStats.size()*sizeof(float)); 259 260 char *src = reinterpret_cast<char*>(fStats.data()); 261 char *end = reinterpret_cast<char*>(fStats.data()+1024*1440*6+3); 262 char *dest = buf.data(); 263 264 while (src<end) 265 { 266 reverse_copy(src, src+sizeof(float), dest); 267 src += sizeof(float); 268 dest += sizeof(float); 269 } 270 271 if (!file.AddRow()) 272 return; 273 274 if (!file.WriteData(buf.data(), 1024*1440*sizeof(float)*6+3)) 275 return; 276 #endif 277 } 278 279 bool Close(RUN_TAIL * = 0) 280 { 281 if (fStep==0) 282 { 283 fOffset.assign(fSum.begin(), fSum.end()); 284 fNumOffset = fNumEntries; 285 286 // 0.5: Scale from ADC to Millivolt 287 GetSampleStats(fStats.data()+3, 0.5); 288 reinterpret_cast<uint32_t*>(fStats.data())[0] = GetRunId();; 289 } 290 if (fStep==1) 291 { 292 fGain.assign(fSum.begin(), fSum.end()); 293 //fNumGain = fNumEntries*1000; 294 295 // DAC: 0..2.5V == 0..65535 296 // V-mV: 1000 297 for (int i=0; i<1024*1440; i++) 298 fGain[i] *= 125; 299 fNumGain = fNumEntries * 65535; 300 301 // 0.5: Scale from ADC to Millivolt 302 GetSampleStats(fStats.data()+1024*1440*2+3, 0.5); 303 reinterpret_cast<uint32_t*>(fStats.data())[1] = GetRunId();; 304 } 305 if (fStep==2) 306 { 307 fTrgOff.assign(fSum.begin(), fSum.end()); 308 fNumTrgOff = fNumEntries; 309 310 // 0.5: Scale from ADC to Millivolt 311 GetSampleStats(fStats.data()+1024*1440*4+3, 0.5); 312 reinterpret_cast<uint32_t*>(fStats.data())[2] = GetRunId();; 313 } 314 315 if (fStep>=0 && fStep<=2) 316 WriteFits(); 317 318 fDim.Update(fStats); 319 320 fStep++; 321 322 return true; 323 } 324 325 static void Apply(int16_t *val, const int16_t *start, uint32_t roi) 326 { 327 CalibData::Apply(val, start, roi, 328 fOffset.data(), fNumOffset, 329 fGain.data(), fNumGain, 330 fTrgOff.data(), fNumTrgOff); 331 } 332 333 static void Apply(float *vec, int16_t *val, const int16_t *start, uint32_t roi) 334 { 335 CalibData::Apply(vec, val, start, roi, 336 fOffset.data(), fNumOffset, 337 fGain.data(), fNumGain, 338 fTrgOff.data(), fNumTrgOff); 339 } 340 }; 341 342 int DataFileCalib::fStep = 0; 343 344 vector<int32_t> DataFileCalib::fOffset(1440*1024, 0); 345 vector<int32_t> DataFileCalib::fGain (1440*1024, 2); 346 vector<int32_t> DataFileCalib::fTrgOff(1440*1024, 0); 347 vector<float> DataFileCalib::fStats (1440*1024*6+3); 348 349 uint64_t DataFileCalib::fNumOffset = 1; 350 uint64_t DataFileCalib::fNumGain = 1; 351 uint64_t DataFileCalib::fNumTrgOff = 1; 352 353 354 class DataFileDebug : public DataFileNone 355 { 356 public: 357 DataFileDebug(uint32_t id, MessageImp &imp) : DataFileNone(id, imp) { } 358 359 bool WriteEvt(EVENT *e) 360 { 361 cout << "WRITE_EVENT #" << GetRunId() << " (" << e->EventNum << ")" << endl; 362 cout << " Typ=" << e->TriggerType << endl; 363 cout << " roi=" << e->Roi << endl; 364 cout << " trg=" << e->SoftTrig << endl; 365 cout << " tim=" << e->PCTime << endl; 366 367 return true; 368 } 369 }; 370 371 #include "FAD.h" 372 373 class DataFileRaw : public DataFileImp 374 { 375 ofstream fOut; 376 377 off_t fPosTail; 378 379 uint32_t fCounter; 380 381 382 // WRITE uint32_t 0xFAC77e1e (FACT Tele) 383 // === 384 // WRITE uint32_t TYPE(>0) == 1 385 // WRITE uint32_t ID(>0) == 0 386 // WRITE uint32_t VERSION(>0) == 1 387 // WRITE uint32_t LENGTH 388 // - 389 // WRITE uint32_t TELESCOPE ID 390 // WRITE uint32_t RUNID 391 // === 392 // WRITE uint32_t TYPE(>0) == 2 393 // WRITE uint32_t ID(>0) == 0 394 // WRITE uint32_t VERSION(>0) == 1 395 // WRITE uint32_t LENGTH 396 // - 397 // WRITE HEADER 398 // === 399 // [ 40 TIMES 400 // WRITE uint32_t TYPE(>0) == 3 401 // WRITE uint32_t ID(>0) == 0..39 402 // WRITE uint32_t VERSION(>0) == 1 403 // WRITE uint32_t LENGTH 404 // - 405 // WRITE BOARD-HEADER 406 // ] 407 // === 408 // WRITE uint32_t TYPE(>0) == 4 409 // WRITE uint32_t ID(>0) == 0 410 // WRITE uint32_t VERSION(>0) == 1 411 // WRITE uint32_t LENGTH 412 // - 413 // WRITE FOOTER (empty) 414 // === 415 // [ N times 416 // WRITE uint32_t TYPE(>0) == 10 417 // WRITE uint32_t ID(>0) == counter 418 // WRITE uint32_t VERSION(>0) == 1 419 // WRITE uint32_t LENGTH HEADER 420 // - 421 // WRITE HEADER+DATA 422 // ] 423 // === 424 // WRITE uint32_t TYPE ==0 425 // WRITE uint32_t VERSION==0 426 // WRITE uint32_t LENGTH ==0 427 // === 428 // Go back and write footer 429 430 public: 431 DataFileRaw(uint32_t id, MessageImp &imp) : DataFileImp(id, imp), fPosTail(0) { } 432 ~DataFileRaw() { if (fOut.is_open()) Close(); } 433 434 void WriteBlockHeader(uint32_t type, uint32_t ver, uint32_t cnt, uint32_t len) 435 { 436 const uint32_t val[4] = { type, ver, cnt, len }; 437 438 fOut.write(reinterpret_cast<const char*>(val), sizeof(val)); 439 } 440 441 template<typename T> 442 void WriteValue(const T &t) 443 { 444 fOut.write(reinterpret_cast<const char*>(&t), sizeof(T)); 445 } 446 447 enum 448 { 449 kEndOfFile = 0, 450 kIdentifier = 1, 451 kRunHeader, 452 kBoardHeader, 453 kRunSummary, 454 kEvent, 455 }; 456 457 bool OpenFile(RUN_HEAD *h) 458 { 459 const string name = FormFileName(GetRunId(), "bin"); 460 if (access(name.c_str(), F_OK)==0) 461 { 462 Error("File '"+name+"' already exists."); 463 return false; 464 } 465 466 fFileName = name; 467 468 errno = 0; 469 fOut.open(name.c_str(), ios_base::out); 470 if (!fOut) 471 { 472 ostringstream str; 473 str << "ofstream::open() failed for '" << name << "': " << strerror(errno) << " [errno=" << errno << "]"; 474 Error(str); 475 476 return false; 477 } 478 479 fCounter = 0; 480 481 static uint32_t FACT = 0xFAC77e1e; 482 483 fOut.write(reinterpret_cast<char*>(&FACT), 4); 484 485 WriteBlockHeader(kIdentifier, 1, 0, 8); 486 WriteValue(uint32_t(0)); 487 WriteValue(GetRunId()); 488 489 WriteBlockHeader(kRunHeader, 1, 0, sizeof(RUN_HEAD)-sizeof(PEVNT_HEADER*)); 490 fOut.write(reinterpret_cast<char*>(h), sizeof(RUN_HEAD)-sizeof(PEVNT_HEADER*)); 491 492 for (int i=0; i<40; i++) 493 { 494 WriteBlockHeader(kBoardHeader, 1, i, sizeof(PEVNT_HEADER)); 495 fOut.write(reinterpret_cast<char*>(h->FADhead+i), sizeof(PEVNT_HEADER)); 496 } 497 498 // FIXME: Split this 499 const vector<char> block(sizeof(uint32_t)+sizeof(RUN_TAIL)); 500 WriteBlockHeader(kRunSummary, 1, 0, block.size()); 501 502 fPosTail = fOut.tellp(); 503 fOut.write(block.data(), block.size()); 504 505 if (!fOut) 506 { 507 ostringstream str; 508 str << "ofstream::write() failed for '" << name << "': " << strerror(errno) << " [errno=" << errno << "]"; 509 Error(str); 510 511 return false; 512 } 513 514 return true; 515 } 516 bool WriteEvt(EVENT *evt) 517 { 518 const int sh = sizeof(EVENT)-2 + NPIX*evt->Roi*2; 519 520 WriteBlockHeader(kEvent, 1, fCounter++, sh); 521 fOut.write(reinterpret_cast<char*>(evt)+2, sh); 522 return true; 523 } 524 bool Close(RUN_TAIL *tail= 0) 525 { 526 WriteBlockHeader(kEndOfFile, 0, 0, 0); 527 528 if (tail) 529 { 530 fOut.seekp(fPosTail); 531 532 WriteValue(uint32_t(1)); 533 fOut.write(reinterpret_cast<char*>(tail), sizeof(RUN_TAIL)); 534 } 535 536 if (!fOut) 537 { 538 ostringstream str; 539 540 str << "ofstream::write() failed for '" << GetFileName() << "': " << strerror(errno) << " [errno=" << errno << "]"; 541 Error(str); 542 543 return false; 544 } 545 546 fOut.close(); 547 548 if (!fOut) 549 { 550 ostringstream str; 551 str << "ofstream::close() failed for '" << GetFileName() << "': " << strerror(errno) << " [errno=" << errno << "]"; 552 Error(str); 553 554 return false; 555 } 556 557 return true; 558 } 559 }; 560 561 #ifdef HAVE_FITS 562 563 564 class DataFileFits : public DataFileImp 565 { 566 Converter *fConv; 567 568 FitsFile fFile; 569 570 public: 571 DataFileFits(uint32_t runid, MessageImp &imp) : 572 DataFileImp(runid, imp), fFile(imp) 573 { 574 } 575 576 // -------------------------------------------------------------------------- 577 // 578 //! Default destructor 579 //! The Fits file SHOULD have been closed already, otherwise the informations 580 //! related to the RUN_TAIL will NOT be written to the file. 581 // 582 ~DataFileFits() { Close(); delete fConv; } 583 584 template <typename T> 585 void WriteKey(const string &name, const int idx, const T &value, const string &comment) 586 { 587 ostringstream str; 588 str << name << idx; 589 590 ostringstream com; 591 com << "Board " << setw(2) << idx << ": " << comment; 592 593 fFile.WriteKey(str.str(), value, com.str()); 594 } 595 596 // -------------------------------------------------------------------------- 597 // 598 //! DataFileFits constructor. This is the one that should be used, not the default one (parameter-less) 599 //! @param runid This parameter should probably be removed. I first thought it was the run number, but apparently it is not 600 //! @param h a pointer to the RUN_HEAD structure that contains the informations relative to this run 601 // 602 bool OpenFile(RUN_HEAD* h) 603 { 604 fFile.AddColumn('I', "EventNum"); 605 fFile.AddColumn('I', "TriggerNum"); 606 fFile.AddColumn('S', "TriggerType"); 607 fFile.AddColumn('I', "NumBoards"); 608 fFile.AddColumn('I', "reserved"); 609 fFile.AddColumn('I', "SoftTrig"); 610 fFile.AddColumn('I', "PCTime", 2); 611 fFile.AddColumn('I', "BoardTime", NBOARDS); 612 fFile.AddColumn('S', "StartCellData", NPIX); 613 fFile.AddColumn('S', "StartCellTimeMarker", NTMARK); 614 fFile.AddColumn('S', "Data", h->NPix*h->Nroi); 615 fFile.AddColumn('S', "TimeMarker", h->NTm*h->NroiTM); 616 617 // Write length of physical pipeline (1024) 618 619 fConv = new Converter(Converter::ToFormat(fFile.GetColumnTypes())); 620 621 const size_t sz = (h->NPix*h->Nroi + h->NTm*h->NroiTM)*2; 622 if (fConv->GetSize()-sz+4!=sizeof(EVENT)) 623 { 624 ostringstream str; 625 str << "The EVENT structure size (" << sizeof(EVENT) << ") doesn't match the described FITS row ("; 626 str << fConv->GetSize()-sz+4 << ")"; 627 Error(str); 628 return false; 629 } 630 631 //Form filename, based on runid and run-type 632 fFileName = FormFileName(GetRunId(), "fits"); 633 634 if (!fFile.OpenFile(fFileName)) 635 return false; 636 637 if (!fFile.OpenTable("Events")) 638 return false; 639 640 if (!fFile.WriteDefaultKeys("fadctrl")) 641 return false; 642 643 Info("==> TODO: Write sampling frequency..."); 644 645 //write header data 646 //first the "standard" keys 647 try 648 { 649 fFile.WriteKey("BLDVER", h->Version, "Builder version"); 650 fFile.WriteKey("RUNID", GetRunId(), "Run number"); 651 fFile.WriteKey("RUNTYPE", h->RunType, "Type of run"); 652 fFile.WriteKey("NBOARD", h->NBoard, "Number of acquisition boards"); 653 fFile.WriteKey("NPIX", h->NPix, "Number of pixels"); 654 fFile.WriteKey("NTMARK", h->NTm, "Number of Time marks"); 655 fFile.WriteKey("NROI", h->Nroi, "Number of slices per pixels"); 656 fFile.WriteKey("NROITM", h->NroiTM, "Number of slices per time-marker"); 657 658 //FIXME should we also put the start and stop time of the received data ? 659 //now the events header related variables 660 fFile.WriteKey("CAMERA", "MGeomCamFACT", ""); 661 fFile.WriteKey("DAQ", "DRS4", ""); 662 663 fFile.WriteKey("ADCCOUNT", 2.0f, "ADC Counts per milliVolt"); 664 665 666 // Write a single key for: 667 // ----------------------- 668 // Start package flag 669 // package length 670 // version number 671 // status 672 // Prescaler 673 674 // Write 40 kays for (?) 675 // Phaseshift 676 // DAC 677 678 for (int i=0; i<h->NBoard; i++) 679 { 680 const PEVNT_HEADER &hh = h->FADhead[i]; 681 682 // Header values whihc won't change during the run 683 WriteKey("ID", i, hh.board_id, "Board ID"); 684 WriteKey("DNA", i, hh.DNA, "DNA"); 685 WriteKey("FWVER", i, hh.version_no, "Firmware Version"); 686 } 687 } 688 catch (const CCfits::FitsException &e) 689 { 690 Error("CCfits::Table::addKey failed in "+fFileName+"': "+e.message()); 691 return false; 692 } 693 694 /* 695 //now the boards related keywords 696 for (int i=0; i<h->NBoard; i++) 697 { 698 const PEVNT_HEADER &hh = h->FADhead[i]; 699 700 WriteKey("STPKGFG", i, hh.start_package_flag, "Start package flag"); 701 WriteKey("PKGLEN", i, hh.package_length, "Package length"); 702 WriteKey("STATUS", i, hh.PLLLCK, ""); 703 704 // WriteKey("TRIGCRC", i, hh.trigger_crc, "Trigger CRC"); 705 // WriteKey("TRIGTYP", i, hh.trigger_type, "Trigger type"); 706 // WriteKey("TRIGID", i, hh.trigger_id, "Trigger ID"); 707 // WriteKey("EVTCNTR", i, hh.fad_evt_counter, "FAD Event Counter"); 708 // WriteKey("REFCLK", i, hh.REFCLK_frequency, "Reference Clock Frequency"); 709 710 WriteKey("PHASESH", i, hh.adc_clock_phase_shift, "ADC clock phase shift"); 711 WriteKey("TRGGEN", i, hh.number_of_triggers_to_generate, "Number of triggers to generate"); 712 WriteKey("PRESC", i, hh.trigger_generator_prescaler, "Trigger generator prescaler"); 713 WriteKey("RUNNB", i, hh.runnumber, "Run number"); 714 715 WriteKey("TIME", i, hh.time, "Time"); 716 717 // for (int j=0;j<NTemp;j++) 718 // { 719 // str.str(""); str2.str(""); 720 // str << "DRS_T" << i << j; 721 // str2 << "DRS temperature #" << i << " " << j; 722 // WriteKey(str.str(), h->FADhead[i].drs_temperature[j], str2.str()); 723 // } 724 for (int j=0;j<NDAC;j++) 725 WriteKey("DAC", i*NDAC+j, hh.dac[j], "DAC"); 726 } 727 */ 728 729 //Last but not least, add header keys that will be updated when closing the file 730 return WriteFooter(NULL); 731 } 732 733 734 735 // -------------------------------------------------------------------------- 736 // 737 //! This writes one event to the file 738 //! @param e the pointer to the EVENT 739 // 740 bool WriteEvt(EVENT *e) 741 { 742 if (!fFile.AddRow()) 743 return false; 744 745 const size_t sz = sizeof(EVENT) + sizeof(e->StartPix)*e->Roi+sizeof(e->StartTM)*e->RoiTM; 746 747 const vector<char> data = fConv->ToFits(reinterpret_cast<char*>(e)+4, sz-4); 748 749 return fFile.WriteData(data.data(), data.size()); 750 } 751 752 bool WriteFooter(RUN_TAIL *rt) 753 { 754 try 755 { 756 fFile.WriteKey("NBEVTOK", rt ? rt->nEventsOk : uint32_t(0), 757 "How many events were written"); 758 759 fFile.WriteKey("NBEVTREJ", rt ? rt->nEventsRej : uint32_t(0), 760 "How many events were rejected by SW-trig"); 761 762 fFile.WriteKey("NBEVTBAD", rt ? rt->nEventsBad : uint32_t(0), 763 "How many events were rejected by Error"); 764 765 //FIXME shouldn't we convert start and stop time to MjD first ? 766 //FIXME shouldn't we also add an MjD reference ? 767 768 fFile.WriteKey("TSTART", rt ? rt->PCtime0 : uint32_t(0), 769 "Time when first event received"); 770 771 fFile.WriteKey("TSTOP", rt ? rt->PCtimeX : uint32_t(0), 772 "Time when last event received"); 773 } 774 catch (const CCfits::FitsException &e) 775 { 776 Error("CCfits::Table::addKey failed in '"+fFile.GetName()+"': "+e.message()); 777 return false; 778 } 779 return true; 780 } 781 782 // -------------------------------------------------------------------------- 783 // 784 //! Closes the file, and before this it write the TAIL data 785 //! @param rt the pointer to the RUN_TAIL data structure 786 // 787 bool Close(RUN_TAIL *rt = 0) 788 { 789 if (!fFile.IsOpen()) 790 return false; 791 792 WriteFooter(rt); 793 794 fFile.Close(); 795 796 return true; 797 } 798 799 }; 800 #else 801 #define DataFileFits DataFileRaw 802 #endif 803 804 #include "DimWriteStatistics.h" 41 // ======================================================================== 805 42 806 43 class EventBuilderWrapper … … 885 122 while (--fRunNumber>0) 886 123 { 887 const string name = Data FileImp::FormFileName(fRunNumber, "");124 const string name = DataProcessorImp::FormFileName(fRunNumber, ""); 888 125 889 126 if (access((name+"bin").c_str(), F_OK) == 0) … … 949 186 //ffMsg.Info("EventBuilder stopped."); 950 187 951 for (vector<Data FileImp*>::iterator it=fFiles.begin(); it!=fFiles.end(); it++)188 for (vector<DataProcessorImp*>::iterator it=fFiles.begin(); it!=fFiles.end(); it++) 952 189 delete *it; 953 190 } … … 1136 373 if (fFileFormat==kCalib) 1137 374 { 1138 Data FileCalib::Restart();1139 Data FileCalib::Update(fDimDrsCalibration);375 DataCalib::Restart(); 376 DataCalib::Update(fDimDrsCalibration); 1140 377 fMsg.Message("Resetted DRS calibration."); 1141 378 } … … 1211 448 }; 1212 449 1213 for (vector<Data FileImp*>::const_iterator it=fFiles.begin();450 for (vector<DataProcessorImp*>::const_iterator it=fFiles.begin(); 1214 451 it!=fFiles.end(); it++) 1215 452 { 1216 const Data FileImp *file = *it;453 const DataProcessorImp *file = *it; 1217 454 1218 455 if (file->GetRunId()<values[1]) … … 1232 469 } 1233 470 1234 vector<Data FileImp*> fFiles;471 vector<DataProcessorImp*> fFiles; 1235 472 1236 473 FileHandle_t runOpen(uint32_t runid, RUN_HEAD *h, size_t) … … 1239 476 1240 477 // Check if file already exists... 1241 Data FileImp *file = 0;478 DataProcessorImp *file = 0; 1242 479 switch (fFileFormat) 1243 480 { 1244 case kNone: file = new Data FileNone(runid, fMsg); break;1245 case kDebug: file = new Data FileDebug(runid, fMsg); break;1246 case kFits: file = new Data FileFits(runid, fMsg); break;1247 case kRaw: file = new Data FileRaw(runid, fMsg); break;1248 case kCalib: file = new Data FileCalib(runid, fDimDrsCalibration, fMsg); break;481 case kNone: file = new DataDump(runid, fMsg); break; 482 case kDebug: file = new DataDebug(runid, fMsg); break; 483 case kFits: file = new DataWriteFits(runid, fMsg); break; 484 case kRaw: file = new DataWriteRaw(runid, fMsg); break; 485 case kCalib: file = new DataCalib(runid, fDimDrsCalibration, fMsg); break; 1249 486 } 1250 487 1251 488 try 1252 489 { 1253 if (!file->Open File(h))490 if (!file->Open(h)) 1254 491 return 0; 1255 492 } … … 1283 520 int runWrite(FileHandle_t handler, EVENT *e, size_t) 1284 521 { 1285 Data FileImp *file = reinterpret_cast<DataFileImp*>(handler);522 DataProcessorImp *file = reinterpret_cast<DataProcessorImp*>(handler); 1286 523 1287 524 if (!file->WriteEvt(e)) … … 1320 557 fMsg.Info(" ==> TODO: Update run configuration in database!"); 1321 558 1322 Data FileImp *file = reinterpret_cast<DataFileImp*>(handler);1323 1324 const vector<Data FileImp*>::iterator it = find(fFiles.begin(), fFiles.end(), file);559 DataProcessorImp *file = reinterpret_cast<DataProcessorImp*>(handler); 560 561 const vector<DataProcessorImp*>::iterator it = find(fFiles.begin(), fFiles.end(), file); 1325 562 if (it==fFiles.end()) 1326 563 { … … 1513 750 memcpy(data.data(), event, sizeof(EVENT)); 1514 751 1515 Data FileCalib::Apply(reinterpret_cast<float*>(data.data()+sizeof(EVENT)),1516 752 DataCalib::Apply(reinterpret_cast<float*>(data.data()+sizeof(EVENT)), 753 event->Adc_Data, event->StartPix, event->Roi); 1517 754 1518 755 fDimEventData.Update(data);
Note:
See TracChangeset
for help on using the changeset viewer.