/** * Create bootstrap samples for every set by calling the snp_data set. * Right now we are always using the same size. * */ void Bagging::preProcess(){ // int bag_num; /*engines.reserve(bag_param->get_number_of_bags()); ADTree *a; DataAccess *d; d = new DataAccess(); d->init(data->getDataObject()); a = 0; a = new ADTree(param_reader,d); if(bag_param->get_engine_type() == ParamReader::ADTREE){ for(int i=0; i < bag_param->get_number_of_bags(); i++){ engines.push_back(*a); } for(int i=0;i < bag_param->get_number_of_bags(); ++i){ engines.at(i).enslave(bag_param); } }else{ cerr << "You must use ADTREE reader." << endl; return; }*/ engines.reserve(bag_param->get_number_of_bags()); if(bag_param->get_engine_type() == ParamReader::ADTREE){ for(int i=0; i < bag_param->get_number_of_bags(); i++){ ADTree *a; DataAccess *d; d = new DataAccess(); d->init(data->getDataObject()); a = new ADTree(d); engines.push_back(*a); } for(int i=0;i < bag_param->get_number_of_bags(); ++i){ engines.at(i).enslave(bag_param); } }else{ cerr << "You must use ADTREE reader." << endl; return; } }
int main() { DataAccess * da = new DataAccess(); IUser * user = da->CreateUser(); IDepartment * department = da->CreateDepartment(); user->Insert(); user->GetUser(); department->Insert(); department->GetDepartment(); return 0; }
Resource* NewResourceAssistant::createResource() { if (m_resourceType == ResourceModel::CourseItem) { Course* course = new Course(); DataIndexCourse* templateDataIndexCourse = qobject_cast<DataIndexCourse*>(m_resourceTemplateWidget->templateResource()); if (templateDataIndexCourse) { Course templateCourse; DataAccess dataAccess; dataAccess.loadCourse(templateDataIndexCourse, &templateCourse); course->copyFrom(&templateCourse); for (int i = 0; i < course->lessonCount(); i++) { course->lesson(i)->setId(QUuid::createUuid().toString()); } } course->setId(QUuid::createUuid().toString()); course->setTitle(m_newCourseWidget->title()); course->setKeyboardLayoutName(m_newCourseWidget->keyboardLayoutName()); course->setDescription(m_newCourseWidget->description()); return course; } else if (m_resourceType == ResourceModel::KeyboardLayoutItem) { KeyboardLayout* keyboardLayout = new KeyboardLayout(); DataIndexKeyboardLayout* templateDataIndexKeyboardLayout = qobject_cast<DataIndexKeyboardLayout*>(m_resourceTemplateWidget->templateResource()); if (templateDataIndexKeyboardLayout) { KeyboardLayout templateKeyboardLayout; DataAccess dataAccess; dataAccess.loadKeyboardLayout(templateDataIndexKeyboardLayout, &templateKeyboardLayout); keyboardLayout->copyFrom(&templateKeyboardLayout); } keyboardLayout->setId(QUuid::createUuid().toString()); keyboardLayout->setName(m_newKeyboardLayoutWidget->name()); keyboardLayout->setTitle(m_newKeyboardLayoutWidget->title()); return keyboardLayout; } return 0; }
virtual InvalidateReply writeRemoteAction( const DataAccess& access ) { cache_iter_t cacheIter; bool noOtherCachesHaveLine = true; for ( cacheIter = allCaches->begin(); cacheIter != allCaches->end(); cacheIter++ ) { SMPCache<State, Addr_t> *otherCache = *cacheIter; if ( otherCache->CPUId == this->CPUId ) { continue; } State* otherLine = NULL; CacheResponse r = otherCache->L1cache->search( access.addr(), otherLine ); if ( r == MISSED_TO_MEMORY ) { // not found in this cache continue; } switch ( otherLine->getState() ) { case MESI_MODIFIED: case MESI_EXCLUSIVE: case MESI_SHARED: otherLine->invalidate(); noOtherCachesHaveLine = false; // have to keep searching to find all Shared copies break; case MESI_INVALID: // keep searching for more copies break; default: assert(false); } } // done with other caches return InvalidateReply( noOtherCachesHaveLine ); } // end writeRemoteAction()
virtual RemoteReadService readRemoteAction( const DataAccess& access ) { cache_iter_t cacheIter; for ( cacheIter = allCaches->begin(); cacheIter != allCaches->end(); cacheIter++ ) { SMPCache<State, Addr_t> *otherCache = *cacheIter; if ( otherCache->CPUId == this->CPUId ) { continue; } State* otherLine = NULL; CacheResponse r = otherCache->L1cache->search( access.addr(), otherLine ); if ( r == MISSED_TO_MEMORY ) { continue; // not found in this cache } // found in a remote cache! switch ( otherLine->getState() ) { case MESI_EXCLUSIVE: case MESI_MODIFIED: otherLine->changeStateTo( MESI_SHARED ); return RemoteReadService( false, true ); case MESI_SHARED: // everyone else will be in Shared state as well, so return now return RemoteReadService( true, false ); case MESI_INVALID: // keep searching for other copies break; default: assert(false); } } // done with other caches // this happens if everyone was MESI_INVALID return RemoteReadService( false, false ); } // end readRemoteAction()
void KeyboardLayoutEditor::openKeyboardLayout(DataIndexKeyboardLayout* dataIndexKeyboardLayout) { DataAccess dataAccess; m_dataIndexKeyboardLayout = dataIndexKeyboardLayout; if (currentUndoStack()) { currentUndoStack()->disconnect(this, SLOT(validateSelection())); } initUndoStack(QString("keyboard-layout-%1").arg(dataIndexKeyboardLayout->id())); m_propertiesWidget->setUndoStack(currentUndoStack()); setSelectedKey(0); connect(currentUndoStack(), SIGNAL(indexChanged(int)), SLOT(validateSelection())); m_keyboardLayout->setAssociatedDataIndexKeyboardLayout(m_dataIndexKeyboardLayout); if (!dataAccess.loadKeyboardLayout(dataIndexKeyboardLayout, m_keyboardLayout)) { KMessageBox::error(this, i18n("Error while opening keyboard layout")); } if (dataIndexKeyboardLayout->source() == DataIndex::BuiltInResource) { setReadOnly(true); m_messageWidget->setMessageType(KMessageWidget::Information); m_messageWidget->setText(i18n("Built-in keyboard layouts can only be viewed.")); m_messageWidget->setCloseButtonVisible(false); m_messageWidget->animatedShow(); } else { setReadOnly(false); m_messageWidget->animatedHide(); } }
int main(int argc, char *argv []) { // Configure logging module const char* routine = "sueplay::main"; Logger::setAppName("sueplay"); Logger::setLogLevel(INFO); Logger::setDisplayLevel(ERROR); Logger::initLogDir(); // Process command-line options processOptions(argc, argv); // Create daemon process if running detached if (detach) { detachProcess(); } string SQL_Item,SQL_Detail,SQL_Remove; PqxxResult R; L_INFO(LOG_SUEPLAY, " -> Reading configuration file"); Config *Conf = new Config("digiplay"); L_INFO(LOG_SUEPLAY, " -> Connecting to Database..."); DataAccess* DB = new DataAccess(); SQL_Item = "SELECT audioid FROM sustschedule ORDER BY id LIMIT 1"; SQL_Detail = "SELECT filetype, archives.localpath AS path, v_audio.md5 AS md5, v_audio.title AS title, v_audio.length_smpl AS length_smpl, sustschedule.id AS id, sustschedule.trim_start_smpl AS start, sustschedule.trim_end_smpl AS end, sustschedule.fade_in AS fade_in, sustschedule.fade_out AS fade_out, v_audio.artist FROM sustschedule, archives, v_audio WHERE sustschedule.audioid = v_audio.id AND archives.id = v_audio.archiveid"; L_INFO(LOG_SUEPLAY, "done."); // Create components Input* ch[] = {new InputFile(), new InputFile()}; ProcessFader* fader[] = {new ProcessFader(), new ProcessFader()}; CounterTrigger* trig[] = {new CounterTrigger(), new CounterTrigger()}; ProcessMixer* mixer = new ProcessMixer(); OutputDsp* player = new OutputDsp(Conf->getParam("channel_1").c_str()); ch[0]->setAutoReload(false); ch[1]->setAutoReload(false); ch[0]->patch(OUT0, fader[0], IN0); ch[1]->patch(OUT0, fader[1], IN0); fader[0]->patch(OUT0,mixer,IN0); fader[1]->patch(OUT0,mixer,IN1); mixer->patch(OUT0,player,IN0); string md5, id, path, title, artist, ext, nicetime; long start = 0, end = 0, fade_in = 0, fade_out = 0; long length_smpl = 0; unsigned short active = 0, inactive = 1; bool warn_flag = true; time_t curtime; // Process schedule table until empty while (true) { L_INFO(LOG_SUEPLAY, "Beginning loading next track"); // Keep trying until successfully loaded a file that exists! do { // Query database for next track to play L_INFO(LOG_SUEPLAY, "Retrieving next track from database."); R = DB->exec("SuePlay",SQL_Item); // If no results, then schedule must have been depleated! Doh! if (R.size() == 0) { // Only warn once, then disable the warning if (warn_flag) { warn_flag = false; L_WARNING(LOG_SUEPLAY, "Schedule is depleated!"); } // Let's not batter the psql server while we poll for new tracks to play sleep(1); continue; } // Reset warn flag so we are warned again when the schedule is // next depleted. warn_flag = true; id = R[0]["audioid"].c_str(); R = DB->exec("SuePlay",SQL_Detail + " AND v_audio.id=" + id); // Load the required data from database id = R[0]["id"].c_str(); path = R[0]["path"].c_str(); md5 = R[0]["md5"].c_str(); title = R[0]["title"].c_str(); artist = R[0]["artist"].c_str(); start = atoi(R[0]["start"].c_str()); end = atoi(R[0]["end"].c_str()); fade_in = atoi(R[0]["fade_in"].c_str()); fade_out = atoi(R[0]["fade_out"].c_str()); length_smpl = atoi(R[0]["length_smpl"].c_str()); path += "/" + md5.substr(0,1) + "/"; L_INFO(LOG_SUEPLAY, "Attempting to load channel " + dps_itoa(active) + ": " + artist + " - " + title); L_INFO(LOG_SUEPLAY, " -> Start: " + dps_itoa(start)); L_INFO(LOG_SUEPLAY, " -> End: " + dps_itoa(end)); // Try and load the track try { if (string(R[0]["filetype"].c_str()) == "raw") { ext = ""; } else if (string(R[0]["filetype"].c_str()) == "flac") { ext = ".flac"; } trig[inactive]->setTriggerTarget(ch[active]); ch[active]->addCounter(trig[active]); ch[active]->load( path + md5 + ext, start, end ); L_INFO(LOG_SUEPLAY, "Successfully loaded track."); break; } catch (...) { L_ERROR(LOG_SUEPLAY, "Error loading track"); } } while (1); DB->abort("SuePlay"); if (R.size() == 0) break; // positions are specified in terms of STEREO samples // database positions are in terms of STEREO samples fader[active]->clearNodes(); unsigned long offset = start; if (fade_in > start) fade_in = fade_in - offset; else fade_in = 256; L_INFO(LOG_SUEPLAY, " -> Fadein: " + dps_itoa(fade_in)); fader[active]->addNode(0,0.0); fader[active]->addNode(fade_in,1.0); L_INFO(LOG_SUEPLAY, " -> Fadeout: " + dps_itoa(fade_out)); if (fade_out < end) fade_out = fade_out - offset; else fade_out = end - 256 - offset; end = end - offset; L_INFO(LOG_SUEPLAY, " -> Fade out length: " + dps_itoa(end - fade_out)); fader[active]->addNode(fade_out,1.0); fader[active]->addNode(end,0.0); trig[active]->setTriggerSample(min(fade_out,end)); // Wait until last track has been played before we load the next if (ch[inactive] && ch[inactive]->isLoaded()) { L_INFO(LOG_SUEPLAY, "Waiting for channel " + dps_itoa(inactive)); trig[inactive]->waitStop(); if (print_info) { curtime = time(NULL); nicetime = ctime(&curtime); nicetime = nicetime.substr(4,12); cout << nicetime << " | Now playing: " << artist << " - " << title << endl; } L_INFO(LOG_SUEPLAY, "Finished waiting"); } else { L_INFO(LOG_SUEPLAY, "Playing channel " + dps_itoa(active)); ch[active]->play(); if (print_info) { curtime = time(NULL); nicetime = ctime(&curtime); nicetime = nicetime.substr(4,12); cout << nicetime << " | Now playing: " << artist << " - " << title << endl; } } int now = (int)time(NULL); artist = DB->esc(artist); title = DB->esc(title); string SQL_Insert = "INSERT INTO log " "(userid, datetime, track_title, track_artist, location) " "VALUES (" + dps_itoa(1) + ", " + dps_itoa(now) + ", '" + title + "', '" + artist + "', " + dps_itoa(0) + ");"; try { L_INFO(LOG_SUEPLAY,"Writing log entry for " + artist + " - " + title + "."); DB->exec("SuePlayLog",SQL_Insert); DB->commit("SuePlayLog"); } catch (...) { DB->abort("SuePlayLog"); L_ERROR(LOG_TABLOGGING,"Failed to log record " + artist + " - " + title + "."); } // Remove the entry from schedule once we've tried to load it L_INFO(LOG_SUEPLAY, "Removing track from sustainer playlist."); SQL_Remove = "DELETE FROM sustschedule WHERE id=" + id; try{ DB->exec("SuePlay",SQL_Remove); DB->commit("SuePlay"); } catch (...) { L_INFO(LOG_SUEPLAY, "Failed to remove track from sustainer playlist."); } active = abs(active - 1); inactive = abs(inactive - 1); } delete ch[0]; delete ch[1]; delete fader[0]; delete fader[1]; delete mixer; delete player; delete Conf; delete DB; }
/** Make a write request. * @param access the memory access being made * @param doStoreBufferAccess whether to use the det store buffer for this write */ virtual void write( const DataAccess& access, bool doStoreBufferAccess ) { State* myLine = NULL; CacheResponse r = L1cache->search( access.addr(), myLine ); if ( r != MISSED_TO_MEMORY ) { switch (r) { case L1_HIT: timeInMemoryHierarchy += L1_HIT_LATENCY; // default det cache latency is an L1 hit, so it doesn't matter whether we hit to a dirty line or not deterministicTimeInMemoryHierarchy += L1_HIT_LATENCY; break; case L2_HIT: { timeInMemoryHierarchy += L2_HIT_LATENCY; if ( myLine->isDirty() ) { deterministicTimeInMemoryHierarchy += L2_HIT_LATENCY; } else { deterministicTimeInMemoryHierarchy += L1_HIT_LATENCY; } break; } case L3_HIT: timeInMemoryHierarchy += L3_HIT_LATENCY; // shared cache hits aren't det deterministicTimeInMemoryHierarchy += L1_HIT_LATENCY; break; default: assert(false); } // we either hit somewhere in our private cache(s) or we hit in the shared cache, // but we may not have write permissions L1cache->access( access.addr(), myLine ); switch ( myLine->getState() ) { case MESI_SHARED: // upgrade miss numUpgradeMisses++; writeRemoteAction( access ); // invalidate other copies timeInMemoryHierarchy += REMOTE_HIT_LATENCY; myLine->changeStateTo( MESI_MODIFIED ); if ( useDetStoreBuffers && doStoreBufferAccess ) { myLine->setDirty(); StoreBufferIsEmpty = false; } return; case MESI_EXCLUSIVE: // write hit case MESI_MODIFIED: numWriteHits++; // TODO: fix this duplication from the MESI_SHARED case myLine->changeStateTo( MESI_MODIFIED ); if ( useDetStoreBuffers && doStoreBufferAccess ) { myLine->setDirty(); StoreBufferIsEmpty = false; } return; default: assert(false); } } // we didn't have the line at all - need to check for remote copies InvalidateReply inv_ack = writeRemoteAction( access ); // remote hits and missing to memory aren't det deterministicTimeInMemoryHierarchy += L1_HIT_LATENCY; if ( inv_ack.nobodyHasThisLine ) { numWriteMisses++; timeInMemoryHierarchy += MEMORY_ACCESS_LATENCY; } else { numWriteRemoteHits++; timeInMemoryHierarchy += REMOTE_HIT_LATENCY; } L1cache->access( access.addr(), myLine ); myLine->changeStateTo( MESI_MODIFIED ); if ( useDetStoreBuffers && doStoreBufferAccess ) { myLine->setDirty(); StoreBufferIsEmpty = false; } } // end write()
/** Perform a data read specified by the given `access'. */ virtual void read( const DataAccess& access ) { State* line = NULL; CacheResponse r = L1cache->search( access.addr(), line ); if ( r != MISSED_TO_MEMORY ) { // we hit somewhere in our private cache(s), or a shared cache numReadHits++; switch ( r ) { case L1_HIT: timeInMemoryHierarchy += L1_HIT_LATENCY; // default det cache latency is an L1 hit, so it doesn't matter whether we hit to a dirty line or not deterministicTimeInMemoryHierarchy += L1_HIT_LATENCY; return; case L2_HIT: { timeInMemoryHierarchy += L2_HIT_LATENCY; if ( line->isDirty() ) { deterministicTimeInMemoryHierarchy += L2_HIT_LATENCY; } else { deterministicTimeInMemoryHierarchy += L1_HIT_LATENCY; } return; } case L3_HIT: timeInMemoryHierarchy += L3_HIT_LATENCY; // shared cache hits aren't det deterministicTimeInMemoryHierarchy += L1_HIT_LATENCY; return; default: assert(false); } } // we missed, so check remote caches for data RemoteReadService rrs = readRemoteAction( access ); // remote hits and missing to memory aren't det deterministicTimeInMemoryHierarchy += L1_HIT_LATENCY; MESIState newMesiState = MESI_INVALID; if ( rrs.providedData == false ) { // No Valid Read-Reply: Need to get this data from Memory numReadMisses++; timeInMemoryHierarchy += MEMORY_ACCESS_LATENCY-1; /* NB: we always fetch from memory into Exclusive. */ newMesiState = MESI_EXCLUSIVE; } else if ( rrs.isShared ) { newMesiState = MESI_SHARED; numReadRemoteHits++; timeInMemoryHierarchy += REMOTE_HIT_LATENCY; } else { //Valid Read-Reply From Modified/Exclusive newMesiState = MESI_SHARED; numReadRemoteHits++; timeInMemoryHierarchy += REMOTE_HIT_LATENCY; } assert( newMesiState != MESI_INVALID ); // pull in the actual line L1cache->access( access.addr(), line ); line->changeStateTo( newMesiState ); } // end read()