void NTupleEventReader::readDataTypes() { TIter nextFile(input->GetListOfFiles()); TChainElement* file = 0; while ((file = (TChainElement*) nextFile()) != 0) { string fileName = file->GetTitle(); DataType::value type = getDataType(fileName); seenDataTypes.at(type) = true; } }
bool Directory::nextFile(void) { if(!mDir) return false; mDirent = readdir(mDir); if(!mDirent) return false; if(fileName() == ".") return nextFile(); if(fileName() == "..") return nextFile(); return true; }
MoveDialog::MoveDialog(QFileInfoList *fileList, QDir *destinationDir, bool deleteAfter, QWidget *parent) : QDialog(parent), ui(new Ui::MoveDialog), fileCopierThread(new QThread()), fileCopier(new FilesCopier()) { ui->setupUi(this); if (deleteAfter) this->setWindowTitle("Moving"); else this->setWindowTitle("Copying"); fileCopier->setSourceFileList(fileList); fileCopier->setDestinatonDir(destinationDir); fileCopier->setDeleteAfter(deleteAfter); //thread settings fileCopier->moveToThread(fileCopierThread); connect(fileCopier, SIGNAL(nextFile(QString)), ui->lFile, SLOT(setText(QString))); connect(fileCopier, SIGNAL(addToLog(QString)), this, SLOT(addToLog(QString))); connect(fileCopier, SIGNAL(progressChanged(int)), ui->pB_Progress, SLOT(setValue(int))); connect(fileCopierThread, SIGNAL(started()), fileCopier, SLOT(copy())); connect(fileCopier, SIGNAL(finished()), fileCopierThread, SLOT(quit()), Qt::DirectConnection); connect(fileCopier, SIGNAL(finished()), this, SLOT(finished())); fileCopierThread->start(); }
/* nextGraph: * Read and return next graph; return NULL if done. * Read graph from currently open file. If none, open next file. */ Agraph_t *nextGraph(ingraph_state * sp) { Agraph_t *g; if (sp->fp == NULL) nextFile(sp); g = NULL; while (sp->fp != NULL) { if ((g = sp->fns->readf(sp->fp)) != 0) break; if (sp->Files) /* Only close if not using stdin */ sp->fns->closef(sp->fp); nextFile(sp); } return g; }
void t4p::ExplorerFileSystemActionClass::BackgroundWork() { std::vector<wxFileName> files; std::vector<wxFileName> subDirs; wxString error; int totalFiles = 0; int totalSubDirs = 0; wxString name; int flags = DoHidden ? (wxDIR_FILES | wxDIR_HIDDEN) : wxDIR_FILES; wxDir fileDir; if (fileDir.Open(Dir.GetPath())) { if (fileDir.GetFirst(&name, wxEmptyString, flags)) { totalFiles++; if (MatchesWildcards(name)) { wxFileName f(Dir.GetPath(), name); files.push_back(f); } while (fileDir.GetNext(&name) && !IsCancelled()) { totalFiles++; if (MatchesWildcards(name)) { wxFileName nextFile(Dir.GetPath(), name); files.push_back(nextFile); } } } } else { error = _("Could not open directory:") + Dir.GetFullPath(); } // now get sub directories if (!IsCancelled()) { flags = DoHidden ? (wxDIR_DIRS | wxDIR_HIDDEN) : wxDIR_DIRS; wxDir dirDir; if (dirDir.Open(Dir.GetFullPath())) { if (dirDir.GetFirst(&name, wxEmptyString, flags)) { totalSubDirs++; wxFileName d; d.AssignDir(Dir.GetPathWithSep() + name); subDirs.push_back(d); while (dirDir.GetNext(&name) && !IsCancelled()) { totalSubDirs++; wxFileName nextDir; nextDir.AssignDir(Dir.GetPathWithSep() + name); subDirs.push_back(nextDir); } } } else { error = _("Could not open directory:") + Dir.GetFullPath(); } } if (!IsCancelled()) { std::sort(files.begin(), files.end(), FileNameCmp); std::sort(subDirs.begin(), subDirs.end(), DirNameCmp); // PostEvent() will set the correct ID t4p::ExplorerEventClass evt(wxID_ANY, Dir, files, subDirs, error, totalFiles, totalSubDirs); PostEvent(evt); } }
void ViNoiseBatcher::process() { QObject::disconnect(mCurrentObject.data(), SIGNAL(decoded()), this, SLOT(process())); qint64 time; ViNoiseCreator creator; creator.createNoise(mCurrentObject->buffer(ViAudio::Target), mCurrentObject->buffer(ViAudio::Corrupted), mCurrentObject->buffer(ViAudio::CustomMask), mCurrentObject->buffer(ViAudio::Custom)); mCurrentObject->clearBuffer(ViAudio::Target); mCurrentObject->clearBuffer(ViAudio::CustomMask); ViClassificationErrorCollection errors; //do //{ mCurrentObject->clearBuffer(ViAudio::Noise); for(int i = 0; i < mParamsStart.size(); ++i) mDetector->setParameter(mParamsNames[i], mParamsCurrent[i]); if(mDetector->validParameters()) { mTime.restart(); mDetector->detect(mCurrentObject->buffer(ViAudio::Corrupted), mCurrentObject->buffer(ViAudio::Noise)); time = mTime.elapsed(); errors = mDetector->error(mCurrentObject->buffer(ViAudio::Noise), mCurrentObject->buffer(ViAudio::Custom), mThreshold); // Write /* QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit())); mCurrentObject->encode(ViAudio::Noise); return;*/ /*calculateThreshold(mCurrentObject->buffer(ViAudio::Noise), mCurrentObject->buffer(ViAudio::Custom), bestThreshold, bestErrors, bestMatthews, maxNoise); if(bestMatthews > maxMatthews) maxMatthews = bestMatthews; clearProgress();*/ // Write /*mDetector->mask(mCurrentObject->buffer(ViAudio::Noise), mCurrentObject->buffer(ViAudio::NoiseMask), 0.15, 8); QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit())); mCurrentObject->encode(ViAudio::NoiseMask); return;*/ } else { time = 0; } ++mDoneParamIterations; printFileData(errors, time); printTerminal(errors, time); //} //while(nextParam()); nextFile(); }
/* nextGraph: * Read and return next graph; return NULL if done. * Read graph from currently open file. If none, open next file. */ Agraph_t *nextGraph(ingraph_state * sp) { Agraph_t *g; if (sp->ingraphs) { g = (Agraph_t*)(sp->u.Graphs[sp->ctr]); if (g) sp->ctr++; return g; } if (sp->fp == NULL) nextFile(sp); g = NULL; while (sp->fp != NULL) { if ((g = sp->fns->readf(sp->fp)) != 0) break; if (sp->u.Files) /* Only close if not using stdin */ sp->fns->closef(sp->fp); nextFile(sp); } return g; }
void KoOdfCollectionLoader::load() { QDir dir(m_path); m_fileList = dir.entryList(QStringList() << "*.odg" << "*.svg", QDir::Files); if(m_fileList.isEmpty()) { kError() << "Found no shapes in the collection!" << m_path; emit loadingFailed(i18n("Found no shapes in the collection! %1", m_path)); return; } nextFile(); }
DataFile* MmapV1ExtentManager::_addAFile(OperationContext* txn, int sizeNeeded, bool preallocateNextFile) { // Database must be stable and we need to be in some sort of an update operation in order // to add a new file. invariant(txn->lockState()->isDbLockedForMode(_dbname, MODE_IX)); const int allocFileId = _files.size(); int minSize = 0; if (allocFileId > 0) { // Make the next file at least as large as the previous minSize = _files[allocFileId - 1]->getHeader()->fileLength; } if (minSize < sizeNeeded + DataFileHeader::HeaderSize) { minSize = sizeNeeded + DataFileHeader::HeaderSize; } { unique_ptr<DataFile> allocFile(new DataFile(allocFileId)); const string allocFileName = _fileName(allocFileId).string(); Timer t; allocFile->open(txn, allocFileName.c_str(), minSize, false); if (t.seconds() > 1) { log() << "MmapV1ExtentManager took " << t.seconds() << " seconds to open: " << allocFileName; } // It's all good _files.push_back(allocFile.release()); } // Preallocate is asynchronous if (preallocateNextFile) { unique_ptr<DataFile> nextFile(new DataFile(allocFileId + 1)); const string nextFileName = _fileName(allocFileId + 1).string(); nextFile->open(txn, nextFileName.c_str(), minSize, false); } // Returns the last file added return _files[allocFileId]; }
bool StressTest::GoToNextFile() { for (;;) { AutoFreeW nextFile(fileProvider->NextFile()); if (nextFile) { if (!IsInRange(fileRanges, ++fileIndex)) continue; if (OpenFile(nextFile)) return true; continue; } if (--cycles <= 0) return false; fileProvider->Restart(); } }
void ViStatistician::run(QString folder) { if(folder == "") { QDir dir("/home/visore/Visore Projects/Files/"); QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); for(int i = 0; i < dirs.size(); ++i) addDir(dirs[i]); } else { addDir(folder); } nextFile(); }
void ViNoiseBatcher::benchmark(QString folder) { if(folder == "") { QDir dir("/home/visore/Visore Projects/Files/"); QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); for(int i = 0; i < dirs.size(); ++i) addDir(dirs[i]); } else { addDir(folder); } mTotalFiles = mFiles.size(); nextFile(); }
nsFileResult::nsFileResult(const nsAString& aSearchString, const nsAString& aSearchParam): mSearchString(aSearchString) { if (aSearchString.IsEmpty()) mSearchResult = RESULT_IGNORED; else { int32_t slashPos = mSearchString.RFindChar('/'); mSearchResult = RESULT_FAILURE; nsCOMPtr<nsIFile> directory; nsDependentSubstring parent(Substring(mSearchString, 0, slashPos + 1)); if (!parent.IsEmpty() && parent.First() == '/') NS_NewLocalFile(parent, true, getter_AddRefs(directory)); if (!directory) { if (NS_FAILED(NS_NewLocalFile(aSearchParam, true, getter_AddRefs(directory)))) return; if (slashPos > 0) directory->AppendRelativePath(Substring(mSearchString, 0, slashPos)); } nsCOMPtr<nsISimpleEnumerator> dirEntries; if (NS_FAILED(directory->GetDirectoryEntries(getter_AddRefs(dirEntries)))) return; mSearchResult = RESULT_NOMATCH; bool hasMore = false; nsDependentSubstring prefix(Substring(mSearchString, slashPos + 1)); while (NS_SUCCEEDED(dirEntries->HasMoreElements(&hasMore)) && hasMore) { nsCOMPtr<nsISupports> nextItem; dirEntries->GetNext(getter_AddRefs(nextItem)); nsCOMPtr<nsIFile> nextFile(do_QueryInterface(nextItem)); nsAutoString fileName; nextFile->GetLeafName(fileName); if (StringBeginsWith(fileName, prefix)) { fileName.Insert(parent, 0); if (mSearchResult == RESULT_NOMATCH && fileName.Equals(mSearchString)) mSearchResult = RESULT_IGNORED; else mSearchResult = RESULT_SUCCESS; bool isDirectory = false; nextFile->IsDirectory(&isDirectory); if (isDirectory) fileName.Append('/'); mValues.AppendElement(fileName); } } mValues.Sort(); } }
bool getNextSong() { int fType = UNKNOWN; int tmpCur = getCursor(); while(fType != SOUNDFILE) { tmpCur = nextFile(getFileName(), getBrowserEntries()); if(tmpCur == -1) return false; fType = getFileType(getFileName()); } moveCursorAbsolute(tmpCur); return true; }
void DirSeeker::firstFile(const char *mask, reg_t buffer) { // Verify that we are given a valid buffer if (!buffer.segment) { error("DirSeeker::firstFile('%s') invoked with invalid buffer", mask); _vm->r_acc = NULL_REG; return; } _outbuffer = buffer; // Obtain a list of all savefiles matching the given mask // TODO: Modify the mask, e.g. by prefixing "TARGET-". Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); _savefiles = saveFileMan->listSavefiles(mask); // Reset the list iterator and write the first match to the output buffer, if any. _iter = _savefiles.begin(); nextFile(); }
void ViBenchMarker3::benchmark() { QDir dir("/home/visore/Visore Projects/Files/"); QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); for(int i = 0; i < dirs.size(); ++i) { QDir dir3("/home/visore/Visore Projects/Results/"+dirs[i]); if(!dir3.exists()) dir3.mkpath(dir3.absolutePath()); QDir dir2(dir.absoluteFilePath(dirs[i])); QStringList files2 = dir2.entryList(QDir::Files); for(int j = 0; j < files2.size(); ++j) { mFiles.enqueue(dir2.absoluteFilePath(files2[j])); mResults.enqueue(dir3.absoluteFilePath(files2[j])+".txt"); } } mTotalFiles = mFiles.size(); nextFile(); }
void ModuleDownloader::downloadNext() { emit nextFile(m_counter, m_fileCount);//show progress if(m_fileCount == 0) { //oh uhm: nothing to download emit downloaded(m_retData);//finish return; } if(m_counter < m_fileCount) { //download next download(m_urls.at(m_counter));//real download m_counter++; } else { //finished all myDebug() << "finished!!!"; emit downloaded(m_retData);//finish } }
void KoOdfCollectionLoader::loadShape() { //kDebug() << m_shape.tagName(); KoShape * shape = KoShapeRegistry::instance()->createShapeFromOdf(m_shape, *m_shapeLoadingContext); if (shape) { if(!shape->parent()) { m_shapeList.append(shape); } } m_shape = m_shape.nextSibling().toElement(); if(m_shape.isNull()) { m_page = m_page.nextSibling().toElement(); if(m_page.isNull()) { m_loadingTimer->stop(); if(m_fileList.isEmpty()) { emit loadingFinished(); } else { nextFile(); } } else { m_shape = m_page.firstChild().toElement(); } } }
int QPlayer::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: on_MuButton_clicked(); break; case 1: on_RemoveButton_clicked(); break; case 2: on_pushButton_clicked(); break; case 3: on_StyleButton_clicked(); break; case 4: on_PrevButton_clicked(); break; case 5: on_NextButton_clicked(); break; case 6: on_PauseButton_clicked(); break; case 7: on_StopButton_clicked(); break; case 8: on_PlayButton_clicked(); break; case 9: on_AddButton_clicked(); break; case 10: addFiles(); break; case 11: nextFile(); break; case 12: prevFile(); break; case 13: aboutToFinish(); break; case 14: finished(); break; case 15: tick((*reinterpret_cast< qint64(*)>(_a[1]))); break; case 16: rndFile(); break; case 17: stateChanged((*reinterpret_cast< Phonon::State(*)>(_a[1])),(*reinterpret_cast< Phonon::State(*)>(_a[2]))); break; case 18: metaStateChanged((*reinterpret_cast< Phonon::State(*)>(_a[1])),(*reinterpret_cast< Phonon::State(*)>(_a[2]))); break; case 19: sourceChanged((*reinterpret_cast< const Phonon::MediaSource(*)>(_a[1]))); break; case 20: tableClicked((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 21: setupActions(); break; case 22: removeFiles(); break; default: ; } _id -= 23; } return _id; }
static void PlayerCtrlTask(void *pvParameters){ //portTickType ulLastTime; //char itemCount = 0; unsigned char soundCtrl = 0; //Start Player Ctrl usStopPlayerCtrl = 0; //List files in root ListFiles(); sFilePath=getCurrentFile(); //DisplayMenu(0x03); // // Loop forever. // vTaskSuspendScheduler(); ShowStartup(); xTaskResumeScheduler(); xTaskDelay(5000); while(1){ //get event from button if( xQueueReceive(xPlayerCtrlQueue, (unsigned char*)&usEventCode,100)==pdPASS) { //Events from USB if(usEventCode == STOP_PLAYER) { PlayState=PAUSE_STATE; usStopPlayerCtrl = 1;//*Stop Player Ctrl soundCtrl = STOP;//*Stop Sound Player giveSoundCtrlEvent((unsigned char*)&soundCtrl,portMAX_DELAY); } else if (usEventCode == START_PLAYER) { usStopPlayerCtrl = 0;//*Start Player Ctrl Root = MENU; ChooseItem = NOWPLAY; DisplayMenu(0x03); } //USB not pluged in if(usStopPlayerCtrl == 0) { //Play sound Button when button pressed if(usEventCode < 10 && SoundButton) { soundCtrl = PLAY_BTN_SND; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); } //Events from Sound Player if(usEventCode==PLAY_DONE) { /**Play Mode: Normal*/ //TODO Play next song if(PlayMode == 0){//normal sFilePath = nextFile(); if(ucFileIndex!=0) { soundCtrl = START; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100);; } }else if(PlayMode == 1)//Single { ; }else if(PlayMode ==2)//repeate { soundCtrl = START; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100);; }else if(PlayMode==3)//loop { sFilePath = nextFile(); soundCtrl = START; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100);; } // if(ChooseItem == NOWPLAY) { NowPlay(STATE_UPDATE); NowPlay(SELECTED_UPDATE); } } //Events form user buttons if(Root == ITEM) { if(ChooseItem == NOWPLAY){ if(usEventCode == L_CENTER) { Root = MENU;//*back ROOT DisplayMenu(0x03); }else if(usEventCode == S_CENTER) { soundCtrl=PAUSE_PLAY; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); NowPlay(STATE_UPDATE); }else if(usEventCode == S_RIGHT) { soundCtrl = VLM_UP; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); NowPlay(VOLUME_UPDATE); } else if(usEventCode == S_LEFT) { soundCtrl = VLM_DOWN; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); NowPlay(VOLUME_UPDATE); } else if(usEventCode == S_UP) { //Play next song sFilePath = preFile(); NowPlay(SELECTED_UPDATE); soundCtrl = START; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); } else if(usEventCode == S_DOWN) { //Play previous song sFilePath = nextFile(); NowPlay(SELECTED_UPDATE); soundCtrl = START; giveSoundCtrlEvent((unsigned char*)&soundCtrl,100); } } else if(ChooseItem == BROWSE) { if(usEventCode == L_CENTER) { //back ROOT/parent's Dir vTaskSuspendScheduler(); if(BackParentDir()) { Root = MENU; DisplayMenu(0x03); } else Browse(BROWSE_UPDATE); xTaskResumeScheduler(); } else if(usEventCode == S_CENTER) { //open dir if it's dir, else file and play; vTaskSuspendScheduler(); ListFiles(); xTaskResumeScheduler(); ChooseItem = NOWPLAY; NowPlay(0x1f); } else if(usEventCode == S_UP){ PreItem(); Browse(BROWSE_UPDATE); }else if(usEventCode == S_DOWN){ NextItem(); Browse(BROWSE_UPDATE); }else if(usEventCode == L_DOWN || usEventCode == L_UP){ vTaskSuspendScheduler(); OpenChooseDir(); xTaskResumeScheduler(); Browse(BROWSE_UPDATE); } }else if(ChooseItem == SETTINGS){ if(usEventCode == L_CENTER){ Root = MENU;//*back MENU DisplayMenu(0x03); }else if(usEventCode == S_CENTER) { if(Selected == PLAY_MODE) { PlayMode++; if(PlayMode >3) PlayMode =0; }else if(Selected == BUTTON_SOUND) { SoundButton++; if(SoundButton>1) SoundButton =0; } Settings(SETTING_MODE); } else if(usEventCode == S_UP) { Selected++; if(Selected > 1) Selected=0; Settings(SETTING_MODE); }else if(usEventCode == S_DOWN) { Selected--; if(Selected > 1) Selected=1; Settings(SETTING_MODE); } }else if(ChooseItem == INFO){ if(usEventCode == L_CENTER){ Root = MENU;//*back MENU DisplayMenu(0x03); } } } else if(Root == MENU){ if(usEventCode == S_CENTER){ Root = ITEM;//enter choose item; if(ChooseItem==NOWPLAY) { NowPlay(0x1f); } else if(ChooseItem==BROWSE) { vTaskSuspendScheduler(); ListDirItems(); xTaskResumeScheduler(); Browse(0x3); } else if(ChooseItem==SETTINGS) { Settings(0x03); } else if(ChooseItem==INFO) { Info(0x03); } }else if(usEventCode == S_UP){ ChooseItem--;//previous item if(ChooseItem > INFO) ChooseItem = INFO; DisplayMenu(MENU_SELECT_UPDATE); }else if(usEventCode == S_DOWN){ ChooseItem++;//next item if(ChooseItem > INFO) ChooseItem = NOWPLAY; DisplayMenu(MENU_SELECT_UPDATE); } } }else{ //USB mass storage USBTransfer(); } } if(Root == ITEM) { if(ChooseItem == NOWPLAY){ //Update time playing if(clock) { NowPlay(TIME_UPDATE); clock=0; } } } } }
void ViStatistician::process() { QObject::disconnect(mCurrentObject.data(), SIGNAL(decoded()), this, SLOT(process())); ViAudioReadData data(mCurrentObject->buffer(ViAudio::Target)); data.setSampleCount(mWindowSize); qreal value = 0; qint64 count = 0; qreal top = 0, bottom1 = 0, bottom2 = 0; qreal valuePos = 0, valueNeg = 0; int countPos = 0, countNeg = 0; while(data.hasData()) { data.read(); ViSampleChunk &samples1 = data.splitSamples(0); ViSampleChunk &samples2 = data.splitSamples(1); if(mMode == Mean) { value += mean(samples1); value += mean(samples2); count += 2; } else if(mMode == StandardDeviation) { value += standardDeviation(samples1); value +standardDeviation(samples2); count += 2; } else if(mMode == Pearson) { qreal theTopA = 0, theBottom1A = 0, theBottom2A = 0; qreal theTopB = 0, theBottom1B = 0, theBottom2B = 0; qreal value1 = pearson(samples1, theTopA, theBottom1A, theBottom2A); qreal value2 = pearson(samples2, theTopB, theBottom1B, theBottom2B); /*if(value1 != 0) { top += theTopA; bottom1 += theBottom1A; bottom2 += theBottom2A; } if(value2 != 0) { top += theTopB; bottom1 += theBottom1B; bottom2 += theBottom2B; }*/ if(value1 > 0) { valuePos += value1; ++countPos; } else if(value1 < 0) { valueNeg += value1; ++countNeg; } if(value2 > 0) { valuePos += value2; ++countPos; } else if(value2 < 0) { valueNeg += value2; ++countNeg; } } } if(mMode == Pearson) { /*value = top / (qSqrt(bottom1) * qSqrt(bottom2)); mValue += value; mCount += 1; printFileData(value); printTerminal(value);*/ mValuePos += valuePos; mCountPos += countPos; mValueNeg += valueNeg; mCountNeg += countNeg; valuePos /= countPos; valueNeg /= countNeg; printFileDataPearson(valuePos, valueNeg); printTerminalPearson(valuePos, valueNeg); } else { mValue += value; mCount += count; value /= count; printFileData(value); printTerminal(value); } nextFile(); }
/* This creates a header by determining the hostname and reading the corresponding information out of the READOUT.conf file. */ _BOS_RCTR::_BOS_RCTR(u_int runNumber,u_int runExtNumber) : _BOS(*(u_int *)"RCTR",rctrRevNbr,0) { rctr = new RCTR_HEADER; rctr->streamNumber=0; rctr->numberOfModules=0; nextFile(runNumber,runExtNumber); // read number of streams GetDefaultUnsigned(rctr->totalNumberOfStreams,configFile,"numberOfStreams"); rctr->totalNumberOfChassis=rctr->totalNumberOfStreams; if (rctr->totalNumberOfChassis>MAXNumberOfStreams) { cout << "Too much streams !" << endl; return; } // determine hostname char chostname[100]; gethostname(chostname,100); char* point=strchr(chostname,'.'); // remove domain name if (point) *point=0; string thisHost = chostname; // read config data & try to determine streamNumber Config_V myConf[MAXNumberOfStreams]; // run configuration: detektor id, card, channel and settings for(unsigned int i = 0;i<rctr->totalNumberOfStreams;i++) { char streamHostStr[10]; sprintf(streamHostStr,"host%d",i+1); // string streamHostStr = form("host%d",i+1); string streamHost; GetDefaultString(streamHost,configFile,streamHostStr); myConf[i] = GetConfigVal(configFile,streamHost+":"); if (streamHost==thisHost) { if (myConf[i].size()>0) rctr->streamNumber=myConf[i][0].getStream(); else cout << "There is no configuration for this stream !" << endl; } } // determine # of modules (total) and # of ch per mod for (u_int s=0;s<rctr->totalNumberOfStreams;s++) { bool found; int curModules=0; // numberOfModules in stream s // look for the existence of modules with number 0..16 for (u_int module=0;module<=16;module++) { // module number to check for int curChNumber=0; // number of of channels in the current module found=false; // if module 'module' was found in the current stream for (u_int i=0;i<myConf[s].size();i++) { // look for the module in all channels of current stream if (myConf[s][i].getModule()==module) { curChNumber++; found=true; } // if myConf } // for i if (found) { numberOfChannels.push_back(curChNumber); curModules++; } }; if (s+1==rctr->streamNumber) rctr->numberOfModules=curModules; // in this file } // for s rctr->totalNumberOfModules=numberOfChannels.size(); //total in run rctr->numberOfChannels=(rctr->streamNumber>0) ? myConf[rctr->streamNumber-1].size() : 0; rctr->experiment = NTOF_as_int; bos->length=sizeof(RCTR_HEADER)/sizeof(int)+rctr->totalNumberOfModules; }
void line_spliter(int digitSplit, int specialMarkSplit, int fileSplit, int file, char specialMark, int outputs, char filesnames[][10]){ int files[5]; int i; int file1; int file2; int file3; int file4; int file5; for(i=0; i<outputs;i++){ switch (i){ case 0: /*file1=fopen(filesnames[0], "w+");*/ file1=system_call(5, filesnames[0],2|64, 0644); files[0]=file1; break; case 1: /*file2=fopen(filesnames[1], "w+");*/ file2=system_call(5, filesnames[1],2|64, 0644); files[1]=file2; break; case 2: /*file3=fopen(filesnames[2], "w+");*/ file3=system_call(OPEN, filesnames[2],2|64, 0644); files[2]=file3; break; case 3: /*file4=fopen(filesnames[3], "w+");*/ file4=system_call(OPEN, filesnames[3],2|64, 0644); files[3]=file4; break; case 4: /*file5=fopen(filesnames[4], "w+");*/ file5=system_call(OPEN, filesnames[4],2|64, 0644); files[4]=file5; break; } } char c; int isFirst=1; int line=1; char tempLine='0'; if(fileSplit){ system_call(SYS_READ,file,&c,1); } else system_call(SYS_READ,STDIN,&c,1); int currentFile; int fileNum=0; if(outputs){ currentFile=file1; } while(c>0){ switch(c){ case '@': if(isFirst){ if(outputs){ system_call(SYS_WRITE,currentFile,"1:",2); /*fprintf(currentFile,"1:" );*/ } else /*printf("1:");*/ system_call(SYS_WRITE,STDOUT,"1:",2); } if(outputs){ system_call(SYS_WRITE,currentFile,"@",1); /*fprintf(currentFile,"@" );*/ } else /*printf("@");*/ system_call(SYS_WRITE,STDOUT,"@",1); line++; tempLine=line+'0'; if(outputs){ system_call(SYS_WRITE,currentFile,"\n",1); /*fprintf(currentFile, "\n");*/ fileNum=nextFile(fileNum,outputs); currentFile=files[fileNum]; system_call(SYS_WRITE,currentFile,&tempLine,1); system_call(SYS_WRITE,currentFile,":",1); /*fprintf(currentFile, "%d:", line);*/ } else {/*printf("\n%d:", line);*/ system_call(SYS_WRITE,STDOUT,"\n",1); system_call(SYS_WRITE,STDOUT,&tempLine,1); system_call(SYS_WRITE,STDOUT,":",1); } isFirst=0; break; case '*': if(isFirst){ if(outputs){ system_call(SYS_WRITE,currentFile,"1:",2); /*fprintf(currentFile,"1:" );*/ } else /*printf("1:");*/ system_call(SYS_WRITE,STDOUT,"1:",2); } if(outputs){ system_call(SYS_WRITE,currentFile,"*",1); /*fprintf(currentFile,"*" );*/ } else /*printf("*");*/ system_call(SYS_WRITE,STDOUT,"*",1); line++; tempLine=line+'0'; if(outputs){ system_call(SYS_WRITE,currentFile,"\n",1); /*fprintf(currentFile, "\n");*/ fileNum=nextFile(fileNum,outputs); currentFile=files[fileNum]; system_call(SYS_WRITE,currentFile,&tempLine,1); system_call(SYS_WRITE,currentFile,":",1); /*fprintf(currentFile, "%d:", line);*/ } else {/*printf("\n%d:", line);*/ system_call(SYS_WRITE,STDOUT,"\n",1); system_call(SYS_WRITE,STDOUT,&tempLine,1); system_call(SYS_WRITE,STDOUT,":",1); } isFirst=0; break; default: if(isFirst){ if(outputs){ system_call(SYS_WRITE,currentFile,"1:",2); /*fprintf(currentFile,"1:" );*/ } else /*printf("1:");*/ system_call(SYS_WRITE,STDOUT,"1:",2); } if(digitSplit && c<57 && c>48){ if(outputs){ system_call(SYS_WRITE,currentFile,&c,1); /*fprintf(currentFile,"%c", c );*/ } else /*printf("%c", c);*/ system_call(SYS_WRITE,STDOUT,&c,1); line++; tempLine=line+'0'; if(outputs){ system_call(SYS_WRITE,currentFile,"\n",1); /*fprintf(currentFile, "\n");*/ fileNum=nextFile(fileNum,outputs); currentFile=files[fileNum]; system_call(SYS_WRITE,currentFile,&tempLine,1); system_call(SYS_WRITE,currentFile,":",1); /*fprintf(currentFile, "%d:", line);*/ } else {/*printf("\n%d:", line);*/ system_call(SYS_WRITE,STDOUT,"\n",1); system_call(SYS_WRITE,STDOUT,&tempLine,1); system_call(SYS_WRITE,STDOUT,":",1); } isFirst=0; } else if( specialMarkSplit && c==specialMark){ if(outputs){ /*fprintf(currentFile,"%c",specialMark );*/ system_call(SYS_WRITE,currentFile,&specialMark,1); } else /*printf("%c",specialMark);*/ system_call(SYS_WRITE,STDOUT,&specialMark,1); line++; tempLine=line+'0'; if(outputs){ system_call(SYS_WRITE,currentFile,"\n",1); /*fprintf(currentFile, "\n");*/ fileNum=nextFile(fileNum,outputs); currentFile=files[fileNum]; system_call(SYS_WRITE,currentFile,&tempLine,1); system_call(SYS_WRITE,currentFile,":",1); /*fprintf(currentFile, "%d:", line);*/ } else {/*printf("\n%d:", line);*/ system_call(SYS_WRITE,STDOUT,"\n",1); system_call(SYS_WRITE,STDOUT,&tempLine,1); system_call(SYS_WRITE,STDOUT,":",1); } isFirst=0; } else { if(outputs){ system_call(SYS_WRITE,currentFile,&c,1); /*fprintf(currentFile,"%c", c );*/ } else {/*printf("%c", c); printf("fvdfbv");*/ system_call(SYS_WRITE,STDOUT,&c,1);} isFirst=0; } break; } if(fileSplit){ system_call(SYS_READ,file,&c,1); } else system_call(SYS_READ,STDIN,&c,1); if(c=='\n'|| c==' ') break; } int k; for(k=0;k<outputs;k++){ /*close(files[k]);*/ system_call(CLOSE,files[k]); } }
InFile *HPJReader::firstFile() { _curFile = _topFile; return nextFile(); }
void ViBenchMarker3::process2() { int time = mTime.elapsed(); QObject::disconnect(mCurrentObject.data(), SIGNAL(noiseGenerated()), this, SLOT(process2())); /*QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit())); mCurrentObject->encode(ViAudio::Noise); return;*/ qreal maxMAT = 0; qint64 maxTP = 0, maxTN = 0, maxFP = 0, maxFN = 0; qint64 i, lengthIndex, offset1 = 0, offset2 = 0; int noChange = 0; ViAudioReadData corrupted(mCurrentObject->buffer(ViAudio::Noise)); ViAudioReadData realMask(mCurrentObject->buffer(ViAudio::CustomMask)); ViAudioReadData length(mCurrentObject->buffer(ViAudio::Custom)); corrupted.setSampleCount(WINDOW_SIZE); realMask.setSampleCount(WINDOW_SIZE); length.setSampleCount(WINDOW_SIZE); ViSampleChunk *nData1 = new ViSampleChunk(corrupted.bufferSamples() / 2); ViSampleChunk *nData2 = new ViSampleChunk(corrupted.bufferSamples() / 2); ViSampleChunk *nMask1 = new ViSampleChunk(corrupted.bufferSamples() / 2); ViSampleChunk *nMask2 = new ViSampleChunk(corrupted.bufferSamples() / 2); ViSampleChunk *nRealMask1 = new ViSampleChunk(realMask.bufferSamples() / 2); ViSampleChunk *nRealMask2 = new ViSampleChunk(realMask.bufferSamples() / 2); ViSampleChunk *nLength1 = new ViSampleChunk(corrupted.bufferSamples() / 2); ViSampleChunk *nLength2 = new ViSampleChunk(corrupted.bufferSamples() / 2); while(corrupted.hasData() && realMask.hasData()) { corrupted.read(); ViSampleChunk &corrupted1 = corrupted.splitSamples(0); ViSampleChunk &corrupted2 = corrupted.splitSamples(1); realMask.read(); ViSampleChunk &realMask1 = realMask.splitSamples(0); ViSampleChunk &realMask2 = realMask.splitSamples(1); length.read(); ViSampleChunk &length1 = length.splitSamples(0); ViSampleChunk &length2 = length.splitSamples(1); for(i = 0; i < corrupted1.size(); ++i) { (*nData1)[i + offset1] = corrupted1[i]; (*nRealMask1)[i + offset1] = realMask1[i]; (*nLength1)[i + offset1] = length1[i]; } offset1 += corrupted1.size(); for(i = 0; i < corrupted2.size(); ++i) { (*nData2)[i + offset2] = corrupted2[i]; (*nRealMask2)[i + offset2] = realMask2[i]; (*nLength2)[i + offset2] = length2[i]; } offset2 += corrupted2.size(); } mCurrentObject->clearBuffer(ViAudio::Target); mCurrentObject->clearBuffer(ViAudio::Noise); mCurrentObject->clearBuffer(ViAudio::NoiseMask); ViNoise noise1(nData1, nMask1, mCurrentThreshold); ViNoise noise2(nData2, nMask2, mCurrentThreshold); QVector<qreal> lengthTP(ViNoiseCreator::noiseSizeCount()); QVector<qreal> lengthFN(ViNoiseCreator::noiseSizeCount()); lengthTP.fill(0); lengthFN.fill(0); QVector<qreal> maxLengthTP, maxLengthFN; for(mCurrentThreshold = MASK_START; mCurrentThreshold <= MASK_END; mCurrentThreshold += MASK_INTERVAL) { noise1.setThreshold(mCurrentThreshold); noise1.generateMask(ViNoise::NOISE_TYPE); noise2.setThreshold(mCurrentThreshold); noise2.generateMask(ViNoise::NOISE_TYPE); qint64 truePositives = 0, falsePositives = 0, trueNegatives = 0, falseNegatives = 0; for(i = 0; i < nRealMask1->size(); ++i) { if((*nRealMask1)[i] == 1) { lengthIndex = ViNoiseCreator::fromSizeMask((*nLength1)[i]) - 1; if((*nMask1)[i] == 1) { ++truePositives; lengthTP[lengthIndex] += 1; } else { ++falseNegatives; lengthFN[lengthIndex] += 1; } } else if((*nRealMask1)[i] == 0) { if((*nMask1)[i] == 1) ++falsePositives; else ++trueNegatives; } } for(i = 0; i < nRealMask2->size(); ++i) { if((*nRealMask2)[i] == 1) { lengthIndex = ViNoiseCreator::fromSizeMask((*nLength2)[i]) - 1; if((*nMask2)[i] == 1) { ++truePositives; lengthTP[lengthIndex] += 1; } else { ++falseNegatives; lengthFN[lengthIndex] += 1; } } else if((*nRealMask2)[i] == 0) { if((*nMask2)[i] == 1) ++falsePositives; else ++trueNegatives; } } qreal math = matthews(truePositives, trueNegatives, falsePositives, falseNegatives); if(math > maxMAT) { maxMAT = math; maxTP = truePositives; maxTN = trueNegatives; maxFP = falsePositives; maxFN = falseNegatives; maxLengthTP = lengthTP; maxLengthFN = lengthFN; noChange = 0; } ++noChange; if(noChange > NO_CHANGE) break; } delete nRealMask1; delete nRealMask2; delete nLength1; delete nLength2; ++mDoneParamIterations; if(maxMAT > mBestMatthews) mBestMatthews = maxMAT; printFileData(time, maxTP, maxTN, maxFP, maxFN, maxLengthTP, maxLengthFN); printTerminal(time, maxTP, maxTN, maxFP, maxFN, mBestMatthews); if(nextParam()) process1(false); else nextFile(); }
bool TarImpl::removeFiles( const QStringList& _files ) { if ( !ensureInMode( ArchiveImpl::Remove ) ) { qDebug( "Couldn't change mode for removeFile" ); return false; } Q_ASSERT( m_mode == ArchiveImpl::Remove ); // need to cut out the sections which apply to // files which need are to be removed. no // api on QIODevice to do this, so read into a // QByteArray, modify it, and write it back. QIODeviceCloser ioDevice( m_ioDevice, QIODevice::ReadOnly, m_ioDevice->openMode() ); // first gather the positions and sizes of any files to be removed std::vector< std::pair<int,int> > removals; if ( !firstFile() ) { // The archive is empty return false; } unsigned int toremove(0); QStringList files( _files ); while( true ) { const int index = files.indexOf( m_dev->fileName() ); if ( index != -1 ) { const tar::TarHeader& curInfo = tarDevice()->headerInfo(); // start position const int pos = curInfo.pos(); // size of entry (header+data+block padding) const int size = curInfo.totalSize(); removals.push_back( std::pair< int, int >(pos, size ) ); toremove += size; files.removeAt( index ); } // stop if there's nothing left to find if ( files.isEmpty() ) { break; } // Move on to the next file if ( !nextFile() ) { // We're out of files break; } } if ( removals.empty() ) { qWarning( "No matching files were found to be removed" ); return false; } ioDevice->reset(); QByteArray data = ioDevice->readAll(); ioDevice->close(); // \todo better to copy the files we want to keep into a new QByteArray or // cut out the files we don't want? could compare size of archive with amount to be // removed // track how much has been removed as this modifies the start pos for // each removal block unsigned int removed(0); std::vector< std::pair<int,int> >:: const_iterator I = removals.begin(); std::vector< std::pair<int,int> >:: const_iterator E = removals.end(); for ( ; I!=E; ++I ) { data.remove( I->first - removed, I->second ); removed += I->second; } Q_ASSERT( toremove == removed ); ioDevice->open( QIODevice::WriteOnly | QIODevice::Truncate ); ioDevice->write( data ); return true; }
/* * fstream_read * * Read 'size' bytes of data from the filestream into 'buffer'. * If 'read_whole_lines' is specified then read up to the last logical row * in the source buffer. 'fo' keeps the state (name, offset, etc) of the current * filestream file we are reading from. */ int fstream_read(fstream_t *fs, void *dest, int size, struct fstream_filename_and_offset *fo, const int read_whole_lines, const char *line_delim_str, const int line_delim_length) { int buffer_capacity = fs->options.bufsize; static char err_buf[FILE_ERROR_SZ] = {0}; if (fs->ferror) return -1; for (;;) { ssize_t bytesread; /* num bytes read from filestream */ ssize_t bytesread2; /* same, but when reading a second round */ if (!size || fs->fidx == fs->glob.gl_pathc) return 0; /* * If data source has a header, we consume it now and in order to * move on to real data that follows it. */ if (fs->skip_header_line) { char* p = fs->buffer; char* q = p + fs->buffer_cur_size; size_t len = 0; assert(fs->buffer_cur_size < buffer_capacity); /* * read data from the source file and fill up the file stream buffer */ len = buffer_capacity - fs->buffer_cur_size; bytesread = gfile_read(&fs->fd, q, len); if (bytesread < 0) { fs->ferror = format_error("cannot read file - ", fs->glob.gl_pathv[fs->fidx]); return -1; } /* update the buffer size according to new byte count we just read */ fs->buffer_cur_size += bytesread; q += bytesread; if (fs->options.is_csv) { /* csv header */ p = scan_csv_records(p, q, 1, fs); } else { if (line_delim_length > 0) { /* text header with defined EOL */ p = find_first_eol_delim (p, q, line_delim_str, line_delim_length); } else { /* text header with \n as delimiter (by default) */ for (; p < q && *p != '\n'; p++) ; } p = (p < q) ? p + 1 : 0; fs->line_number++; } if (!p) { if (fs->buffer_cur_size == buffer_capacity) { gfile_printf_then_putc_newline( "fstream ERROR: header too long in file %s", fs->glob.gl_pathv[fs->fidx]); fs->ferror = "line too long in file"; return -1; } p = q; } /* * update the filestream buffer offset to past last line read and * copy the end of the buffer (past header data) to the beginning. * we now bypassed the header data and can continue to real data. */ fs->foff += p - fs->buffer; fs->buffer_cur_size = q - p; memmove(fs->buffer, p, fs->buffer_cur_size); fs->skip_header_line = 0; } /* * If we need to read all the data up to the last *complete* logical * line in the data buffer (like gpfdist for example) - we choose this * path. We grab the bigger chunk we can get that includes whole lines. * Otherwise, if we just want the whole buffer we skip. */ if (read_whole_lines) { char *p; ssize_t total_bytes = fs->buffer_cur_size; assert(size >= buffer_capacity); if (total_bytes > 0) { /* * source buffer is not empty. copy the data from the beginning * up to the current length before moving on to reading more */ fs->buffer_cur_size = 0; updateCurFileState(fs, fo); memcpy(dest, fs->buffer, total_bytes); } /* read more data from source file into destination buffer */ bytesread2 = gfile_read(&fs->fd, (char*) dest + total_bytes, size - total_bytes); if (bytesread2 < 0) { fs->ferror = format_error("cannot read file - ", fs->glob.gl_pathv[fs->fidx]); return -1; } if (bytesread2 < size - total_bytes) { /* * We didn't read as much as we asked for. Check why. * We could be done reading data, we may need to move * on the reading the next data file (if any). */ if (total_bytes == 0) { if (bytesread2 == 0) { if (nextFile(fs)) return -1; /* found next file but failed to open */ continue; } updateCurFileState(fs, fo); } /* * try to open the next file if any, and return the number of * bytes read to buffer earlier, if next file was found but * could not open return -1 */ return nextFile(fs) ? -1 : total_bytes + bytesread2; } updateCurFileState(fs, fo); /* * Now that we have enough data in our filestream buffer, get a * chunk of whole rows and copy it into our dest buffer to be sent * out later. */ if (fs->options.is_csv) { /* CSV: go slow, scan byte-by-byte for record boundary */ p = scan_csv_records(dest, (char*)dest + size, 0, fs); } else { /* * TEXT: go fast, scan for end of line delimiter (\n by default) for * record boundary. * find the last end of line delimiter from the back */ if (line_delim_length > 0) { p = find_last_eol_delim((char*)dest, size, line_delim_str, line_delim_length); } else { for (p = (char*)dest + size; (char*)dest <= --p && *p != '\n';) ; } p = (char*)dest <= p ? p + 1 : 0; fs->line_number = 0; } /* * could we not find even one complete row in this buffer? error. */ if (!p || (char*)dest + size >= p + buffer_capacity) { snprintf(err_buf, sizeof(err_buf), "line too long in file %s near (%lld bytes)", fs->glob.gl_pathv[fs->fidx], (long long) fs->foff); fs->ferror = err_buf; gfile_printf_then_putc_newline("%s", err_buf); return -1; } /* copy the result chunk of data into our buffer and we're done */ fs->buffer_cur_size = (char*)dest + size - p; memcpy(fs->buffer, p, fs->buffer_cur_size); fs->foff += p - (char*)dest; return p - (char*)dest; } /* * if we're here it means that we just want chunks of data and don't * care if it includes whole rows or not (for example, backend url_read * code - a segdb that reads all the data that gpfdist sent to it, * buffer by buffer and then parses the lines internally). */ if (fs->buffer_cur_size) { ssize_t total_bytes = fs->buffer_cur_size; updateCurFileState(fs, fo); if (total_bytes > size) total_bytes = size; memcpy(dest, fs->buffer, total_bytes); fs->buffer_cur_size -= total_bytes; memmove(fs->buffer, fs->buffer + total_bytes, fs->buffer_cur_size); fs->foff += total_bytes; fs->line_number = 0; return total_bytes; } bytesread = gfile_read(&fs->fd, dest, size); if (bytesread < 0) { fs->ferror = format_error("cannot read file - ", fs->glob.gl_pathv[fs->fidx]); return -1; } if (bytesread) { updateCurFileState(fs, fo); fs->foff += bytesread; fs->line_number = 0; return bytesread; } if (nextFile(fs)) return -1; } }