static bool mustBreakBeam(int t, int bn, TabTrack *trk) { int bv = 1; // this bar's beat value as duration switch (trk->bars()[bn].time2) { case 1: bv = 480; break; case 2: bv = 240; break; case 4: bv = 120; break; case 8: bv = 60; break; case 16: bv = 30; break; case 32: bv = 15; break; default: bv = 1; break; // safe default } int ts = tStart(t, bn, trk); // note start int te = ts + trk->c[t].fullDuration(); // note end int bs = ts / bv; // beat where note starts int be = te / bv; // beat where note ends return (bs != be); }
// Main Program int main( int nArgs, char **args ) { // Read command line parameters if ( nArgs < 3 ) { std::cout << "Please specify output filename and run time (seconds)." << std::endl; return 1; } std::string outFileName(args[1]); int runTime(30); { std::stringstream tmp; tmp << std::string(args[2]); tmp >> runTime; } std::cout << "LED triggered run for " << runTime << " seconds: " << outFileName << std::endl; // Create the ROOT Application (to draw canvases) TApplication *theApp = new TApplication("LEDRun",&nArgs,args); //gStyle->SetPalette(1); // Configure the Argonne Board int err(0); uint nSamples = 600; //1024; // max = 2046 uint preTrigSamples = 50; err = ConfigArgoBoard_ExtTrig( nSamples, preTrigSamples ); if ( err != 0 ) { std::cout << "Failed to configure ANL Digitizer." << std::endl; return err; } // Get ANL Digitizer configuration info uint ANL_nSamples(0); DeviceRead(lbneReg.readout_window[0],&ANL_nSamples); uint ANL_preTrigSize(0); DeviceRead(lbneReg.readout_pretrigger[0],&ANL_preTrigSize); uint ANL_eventSize = sizeof(Event_Header) + 2*nSamples; // in bytes uint m1Size(0); DeviceRead(lbneReg.m1_window[0],&m1Size); uint m2Size(0); DeviceRead(lbneReg.m2_window[0],&m2Size); uint pWindow(0); DeviceRead(lbneReg.p_window[0],&pWindow); uint kWindow(0); DeviceRead(lbneReg.k_window[0],&kWindow); uint iWindow(0); DeviceRead(lbneReg.i_window[0],&iWindow); uint dWindow(0); DeviceRead(lbneReg.d_window[0],&dWindow); // Output File TFile *outFile = new TFile(outFileName.c_str(),"RECREATE"); TDirectory *waveDir = outFile->mkdir("waveforms"); std::vector<TH1D*> waveformExamples; // Set up output ROOT tree for ANL Digitizer TTree *ANLTree = new TTree("ANLTree","ANLTree"); Event_Packet ArPacket; Event ArEvent; ANLTree->Branch("channelID",&(ArEvent.channelID),"channelID/s"); ANLTree->Branch("syncDelay",&(ArEvent.syncDelay),"syncDelay/i"); ANLTree->Branch("syncCount",&(ArEvent.syncCount),"syncCount/i"); ANLTree->Branch("timestamp",&(ArEvent.intTimestamp),"timestamp/l"); ANLTree->Branch("peakSum",&(ArEvent.peakSum),"peakSum/I"); ANLTree->Branch("peakTime",&(ArEvent.peakTime),"peakTime/C"); ANLTree->Branch("prerise",&(ArEvent.prerise),"prerise/i"); ANLTree->Branch("integratedSum",&(ArEvent.integratedSum),"integratedSum/i"); ANLTree->Branch("baseline",&(ArEvent.baseline),"baseline/s"); ANLTree->Branch("cfdPoint",&(ArEvent.cfdPoint),"cfdPoint[4]/S"); ANLTree->Branch("nSamples",&(ArEvent.waveformWords),"nSamples/s"); std::stringstream waveformDescr; waveformDescr << "waveform[" << nSamples << "]/s"; ANLTree->Branch("waveform",&(ArEvent.waveform),waveformDescr.str().c_str()); // Set up configuration ROOT tree TTree *configTree = new TTree("configTree","configTree"); configTree->Branch("runTime",&runTime,"runTime/I"); configTree->Branch("ANL_nSamples",&ANL_nSamples,"ANL_nSamples/i"); configTree->Branch("ANL_preTrigSize",&ANL_preTrigSize,"ANL_preTrigSize/i"); configTree->Branch("m1Size",&m1Size,"m1Size/i"); configTree->Branch("m2Size",&m2Size,"m2Size/i"); configTree->Branch("pWindow",&pWindow,"pWindow/i"); configTree->Branch("kWindow",&kWindow,"kWindow/i"); configTree->Branch("iWindow",&iWindow,"iWindow/i"); configTree->Branch("dWindow",&dWindow,"dWindow/i"); configTree->Fill(); configTree->Write(); // Monitoring histograms TH1D *ANL_pulseAmp[32]; for ( int chan = 0; chan < 12; ++chan ) { std::stringstream histName; histName << "ANL_pulseAmp_CH" << chan; std::stringstream histTitle; histTitle << "Pulse Amplitudes, ANL Channel " << chan << ";ADC Counts"; ANL_pulseAmp[chan] = new TH1D(histName.str().c_str(),histTitle.str().c_str(),3000,0,3000); } std::cout << "Starting acquisition." << std::endl; // Enable boards err = DeviceTimeout(500); err = DeviceStart(); // Loop for specified time int totArEvts(0); time_t tStart(0), tEnd(0); time(&tStart); time(&tEnd); while ( tEnd - tStart < runTime ) { /*** ANL Digitizer Readout ***/ uint dataSize; err = DeviceQueueStatus(&dataSize); // How many full events have been collected? if ( err != 0 ) { std::cout << "Failed device queue status check." << std::endl; break; } uint ANL_nEvts = uint(dataSize) / ANL_eventSize; //if ( ANL_nEvts > 0 ) std::cout << "Received " << ANL_nEvts << " events on the Argonne Digitizer (" << dataSize << " bytes)." << std::endl; for ( uint evt = 0; evt < ANL_nEvts; ++evt ) { totArEvts++; uint dataReceived = 0; err = DeviceReceive(&ArPacket,&dataReceived); if ( err != 0 ) { std::cout << "Failed device receive." << std::endl; break; } err = LBNE_EventUnpack(&ArPacket,&ArEvent); if ( err != 0 ) { std::cout << "Failed to unpack data." << std::endl; break; } ANLTree->Fill(); ANL_pulseAmp[ArEvent.channelID]->Fill(ArEvent.prerise/double(kWindow)-ArEvent.peakSum/double(m1Size)); /* std::stringstream waveHistName; waveHistName << "waveform_" << totArEvts; TH1D *hist = new TH1D(waveHistName.str().c_str(),waveHistName.str().c_str(),nSamples,0,nSamples); for ( uint samp = 0; samp < nSamples; ++samp ) { hist->SetBinContent(samp+1,ArEvent.waveform[samp] & 0x3FFF); // 0x3FFF drops time marks on waveform, not necessary in next firmware upgrade } waveformExamples.push_back(hist); */ } //std::cout << tEnd-tStart << std::endl; time(&tEnd); } //// Finalize // Finalize Argonne Digitizer err = DeviceStopReset(); if ( err != 0 ) { std::cout << "Failed to stop and reset board 0. ErrorCode " << err << std::endl; return 1; } err = DeviceDisconnect(commUSB); // Write and close output file ANLTree->Write(); for ( int chan = 0; chan < 12; ++chan ) ANL_pulseAmp[chan]->Write(); waveDir->cd(); for ( uint i = 0; i < waveformExamples.size(); ++i ) { waveformExamples[i]->Write(); } outFile->cd(); outFile->Close(); // Done! std::cout << "Done! Collected " << totArEvts/12 << " events" << std::endl; return 0; }
int LandSimulation(int landfg,char* strInputFilePath,CProgressWnd* pwndProgress) { CString ReportFilePath(strInputFilePath); ReportFilePath.TrimRight("inp"); CString OutputFilePath = ReportFilePath; ReportFilePath += "rpt"; OutputFilePath += "out"; char* strReportFilePath = ReportFilePath.GetBuffer(ReportFilePath.GetLength()); char* strOutputFilePath = OutputFilePath.GetBuffer(OutputFilePath.GetLength()); // initialize progress bar pwndProgress->SetRange(0, 100); pwndProgress->SetText(""); CString strMsg, strForDdg, strE; COleDateTime time_i; // time at the beginning of the simulation COleDateTime time_f; // time at the end of the simulation COleDateTimeSpan time_dif; // simulation run time SYSTEMTIME tm; // system time GetLocalTime(&tm); time_i = COleDateTime(tm); long newHour, oldHour = 0; DateTime elapsedTime = 0.0; // --- open the files & read input data ErrorCode = 0; swmm_open(strInputFilePath,strReportFilePath,strOutputFilePath); // --- run the simulation if input data OK if ( !ErrorCode ) { // --- initialize values swmm_start(TRUE); // --- execute each time step until elapsed time is re-set to 0 if ( !ErrorCode ) { int y, m, d; datetime_decodeDate(StartDateTime, &y, &m, &d); COleDateTime tStart(y,m,d,0,0,0); datetime_decodeDate(EndDateTime, &y, &m, &d); COleDateTime tEnd(y,m,d,0,0,0); COleDateTimeSpan span0 = tEnd - tStart; do { swmm_step(&elapsedTime); newHour = elapsedTime * 24.0; COleDateTimeSpan span = COleDateTimeSpan(0,newHour,0,0); COleDateTime tCurrent = tStart + span; int nSYear = tCurrent.GetYear(); int nSMonth = tCurrent.GetMonth(); int nSDay = tCurrent.GetDay(); int nSHour = tCurrent.GetHour(); GetLocalTime(&tm); time_f = COleDateTime(tm); time_dif = time_f - time_i; int dd_elap = int(time_dif.GetDays()); int hh_elap = int(time_dif.GetHours()); int mm_elap = int(time_dif.GetMinutes()); int ss_elap = int(time_dif.GetSeconds()); if ( newHour > oldHour ) { oldHour = newHour; if (landfg == 0) strMsg.Format("Land Simulation:\t Pre-Development Scenario\n"); else strMsg.Format("Land Simulation:\t Post-Development Scenario\n"); strForDdg = strMsg; strMsg.Format("Calculating:\t %02d-%02d-%04d\n", nSMonth, nSDay, nSYear); strForDdg += strMsg; strE.Format("\nTime Elapsed:\t %02d:%02d:%02d:%02d\n", dd_elap, hh_elap, mm_elap, ss_elap); strForDdg += strE; double lfPart = span.GetTotalSeconds(); double lfAll = span0.GetTotalSeconds(); double lfPerc = lfPart/lfAll; if(pwndProgress->GetSafeHwnd() != NULL && nSHour == 0) { pwndProgress->SetText(strForDdg); pwndProgress->SetPos((int)(lfPerc*100)); pwndProgress->PeekAndPump(); } if (pwndProgress->Cancelled()) { pwndProgress->DestroyWindow(); AfxMessageBox("BMP simulation is cancelled"); break; } } } while ( elapsedTime > 0.0 && !ErrorCode ); } // --- clean up swmm_end(); } // --- report results swmm_report(); // --- close the system swmm_close(); //return ErrorCode; return ErrorCode; }
int CCaHtmlParse::ParseCaHtmlFlights(std::list<SCaLowPriceFlightDetail*> & listFlight, const std::string& strHtmlData, const CStringA & straDCode, const CStringA & straACode, const SCaLowPriceFlightInfo* pLowPriceFlightInfo) { TidyDoc doc = tidyCreate(); tidySetCharEncoding(doc,"raw"); tidyParseString(doc,strHtmlData.c_str()); TidyNode tnRoot = tidyGetRoot(doc); TidyNode tFlightTab; TidyNode tdChild; int nIndexTd = 0; CTime tCurrent = CTime::GetCurrentTime(); SCaLowPriceFlightDetail *pfindFlight = NULL; if (FindNode(tnRoot,"class","CA_table mt_10 clear",tFlightTab)) { //循环解析结算价,tblPolicy下的每一个子节点即为一条结算价信息 TidyNode trFlight; int nIndexTr = 0; BOOL bValid = FALSE; CStringA straDPortCode = straDCode; CStringA straAPortCode = straACode; CStringA straFlightNo(""); CStringA straFlightStartDate(""); CStringA straSaleEndDate(""); CStringA straSaleEndTime(""); CStringA straFlightStartTime(""); UINT uPrice = 0; UINT uRemainTicket = 0; for ( trFlight = tidyGetChild(tFlightTab); trFlight; trFlight = tidyGetNext(trFlight) ) { if (0 == nIndexTr)//跳过表头 { nIndexTr++; continue; } nIndexTd = 0; bValid = FALSE; straFlightNo = ""; straFlightStartDate = ""; straSaleEndDate = ""; straSaleEndTime = ""; straFlightStartTime = ""; uPrice = 0; uRemainTicket = 0; for ( tdChild = tidyGetChild(trFlight); tdChild; tdChild = tidyGetNext(tdChild) ) { switch(nIndexTd) { case 0: { //选择,是否为disabled bValid = __IsFlightValid(tdChild); TRACE(_T("Flight valid:%d-"), bValid); } break; case 1: { //日期/航班号 //dumpNode(tdChild, 0); //TRACE(_T("\r\n")); __GetFlightNoAndFlightStartDate(straFlightNo, straFlightStartDate, doc, tdChild); TRACE("date:%s, no:%s-", straFlightStartDate, straFlightNo); //TRACE("%s\r\n", GetNodeContent(doc, tdChild)); } break; case 2: { //起降时间 //dumpNode(tdChild, 0); //TRACE(_T("\r\n")); //TRACE("%s\r\n", GetNodeContent(doc, tdChild)); __GetFlightStartTime(straFlightStartTime, doc, tdChild); } break; case 3: { //机场 //dumpNode(tdChild, 0); //TRACE(_T("\r\n")); //TRACE("%s\r\n", GetNodeContent(doc, tdChild)); if (__IsTwoAirPort(straDCode, straACode)) { __GetAirPortCode(straDPortCode, straAPortCode, doc, tdChild); if(straDPortCode.IsEmpty()) straDPortCode = straDCode; if(straAPortCode.IsEmpty()) straAPortCode = straACode; TRACE("%s->%s-", straDPortCode, straAPortCode); } } break; case 4: { //销售结束日期,时间 //dumpNode(tdChild, 0); //TRACE(_T("\r\n")); //TRACE("%s\r\n", GetNodeContent(doc, tdChild)); __GetSaleEndDate(straSaleEndDate, straSaleEndTime, doc, tdChild); TRACE("sale end date:%s, %s-", straSaleEndDate, straSaleEndTime); } break; case 5: { //团购价 //dumpNode(tdChild, 0); //TRACE(_T("\r\n")); //TRACE("%s\r\n", GetNodeContent(doc, tdChild)); //CStringA straSetPrice = GetNodeContent(doc, tdChild); //double fSetPrice = atof(straSetPrice.GetBuffer(0)); //straSetPrice.ReleaseBuffer(); //tidyRelease(doc); //return fSetPrice; __GetPriceAndRamainTicket(&uPrice, &uRemainTicket, doc, tdChild); TRACE("price:%d, remain %d seats", uPrice, uRemainTicket); } break; } nIndexTd++; } TRACE(_T("\r\n")); //截至日期之后的航班不抓取 //得到起飞日期 int nFlightStartYear = 2014; int nFlightStartMonth = 12; int nFlightStartDay = 12; GetYearMonthDay(straFlightStartDate, &nFlightStartYear, &nFlightStartMonth, &nFlightStartDay); CTime tStart(nFlightStartYear, nFlightStartMonth, nFlightStartDay, 0, 0, 0); //if (!m_bGetAllCaTuanFlight) //{ // if (tStart > m_tGetEndTime) // continue; //} // //double d6 = pLowPriceFlightInfo->iMinHangPrice * 0.6; //UINT u6 = (UINT)d6; ////6折以上普通团购退改签要收费(低价申请不受限制),所以不上 //if (uPrice > d6 && CA_TUAN_PRODUCT == pLowPriceFlightInfo->iProductType) //{ // bValid = FALSE; // uRemainTicket = 0; // continue; //} //相同日期、时间、班次的航班,只取最低价 BOOL bFind = __findCaFlight(&pfindFlight, straFlightStartDate, straDPortCode, straAPortCode, straFlightNo, listFlight); if (bFind) { int nCurPrice = (int)uPrice; //当前解析出的这个比上次解析出的便宜 if(pfindFlight->nPrice > nCurPrice) { if (uRemainTicket > m_nMinTicketWarnNum) { //当前票的数量充足时,用当前票的数量更新上次解析出的数量 pfindFlight->nRemainSeat = uRemainTicket; pfindFlight->nPrice = nCurPrice; pfindFlight = NULL; } } else //(pfindFlight->nPrice <= nCurPrice) { if(pfindFlight->nRemainSeat <= m_nMinTicketWarnNum) { pfindFlight->nRemainSeat = uRemainTicket; pfindFlight->nPrice = nCurPrice; pfindFlight = NULL; } } continue; } //保存解析出来的航班信息,调用者负责释放内存 if (bValid) { SCaLowPriceFlightDetail* pDetail = new SCaLowPriceFlightDetail; pDetail->straCompany = "CA"; pDetail->straFromCityCode = straDPortCode; pDetail->straToCityCode = straAPortCode; pDetail->straFlightNo = straFlightNo; pDetail->straFromDate = straFlightStartDate; //由于携程订单进入需要一定的时间,国航下班16:00下班,所以当天的票,第2天12:00之前的票,销售结束时间提前30分钟, //取销售间隔 int nSaleEndYear = 2014; int nSaleEndMonth = 12; int nSaleEndDay = 12; GetYearMonthDay(straSaleEndDate, &nSaleEndYear, &nSaleEndMonth, &nSaleEndDay); int nSaleEndHour = 12; int nSaleEndMin = 0; GetHourMinSec(straSaleEndTime, &nSaleEndHour, &nSaleEndMin); CTime tSaleEndDate(nSaleEndYear, nSaleEndMonth, nSaleEndDay, nSaleEndHour, nSaleEndMin, 0); CTimeSpan tSpan = tSaleEndDate - tCurrent; //end 取销售间隔 //得到起飞时间 int nFlightStartHour = 12; int nFlightStartMin = 0; GetHourMinSec(straFlightStartTime, &nFlightStartHour, &nFlightStartMin); CTime tFlightStartTime(nFlightStartYear, nFlightStartMonth, nFlightStartDay, nFlightStartHour, nFlightStartMin, 0); CTime tTimeKey(nFlightStartYear, nFlightStartMonth, nFlightStartDay, 12, 0, 0); //end 得到起飞时间 //今明两天的、起飞时间在12点之前、且是低价申请的,销售结束时间为 前一天的官网销售结束的前30分钟 if ((CA_TUAN_LOW_PRICE_APPLY_PRODUT == pLowPriceFlightInfo->iProductType) && (1 == tSpan.GetDays()))//明天的的低价申请 { if(tFlightStartTime <= tTimeKey)//明天12起飞的低价申请, 今天下午3:25前有效(国航4点下班) { pDetail->straSaleEndDate.Format("%d-%02d-%02d", tCurrent.GetYear(), tCurrent.GetMonth(), tCurrent.GetDay()); CTime tSaleEnd(tCurrent.GetYear(), tCurrent.GetMonth(), tCurrent.GetDay(), 15, 25, 0); pDetail->straSaleEndTime.Format("%02d:%02d:%02d", tSaleEnd.GetHour(), tSaleEnd.GetMinute(), 0); } else//明天12后起飞的低价申请,明早可以出票 { pDetail->straSaleEndDate = straSaleEndDate; pDetail->straSaleEndTime.Format("%02d:%02d:%02d", nSaleEndHour, nSaleEndMin, 0); } } else if ((CA_TUAN_LOW_PRICE_APPLY_PRODUT == pLowPriceFlightInfo->iProductType) && (tSpan.GetDays() < 1))//今天的的低价申请,今天下午3:30前有效(国航4点下班) { pDetail->straSaleEndDate.Format("%d-%02d-%02d", tCurrent.GetYear(), tCurrent.GetMonth(), tCurrent.GetDay()); CTime tSaleEnd(tCurrent.GetYear(), tCurrent.GetMonth(), tCurrent.GetDay(), 15, 30, 0); pDetail->straSaleEndTime.Format("%02d:%02d:%02d", tSaleEnd.GetHour(), tSaleEnd.GetMinute(), 0); } else//普通团购,后天及以后的低价申请 { pDetail->straSaleEndDate = straSaleEndDate; pDetail->straSaleEndTime.Format("%02d:%02d:%02d", nSaleEndHour, nSaleEndMin, 0); } //政策销售时间到,删除政策 GetYearMonthDay(pDetail->straSaleEndDate, &nSaleEndYear, &nSaleEndMonth, &nSaleEndDay); int nSaleEndSec = 0; GetHourMinSec(pDetail->straSaleEndTime, &nSaleEndHour, &nSaleEndMin, &nSaleEndSec); CTime tPolicyDeleteTime(nSaleEndYear, nSaleEndMonth, nSaleEndDay, nSaleEndHour, nSaleEndMin, nSaleEndSec); if (tCurrent >= tPolicyDeleteTime) uRemainTicket = 0; pDetail->nPrice = uPrice; pDetail->nProductId = pLowPriceFlightInfo->iProductId; pDetail->nRemainSeat = uRemainTicket; pDetail->nProductType = pLowPriceFlightInfo->iProductType; listFlight.push_back(pDetail); } } } tidyRelease(doc); return -1.0; }