Changeset 11445
- Timestamp:
- 07/18/11 16:26:48 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilderWrapper.h
r11420 r11445 18 18 extern "C" { 19 19 extern void StartEvtBuild(); 20 extern int CloseRunFile(uint32_t runId, uint32_t closeTime );20 extern int CloseRunFile(uint32_t runId, uint32_t closeTime, uint32_t maxEvt); 21 21 } 22 22 … … 399 399 str << name << idx; 400 400 401 WriteKey(str.str(), value, comment); 401 ostringstream com; 402 com << "Board " << setw(2) << idx << ": " << comment; 403 404 WriteKey(str.str(), value, com.str()); 402 405 } 403 406 … … 451 454 AddColumnEntry(colNames, dataTypes, 1, 'I', "TriggerType"); 452 455 AddColumnEntry(colNames, dataTypes, 1, 'J', "SoftTrig"); 453 AddColumnEntry(colNames, dataTypes, 1, 'J', "PCTime");456 AddColumnEntry(colNames, dataTypes, 2, 'J', "PCTime"); 454 457 AddColumnEntry(colNames, dataTypes, NBOARDS, 'J', "BoardTime"); 455 458 AddColumnEntry(colNames, dataTypes, NPIX, 'I', "StartPix"); … … 458 461 459 462 ostringstream fmt; 460 fmt << "I:1;S:1;I:1;I: 1";463 fmt << "I:1;S:1;I:1;I:2"; 461 464 fmt << ";I:" << NBOARDS; 462 465 fmt << ";S:" << NPIX; … … 488 491 //first the "standard" keys 489 492 WriteKey("EXTREL", 1.0f, "Release Number"); 490 WriteKey("TELESCOP", "FACT", "Telescope that acquired this data"); 491 WriteKey("ORIGIN", "ISDC", "Institution that wrote the file"); 492 WriteKey("CREATOR", "FACT++ Event Builder", "Program that wrote this file"); 493 494 string stringValue; 495 stringValue = Time().GetAsStr(); 496 stringValue[10]= 'T'; 497 WriteKey("DATE", stringValue, "File creation data"); 498 WriteKey("TIMESYS", "TT", "Time frame system"); 499 WriteKey("TIMEUNIT", "d", "Time unit"); 500 WriteKey("TIMEREF", "UTC", "Time reference frame"); 501 //FIXME should we also put the start and stop time of the received data ? 502 //now the events header related variables 503 WriteKey("VERSION", h->Version, "Builder version"); 504 WriteKey("NIGHT", Time().NightAsInt(), "Night as int"); 493 WriteKey("TELESCOP", "FACT", "Telescope that acquired this data"); 494 WriteKey("ORIGIN", "ISDC", "Institution that wrote the file"); 495 WriteKey("CREATOR", "fadctrl", "Program that wrote this file (FACT++ Event Builder)"); 496 497 WriteKey("PACKAGE", PACKAGE_NAME, "Package name"); 498 WriteKey("VERSION", PACKAGE_VERSION, "Package description"); 499 WriteKey("COMPILED", __DATE__" "__TIME__, "Compile time"); 500 WriteKey("REVISION", REVISION, "SVN revision"); 501 //WriteKey("CONTACT", PACKAGE_BUGREPORT, "Current package maintainer"); 502 //WriteKey("URL", PACKAGE_URL, "Current repositiory location"); 503 504 WriteKey("BLDVER", h->Version, "Builder version"); 505 505 WriteKey("RUNID", GetRunId(), "Run number"); 506 506 WriteKey("RUNTYPE", h->RunType, "Type of run"); 507 507 WriteKey("NBOARD", h->NBoard, "Number of acquisition boards"); 508 508 WriteKey("NPIX", h->NPix, "Number of pixels"); 509 WriteKey("NTM ",h->NTm, "Number of Time marks");509 WriteKey("NTMARK", h->NTm, "Number of Time marks"); 510 510 WriteKey("NROI", h->Nroi, "Number of slices per pixels"); 511 WriteKey("CAMERA", "MGeomCamFact", ""); 512 /* 511 512 const Time now; 513 WriteKey("TIMESYS", "UTC", "Time system"); 514 WriteKey("DATE", now.Iso(), "File creation date"); 515 WriteKey("NIGHT", now.NightAsInt(), "Night as int"); 516 // WriteKey("TSTART", "", "Time when first event was received") 517 // WriteKey("TSTOP", "", "Time when last event was received") 518 519 //FIXME should we also put the start and stop time of the received data ? 520 //now the events header related variables 521 WriteKey("CAMERA", "MGeomCamFACT", ""); 522 WriteKey("DAQ", "DRS4", ""); 523 524 Fatal("Write sampling frequency..."); 525 526 // Write a single key for: 527 // ----------------------- 528 // Start package flag 529 // package length 530 // version number 531 // status 532 // Prescaler 533 534 // Write 40 kays for (?) 535 // Phaseshift 536 // DAC 537 538 for (int i=0; i<h->NBoard; i++) 539 { 540 const PEVNT_HEADER &hh = h->FADhead[i]; 541 542 // Header values whihc won't change during the run 543 WriteKey("BOARDID", i, hh.board_id, "ID"); 544 WriteKey("DNA", i, hh.DNA, "DNA"); 545 WriteKey("FWVER", i, hh.version_no, "Firmware Version"); 546 } 547 548 549 /* 513 550 //now the boards related keywords 514 551 for (int i=0; i<h->NBoard; i++) … … 516 553 const PEVNT_HEADER &hh = h->FADhead[i]; 517 554 518 WriteKey("STPKGFG", i, hh.start_package_flag, 519 "Start package flag"); 520 521 WriteKey("PKGLEN", i, hh.package_length, 522 "Package length"); 523 524 WriteKey("VERNO", i, hh.version_no, 525 "Version number"); 526 527 WriteKey("STATUS", i, hh.PLLLCK, 528 ""); 529 530 // WriteKey("TRIGCRC", i, hh.trigger_crc, 531 // "Trigger CRC"); 532 533 // WriteKey("TRIGTYP", i, hh.trigger_type, 534 // "Trigger type"); 535 536 // WriteKey("TRIGID", i, hh.trigger_id, 537 // "Trigger ID"); 538 539 // WriteKey("EVTCNTR", i, hh.fad_evt_counter, 540 // "FAD Event Counter"); 541 542 // WriteKey("REFCLK", i, hh.REFCLK_frequency, 543 // "Reference Clock Frequency"); 544 545 WriteKey("BOARDID", i, hh.board_id, 546 "Board ID"); 547 548 WriteKey("PHASESH", i, hh.adc_clock_phase_shift, 549 "ADC clock phase shift"); 550 551 WriteKey("TRGGEN", i, hh.number_of_triggers_to_generate, 552 "Number of triggers to generate"); 553 554 WriteKey("PRESC", i, hh.trigger_generator_prescaler, 555 "Trigger generator prescaler"); 556 557 WriteKey("DNA", i, hh.DNA, "DNA"); 555 WriteKey("STPKGFG", i, hh.start_package_flag, "Start package flag"); 556 WriteKey("PKGLEN", i, hh.package_length, "Package length"); 557 WriteKey("STATUS", i, hh.PLLLCK, ""); 558 559 // WriteKey("TRIGCRC", i, hh.trigger_crc, "Trigger CRC"); 560 // WriteKey("TRIGTYP", i, hh.trigger_type, "Trigger type"); 561 // WriteKey("TRIGID", i, hh.trigger_id, "Trigger ID"); 562 // WriteKey("EVTCNTR", i, hh.fad_evt_counter, "FAD Event Counter"); 563 // WriteKey("REFCLK", i, hh.REFCLK_frequency, "Reference Clock Frequency"); 564 565 WriteKey("PHASESH", i, hh.adc_clock_phase_shift, "ADC clock phase shift"); 566 WriteKey("TRGGEN", i, hh.number_of_triggers_to_generate, "Number of triggers to generate"); 567 WriteKey("PRESC", i, hh.trigger_generator_prescaler, "Trigger generator prescaler"); 568 WriteKey("RUNNB", i, hh.runnumber, "Run number"); 569 558 570 WriteKey("TIME", i, hh.time, "Time"); 559 WriteKey("RUNNB", i, hh.runnumber, "Run number");560 571 561 572 // for (int j=0;j<NTemp;j++) … … 572 583 573 584 //Last but not least, add header keys that will be updated when closing the file 574 //WriteFooter(NULL);585 WriteFooter(NULL); 575 586 576 587 return true; … … 701 712 return false; 702 713 703 //WriteFooter(rt);714 WriteFooter(rt); 704 715 705 716 delete fFile; … … 817 828 fDimRuns ("FAD_CONTROL/RUNS", "I:5;C", ""), 818 829 fDimEvents ("FAD_CONTROL/EVENTS", "I:4", ""), 819 fDimEventData ("FAD_CONTROL/EVENT_DATA", "S:1;I:1;S:1;I:2;S:1;S", ""),830 fDimEventData ("FAD_CONTROL/EVENT_DATA", "S:1;I:1;S:1;I:1;I:2;I:40;S:1440;S:160;S", ""), 820 831 fDimFwVersion ("FAD_CONTROL/FIRMWARE_VERSION", "F:42", ""), 821 832 fDimRunNumber ("FAD_CONTROL/RUN_NUMBER", "I:42", ""), … … 856 867 } 857 868 858 uint32_t IncreaseRunNumber() 859 { 869 map<uint32_t, pair<uint32_t, uint32_t>> fExpectedRuns; 870 871 uint32_t StartNewRun() 872 { 873 uint32_t maxtime = 0; 874 uint32_t maxevt = 0; 875 876 if (maxtime==0) 877 maxtime = 24*60*60; 878 if (maxevt==0) 879 maxevt = 2147483646; 880 881 maxtime = 60; 882 maxevt = 10; 883 884 fExpectedRuns[fRunNumber] = make_pair(maxtime, maxevt); 860 885 return fRunNumber++; 861 886 } 862 863 uint32_t GetRunNumber() const { return fRunNumber; }864 887 865 888 bool IsThreadRunning() … … 1046 1069 // size_t GetUsedMemory() const { return gi_usedMem; } 1047 1070 1048 virtual int CloseOpenFiles() { CloseRunFile(0, 0 ); return 0; }1071 virtual int CloseOpenFiles() { CloseRunFile(0, 0, 0); return 0; } 1049 1072 1050 1073 … … 1301 1324 } 1302 1325 1303 struct DimEventData1304 {1305 uint16_t Roi ; // #slices per pixel (same for all pixels and tmarks)1306 uint32_t EventNum ; // EventNumber as from FTM1307 uint16_t TriggerType ; // Trigger Type from FTM1308 1309 uint32_t PCTime ; // when did event start to arrive at PC1310 uint32_t BoardTime; //1311 1312 int16_t StartPix; // First Channel per Pixel (Pixels sorted according Software ID) ; -1 if not filled1313 int16_t StartTM; // First Channel for TimeMark (sorted Hardware ID) ; -1 if not filled1314 1315 uint16_t Adc_Data[]; // final length defined by malloc ....1316 1317 } __attribute__((__packed__));;1318 1319 1326 int eventCheck(PEVNT_HEADER *fadhd, EVENT *event) 1320 1327 { … … 1331 1338 */ 1332 1339 1340 // Check consistency of: 1341 // ===================== 1342 1343 // Write a single key for: 1344 // ----------------------- 1345 // Start package flag 1346 // package length 1347 // version number 1348 // status 1349 // Prescaler 1350 1351 // Write 40 kays for (?) 1352 // Phaseshift 1353 // DNA 1354 // DAC 1355 1356 1357 /* 1358 uint16_t start_package_flag; 1359 uint16_t package_length; 1360 uint16_t version_no; 1361 uint16_t PLLLCK; 1362 1363 uint16_t trigger_crc; 1364 uint16_t trigger_type; 1365 uint32_t trigger_id; 1366 1367 uint32_t fad_evt_counter; 1368 uint32_t REFCLK_frequency; 1369 1370 uint16_t board_id; 1371 uint8_t zeroes; 1372 int8_t adc_clock_phase_shift; 1373 uint16_t number_of_triggers_to_generate; 1374 uint16_t trigger_generator_prescaler; 1375 1376 uint64_t DNA; 1377 1378 uint32_t time; 1379 uint32_t runnumber; 1380 1381 int16_t drs_temperature[NTemp]; 1382 1383 int16_t dac[NDAC]; 1384 */ 1385 1386 1333 1387 static Time oldt(boost::date_time::neg_infin); 1334 1388 Time newt; … … 1339 1393 oldt = newt; 1340 1394 1341 static DimEventData *data = 0; 1342 1343 const size_t sz = sizeof(DimEventData)+event->Roi*2*1440; 1344 1345 if (data && data->Roi != event->Roi) 1346 { 1347 delete data; 1348 data = 0; 1349 } 1350 1351 if (!data) 1352 data = reinterpret_cast<DimEventData*>(new char[sz]); 1353 1354 // cout << sizeof(DimEventData) << " " << event->Roi << " " << sz << " " << sizeof(*data) << endl; 1355 1356 data->Roi = event->Roi; 1357 data->EventNum = event->EventNum; 1358 data->TriggerType = event->TriggerType; 1359 data->PCTime = event->PCTime; 1360 data->BoardTime = event->BoardTime[0]; 1361 data->StartPix = event->StartPix[0]; 1362 data->StartTM = event->StartTM[0]; 1363 1364 memcpy(data->Adc_Data, event->Adc_Data, event->Roi*2*1440); 1365 1366 fDimEventData.setData(data, sz); 1395 const size_t sz = sizeof(EVENT)+event->Roi*2*1440; 1396 1397 fDimEventData.setData(event, sz); 1367 1398 fDimEventData.updateService(); 1368 1399 … … 1372 1403 } 1373 1404 1374 set<uint32_t> fStartedRuns; 1375 1376 bool IsRunStarted(uint32_t runno) const 1377 { 1378 return fStartedRuns.find(runno)!=fStartedRuns.end(); 1405 bool IsRunStarted() const 1406 { 1407 return fExpectedRuns.find(fRunNumber-1)==fExpectedRuns.end(); 1379 1408 } 1380 1409 1381 1410 void gotNewRun(int runnr, PEVNT_HEADER *headers) 1382 1411 { 1383 fStartedRuns.insert(runnr); 1412 // This function is called even when writing is switched off 1413 const map<uint32_t,pair<uint32_t,uint32_t>>::iterator it = fExpectedRuns.find(runnr); 1414 if (it==fExpectedRuns.end()) 1415 { 1416 ostringstream str; 1417 str << "gotNewRun - Run " << runnr << " wasn't expected." << endl; 1418 return; 1419 } 1420 1421 CloseRunFile(runnr, time(NULL)+it->second.first, it->second.second); 1422 // return: 0=close scheduled / >0 already closed / <0 does not exist 1423 1424 fExpectedRuns.erase(it); 1384 1425 } 1385 1426
Note:
See TracChangeset
for help on using the changeset viewer.