void ProfileManager::updateCurrentProfile() { QDir profileDir(DataPaths::currentProfilePath()); if (!profileDir.exists()) { QDir newDir(profileDir.path().remove(profileDir.dirName())); newDir.mkdir(profileDir.dirName()); } QFile versionFile(profileDir.filePath(QLatin1String("version"))); // If file exists, just update the profile to current version if (versionFile.exists()) { versionFile.open(QFile::ReadOnly); QString profileVersion = versionFile.readAll(); versionFile.close(); updateProfile(Qz::VERSION, profileVersion.trimmed()); } else { copyDataToProfile(); } versionFile.open(QFile::WriteOnly); versionFile.write(Qz::VERSION); versionFile.close(); }
void CExplorerView::CreateContextMenuActions() { m_aRename = new QAction(tr("Renomer"), this); // m_aRename->setShortcuts(QKeySequence::Replace); m_aRename->setStatusTip(tr("Renome le fichier ou le dossier")); addAction(m_aRename); connect(m_aRename, SIGNAL(triggered()), this, SLOT(rename())); m_aErase = new QAction(tr("Supprimer"), this); m_aErase->setShortcut(QKeySequence::Delete); m_aErase->setStatusTip(tr("Renome le fichier ou le dossier")); addAction(m_aErase); connect(m_aErase, SIGNAL(triggered()), this, SLOT(erase())); m_aOpen = new QAction(tr("Ouvrir"), this); m_aOpen->setShortcut(QKeySequence::Open); m_aOpen->setStatusTip(tr("Ouvrir le fichier ou le dossier")); addAction(m_aOpen); connect(m_aOpen, SIGNAL(triggered()), this, SLOT(open())); m_aNewDir = new QAction(tr("Nouveau dossier"), this); m_aNewDir->setShortcut(QKeySequence::New); m_aNewDir->setStatusTip(tr("Créer un nouveau dossier")); addAction(m_aNewDir); connect(m_aNewDir, SIGNAL(triggered()), this, SLOT(newDir())); }
void ProfileUpdater::checkProfile() { QDir profileDir(m_profilePath); if (!profileDir.exists()) { QDir newDir(profileDir.path().remove(profileDir.dirName())); newDir.mkdir(profileDir.dirName()); } QFile versionFile(m_profilePath + "version"); if (versionFile.exists()) { versionFile.open(QFile::ReadOnly); QString profileVersion = versionFile.readAll(); versionFile.close(); versionFile.remove(); updateProfile(QupZilla::VERSION, profileVersion.trimmed()); } else { copyDataToProfile(); } versionFile.open(QFile::WriteOnly); versionFile.write(QupZilla::VERSION.toUtf8()); versionFile.close(); }
void CFileSystem::addDir(const CString& dir, const CString& wildcard, bool forceRecursive) { #ifndef NO_BOOST boost::recursive_mutex::scoped_lock lock(*m_preventChange); #endif if (server == 0) return; // Format the directory. CString newDir(dir); if (newDir[newDir.length() - 1] == '/' || newDir[newDir.length() - 1] == '\\') CFileSystem::fixPathSeparators(&newDir); else { newDir << fSep; CFileSystem::fixPathSeparators(&newDir); } // Add the directory to the directory list. CString ndir = CString() << server->getServerPath() << newDir << wildcard; if (vecSearch<CString>(dirList, ndir) != -1) // Already exists? Resync. resync(); else { dirList.push_back(ndir); // Load up the files in the directory. loadAllDirectories(ndir, (forceRecursive ? true : server->getSettings()->getBool("nofoldersconfig", false))); } }
bool KoDirectoryStore::enterAbsoluteDirectory(const QString& path) { m_currentPath = m_basePath + path; //debugStore <<"KoDirectoryStore::enterAbsoluteDirectory" << m_currentPath; QDir newDir(m_currentPath); Q_ASSERT(newDir.exists()); // We've been there before, therefore it must exist. return newDir.exists(); }
b2Vec2 Enemy::spin(float speed) { b2Vec2 orientation = getOrientation(); float rotation = atan2f(orientation.y, orientation.x); b2Vec2 newDir(cosf(rotation + speed), sinf(rotation + speed)); return newDir; }
void SetupDatabase::applySettings() { AlbumSettings* settings = AlbumSettings::instance(); if (!settings) { return; } if (d->databaseWidget->currentDatabaseType() == QString(DatabaseParameters::SQLiteDatabaseType())) { QString newPath = d->databaseWidget->databasePathEdit->url().path(); QDir oldDir(d->databaseWidget->originalDbPath); QDir newDir(newPath); if (oldDir != newDir || d->databaseWidget->currentDatabaseType() != d->databaseWidget->originalDbType) { settings->setDatabaseParameters(DatabaseParameters::parametersForSQLiteDefaultFile(newPath)); // clear other fields d->databaseWidget->internalServer->setChecked(false); settings->saveSettings(); } } else { if (d->databaseWidget->internalServer->isChecked()) { DatabaseParameters internalServerParameters = DatabaseParameters::defaultParameters(d->databaseWidget->currentDatabaseType()); settings->setInternalDatabaseServer(true); settings->setDatabaseType(d->databaseWidget->currentDatabaseType()); settings->setDatabaseName(internalServerParameters.databaseName); settings->setDatabaseNameThumbnails(internalServerParameters.databaseName); settings->setDatabaseConnectoptions(internalServerParameters.connectOptions); settings->setDatabaseHostName(internalServerParameters.hostName); settings->setDatabasePort(internalServerParameters.port); settings->setDatabaseUserName(internalServerParameters.userName); settings->setDatabasePassword(internalServerParameters.password); } else { settings->setInternalDatabaseServer(d->databaseWidget->internalServer->isChecked()); settings->setDatabaseType(d->databaseWidget->currentDatabaseType()); settings->setDatabaseName(d->databaseWidget->databaseName->text()); settings->setDatabaseNameThumbnails(d->databaseWidget->databaseNameThumbnails->text()); settings->setDatabaseConnectoptions(d->databaseWidget->connectionOptions->text()); settings->setDatabaseHostName(d->databaseWidget->hostName->text()); settings->setDatabasePort(d->databaseWidget->hostPort->text().toInt()); settings->setDatabaseUserName(d->databaseWidget->userName->text()); settings->setDatabasePassword(d->databaseWidget->password->text()); } settings->saveSettings(); } }
void ofxNestedFileLoader::findNestedFilePaths(string root) { ofDirectory dir(root); dir.listDir(); for(int i = 0; i < dir.size(); i++) { ofDirectory newDir(dir.getPath(i)); if(newDir.isDirectory()) { findNestedFilePaths(dir.getPath(i)); } else { paths.push_back(dir.getPath(i)); } } }
bool JSONFileLoader::Load(const std::string& szFileName, json_spirit::mObject& tData, const std::string& szSubDirectory, bool bIsBinary) { bool bSuccess = false; if (!szFileName.empty()) { std::string szDirPath = APP_DATA_PATH + "\\"; if (!szSubDirectory.empty()) { szDirPath += szSubDirectory + "\\"; boost::filesystem::path newDir(szDirPath); if (!boost::filesystem::exists(newDir)) { if (!boost::filesystem::create_directory(newDir)) { bSuccess = false; } } } if (!szDirPath.empty()) { std::string szDirFile = szDirPath + szFileName; boost::filesystem::path dirFile(szDirFile); if (boost::filesystem::exists(dirFile)) { json_spirit::mValue readVal; if (!bIsBinary) { std::ifstream jsonInFile(szDirFile); json_spirit::read(jsonInFile, readVal); jsonInFile.close(); } else { std::ifstream jsonInFile(szDirFile, std::ios::binary); json_spirit::read(jsonInFile, readVal); jsonInFile.close(); } tData["DATA"] = readVal; bSuccess = true; } } } return bSuccess; }
bool JSONFileLoader::Save(const std::string& szFileName, json_spirit::mObject tData, const std::string& szSubDirectory, bool bOverwrite, bool bIsBinary) { bool bSuccess = false; if (!szFileName.empty()) { std::string szDirPath = APP_DATA_PATH + "\\"; if (!szSubDirectory.empty()) { szDirPath += szSubDirectory + "\\"; boost::filesystem::path newDir(szDirPath); if (!boost::filesystem::exists(newDir)) { if (!boost::filesystem::create_directory(newDir)) { bSuccess = false; } } } if (!szDirPath.empty()) { std::string szDirFile = szDirPath + szFileName; boost::filesystem::path dirFile(szDirFile); if ((!boost::filesystem::exists(dirFile)) || (bOverwrite && boost::filesystem::is_regular_file(dirFile))) { if (!bIsBinary) { std::ofstream jsonFile(szDirFile); json_spirit::write(tData, jsonFile, json_spirit::Output_options::pretty_print); jsonFile.close(); } else { std::ofstream jsonBinaryFile(szDirFile, std::ios::binary); json_spirit::write(tData, jsonBinaryFile, json_spirit::Output_options::none); jsonBinaryFile.close(); } bSuccess = true; } } } return bSuccess; }
//Towards player, shoot if close, run if low hp void Enemy::classicAI() { Shape* player = getPlayer_(); if (player) { b2Vec2 playerPos = player->getPosition(); b2Vec2 ePos = getPosition(); b2Vec2 between = playerPos - ePos; //In long distance, look if (between.Length() < 40 || between.Length() < 4.f) { orient(between); } //In med distance, move towards, shoot at if (between.Length() < 25 && (getHP() >= verticesMIN_ * hpScale_)) { if (getArmed()) { move(between); orient(between); if (getWeaponReady()) { float rotation = atan2f(between.y, between.x); float adjust = randFloat(-0.4, 0.4); b2Vec2 newDir(cosf(rotation + adjust), sinf(rotation + adjust)); trigger(between); } else release(); } } else if (getArmed() && between.Length() < verticesMIN_ * hpScale_) { orient(-between); move(-between); } else if (!getArmed() && between.Length() < size_ * 1.5f) { orient(-between); } else move(b2Vec2_zero); } }
bool Enemy::fireAt(const b2Vec2& target, float spread) { if (getWeaponReady()) { float rotation = atan2f(target.y, target.x); float adjust = randFloat(-0.4, 0.4); b2Vec2 newDir(cosf(rotation + adjust), sinf(rotation + adjust)); orient(target); trigger(newDir); fired_ = true; return true; } else return false; }
bool KoDirectoryStore::enterRelativeDirectory(const QString& dirName) { QDir origDir(m_currentPath); m_currentPath += dirName; if (!m_currentPath.endsWith('/')) m_currentPath += '/'; //debugStore <<"KoDirectoryStore::enterRelativeDirectory m_currentPath now" << m_currentPath; QDir newDir(m_currentPath); if (newDir.exists()) return true; // Dir doesn't exist. If reading -> error. If writing -> create. if (mode() == Write && origDir.mkdir(dirName)) { debugStore << "Created" << dirName << " under" << origDir.absolutePath(); return true; } return false; }
void PropagateLocalMkdir::start() { if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) return; QDir newDir(_propagator->_localDir + _item._file); QString newDirStr = QDir::toNativeSeparators(newDir.path()); if( Utility::fsCasePreserving() && _propagator->localFileNameClash(_item._file ) ) { qDebug() << "WARN: new directory to create locally already exists!"; done( SyncFileItem::NormalError, tr("Attention, possible case sensitivity clash with %1").arg(newDirStr) ); return; } QDir localDir(_propagator->_localDir); if (!localDir.mkpath(_item._file)) { done( SyncFileItem::NormalError, tr("could not create directory %1").arg(newDirStr) ); return; } done(SyncFileItem::Success); }
//--------------------------------------------------------------------------- STATIC void C23Cooker::CookObjFilesInFolder( const std::string& rawDataDirectory, const std::string& cookedDataDestinationDirectory, bool isCookAllEnabled ) { std::vector< Vertex3D > vertexes; std::vector< unsigned int > indexes; std::vector< std::string > filePaths; std::string objFileName; std::string c23FileName; std::string destination( cookedDataDestinationDirectory ); OBJFileHandler objFileHandler; C23FileHandler c23FileHandler; // find all the .obj files in this directory // if ( rawDataDirectory.back() == '/' ) // { // FileSystem::EnumerateFilesInDirectory( rawDataDirectory + "*.obj", filePaths ); // } // else // { // FileSystem::EnumerateFilesInDirectory( rawDataDirectory + "/*.obj", filePaths ); // } FileSystem::EnumerateFilesInDirectory( rawDataDirectory, filePaths ); // if we found no files, return if ( filePaths.empty() ) { std::cerr << "No files found!" << std::endl; return; } // add a trailing '/' to destination if don't already have if ( destination.back() != '/' ) { destination += '/'; } std::wstring dataFolder( destination.begin(), destination.end() ); CreateDirectoryW( dataFolder.c_str(), nullptr ); for ( unsigned int index = 0; index < ( unsigned int ) filePaths.size(); ++ index ) { std::string& currentFilePath = filePaths[ index ]; destination = cookedDataDestinationDirectory + currentFilePath.substr( rawDataDirectory.find_first_of( '*' ) ); if ( currentFilePath.substr( 0, currentFilePath.find_last_of( '/' ) + 1 ) == currentFilePath ) { std::cout << "Creating directory " + destination + "... "; std::wstring newDir( destination.begin(), destination.end() ); CreateDirectoryW( newDir.c_str(), nullptr ); std::cout << "Done!" << std::endl; } else if ( currentFilePath.substr( currentFilePath.find_last_of( '.' ) ) == ".obj" ) { if ( FileSystem::IsFileDateOlder( currentFilePath, destination.substr( 0, destination.find_last_of( '.' ) ) + ".c23" ) && !isCookAllEnabled ) continue; destination = destination.substr( 0, destination.find_last_of( '/' ) + 1 ); objFileName = currentFilePath.substr( currentFilePath.find_last_of( '/' ) + 1 ); c23FileName = objFileName.substr( 0, objFileName.find_last_of( '.' ) ) + ".c23"; std::cout << "Cooking " << objFileName << "... "; objFileHandler.ReadFromObjAndStoreVertexesAndIndexes( currentFilePath.c_str(), vertexes, indexes ); if ( vertexes.empty() ) { std::cerr << "Error - file failed to load!" << std:: endl; continue; } c23FileHandler.WriteToFile( ( destination + c23FileName ).c_str(), vertexes, indexes ); std::cout << "Success!" << std::endl; vertexes.clear(); indexes.clear(); } else { if ( FileSystem::IsFileDateOlder( currentFilePath, destination ) && !isCookAllEnabled ) continue; std::cout << "Copying " << currentFilePath << " to " << destination << "... "; std::wstring oldFile( currentFilePath.begin(), currentFilePath.end() ); std::wstring newFile( destination.begin(), destination.end() ); CopyFileW( oldFile.c_str(), newFile.c_str(), false ); std::cout << "Done!" << std::endl; } } // std::cout << "Cooking " << filePaths.size() << " items..." << std::endl; // cook each file to the destination directory }
int yyparse (void) { int yystate; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; /* The stacks and their tools: 'yyss': related to states. 'yyvs': related to semantic values. Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ yytype_int16 yyssa[YYINITDEPTH]; yytype_int16 *yyss; yytype_int16 *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs; YYSTYPE *yyvsp; YYSIZE_T yystacksize; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ int yytoken = 0; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; #if YYERROR_VERBOSE /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; yyssp = yyss = yyssa; yyvsp = yyvs = yyvsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; yysetstate: *yyssp = yystate; if (yyss + yystacksize - 1 <= yyssp) { /* Get the current used size of the three stacks, in elements. */ YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; yytype_int16 *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE goto yyexhaustedlab; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { yytype_int16 *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); if (yystate == YYFINAL) YYACCEPT; goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: /* Do appropriate processing given the current state. Read a lookahead token if we need one and don't already have one. */ /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); yychar = yylex (); } if (yychar <= YYEOF) { yychar = yytoken = YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } else { yytoken = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ yyn += yytoken; if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) { if (yytable_value_is_error (yyn)) goto yyerrlab; yyn = -yyn; goto yyreduce; } /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the shifted token. */ yychar = YYEMPTY; yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce; /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: '$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; YY_REDUCE_PRINT (yyn); switch (yyn) { case 2: #line 53 "parser.y" /* yacc.c:1646 */ { printf("P->PL\n"); fprintf(yyout,"P->PL\n"); } #line 1269 "y.tab.c" /* yacc.c:1646 */ break; case 3: #line 56 "parser.y" /* yacc.c:1646 */ { printf("P->L\n"); fprintf(yyout,"P->L\n"); } #line 1278 "y.tab.c" /* yacc.c:1646 */ break; case 4: #line 61 "parser.y" /* yacc.c:1646 */ { printf("L->E NL\n"); fprintf(yyout,"L->E NL\n"); } #line 1287 "y.tab.c" /* yacc.c:1646 */ break; case 5: #line 66 "parser.y" /* yacc.c:1646 */ { printf("S->id=E;\n"); // $1=(char*)malloc(2*sizeof(char)); // strcpy($$.code,$1); // printf("%s=%s;\n",$$.code,$3.code); fprintf(yyout,"S->id=E;\n"); } #line 1299 "y.tab.c" /* yacc.c:1646 */ break; case 6: #line 74 "parser.y" /* yacc.c:1646 */ { printf("L->id[E]\n"); fprintf(yyout,"L->id[E]\n"); } #line 1308 "y.tab.c" /* yacc.c:1646 */ break; case 7: #line 77 "parser.y" /* yacc.c:1646 */ { printf("L->L[E]"); fprintf(yyout,"L->L[E]"); } #line 1317 "y.tab.c" /* yacc.c:1646 */ break; case 8: #line 82 "parser.y" /* yacc.c:1646 */ { newDir(); (yyval.type).code=(char*)malloc(2*sizeof(char)); strcpy((yyval.type).code,"t"); char dr[100]; sprintf(dr,"%d",dir); strcat((yyval.type).code,dr); printf("%s = %s + %s\n", (yyval.type).code,(yyvsp[-2].type).code,(yyvsp[0].type).code); fprintf(yyout,"%s = %s + %s\n", (yyval.type).code,(yyvsp[-2].type).code,(yyvsp[0].type).code); printf("E->E+T\n"); fprintf(yyout,"E->E+T\n"); } #line 1334 "y.tab.c" /* yacc.c:1646 */ break; case 9: #line 94 "parser.y" /* yacc.c:1646 */ { (yyval.type) = (yyvsp[0].type); printf("E->T\n"); fprintf(yyout,"E->T\n"); } #line 1344 "y.tab.c" /* yacc.c:1646 */ break; case 10: #line 100 "parser.y" /* yacc.c:1646 */ { newDir(); (yyval.type).code=(char*)malloc(2*sizeof(char)); strcpy((yyval.type).code,"t"); char dr[100]; sprintf(dr,"%d",dir); strcat((yyval.type).code,dr); printf("%s = %s * %s\n", (yyval.type).code,(yyvsp[-2].type).code,(yyvsp[0].type).code); fprintf(yyout,"%s = %s * %s\n", (yyval.type).code,(yyvsp[-2].type).code,(yyvsp[0].type).code); printf("T->T*F\n"); fprintf(yyout,"T->T*F\n"); } #line 1361 "y.tab.c" /* yacc.c:1646 */ break; case 11: #line 112 "parser.y" /* yacc.c:1646 */ { (yyval.type)=(yyvsp[0].type); printf("T->F\n"); fprintf(yyout,"T->F\n"); } #line 1371 "y.tab.c" /* yacc.c:1646 */ break; case 12: #line 118 "parser.y" /* yacc.c:1646 */ { (yyval.type)=(yyvsp[-1].type); printf("F->(E)\n"); } #line 1380 "y.tab.c" /* yacc.c:1646 */ break; case 13: #line 122 "parser.y" /* yacc.c:1646 */ { (yyval.type).code=(char*)malloc(2*sizeof(char)); strcpy((yyval.type).code,(yyvsp[0].sval)); printf("F->id\n"); fprintf(yyout,"F->id\n"); } #line 1391 "y.tab.c" /* yacc.c:1646 */ break; case 14: #line 127 "parser.y" /* yacc.c:1646 */ { (yyval.type).code=(char*)malloc(2*sizeof(char)); strcpy((yyval.type).code,(yyvsp[0].num).code); printf("F->num\n"); fprintf(yyout,"F->num\n"); } #line 1402 "y.tab.c" /* yacc.c:1646 */ break; case 15: #line 132 "parser.y" /* yacc.c:1646 */ { printf("F->S\n"); fprintf(yyout,"F->S\n"); } #line 1411 "y.tab.c" /* yacc.c:1646 */ break; case 16: #line 135 "parser.y" /* yacc.c:1646 */ { printf("F->L\n"); fprintf(yyout,"F->L\n"); } #line 1420 "y.tab.c" /* yacc.c:1646 */ break; #line 1424 "y.tab.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires that yytoken be updated with the new translation. We take the approach of translating immediately before every use of yytoken. One alternative is translating here after every semantic action, but that translation would be missed if the semantic action invokes YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an incorrect destructor might then be invoked immediately. In the case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ yyn = yyr1[yyn]; yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else yystate = yydefgoto[yyn - YYNTOKENS]; goto yynewstate; /*--------------------------------------. | yyerrlab -- here on detecting error. | `--------------------------------------*/ yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; #if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); #else # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ yyssp, yytoken) { char const *yymsgp = YY_("syntax error"); int yysyntax_error_status; yysyntax_error_status = YYSYNTAX_ERROR; if (yysyntax_error_status == 0) yymsgp = yymsg; else if (yysyntax_error_status == 1) { if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); if (!yymsg) { yymsg = yymsgbuf; yymsg_alloc = sizeof yymsgbuf; yysyntax_error_status = 2; } else { yysyntax_error_status = YYSYNTAX_ERROR; yymsgp = yymsg; } } yyerror (yymsgp); if (yysyntax_error_status == 2) goto yyexhaustedlab; } # undef YYSYNTAX_ERROR #endif } if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ if (yychar <= YYEOF) { /* Return failure if at end of input. */ if (yychar == YYEOF) YYABORT; } else { yydestruct ("Error: discarding", yytoken, &yylval); yychar = YYEMPTY; } } /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; /*---------------------------------------------------. | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: /* Pacify compilers like GCC when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ if (/*CONSTCOND*/ 0) goto yyerrorlab; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); yystate = *yyssp; goto yyerrlab1; /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { yyn = yytable[yyn]; if (0 < yyn) break; } } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) YYABORT; yydestruct ("Error: popping", yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturn; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturn; #if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: if (yychar != YYEMPTY) { /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", yytoken, &yylval); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", yystos[*yyssp], yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif #if YYERROR_VERBOSE if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); #endif return yyresult; }
void Gutenbrowser::doOptions() { optionsDialog* optDlg; optDlg = new optionsDialog( this,"Options_Dlg", true); QString Ddir; Config config("Gutenbrowser"); config.setGroup( "General" ); QFont myFont; optDlg->showMaximized(); if( optDlg->exec() !=0) { qApp->processEvents(); brow=optDlg->browserName; toggleButtonIcons( optDlg->useIcon); ftp_host= optDlg->ftp_host; ftp_base_dir= optDlg->ftp_base_dir; brow=optDlg->browserName; Ddir=optDlg->downloadDirEdit->text(); odebug << "writing library config" << oendl; Config config("Gutenbrowser"); config.setGroup("General"); QString dirname= optDlg->downloadDirEdit->text(); if(dirname.right(1)!="/") dirname+="/"; config.writeEntry( "DownloadDirectory",dirname); QDir newDir( optDlg->downloadDirEdit->text()); if( !newDir.exists() ) { int exit=QMessageBox::information(this, "Note", "Ok, to make a new directory\n" + Ddir + " ?", QMessageBox::Ok, QMessageBox::Cancel); if (exit==1) { QString cmd="mkdir -p "; cmd+=Ddir.latin1(); system(cmd); odebug << "Making new dir "+cmd << oendl; if(Ddir.right(1)!="/") Ddir+="/"; config.writeEntry("DownloadDirectory",Ddir); } } if(optDlg->b_qExit==TRUE) b_queryExit=TRUE; else b_queryExit=FALSE; if(optDlg->fontDlg-> changedFonts) { odebug << "Setting font" << oendl; myFont=optDlg->fontDlg->selectedFont; Lview->setFont( myFont); } if(optDlg->useWordWrap_CheckBox->isChecked() ) { odebug << "WORD WRAP is set" << oendl; Lview->setWordWrap(QMultiLineEdit::WidgetWidth); useWrap=true; } else { odebug << "Word wrap is NOT set" << oendl; Lview->setWordWrap(QMultiLineEdit::NoWrap); useWrap=false; } } if(showMainList) { if(!Lview->isHidden()) Lview->hide(); qApp->processEvents(); if(mainList->isHidden()) mainList->show(); fillWithTitles(); } else { Lview->show(); showMainList=FALSE; mainList->hide(); } qApp->processEvents(); update(); }
// We return the UserSettings here because we have to make changes to the // configuration and the location of the file may change between releases. UserSettingsPointer Upgrade::versionUpgrade(const QString& settingsPath) { /* Pre-1.7.0: * * Since we didn't store version numbers in the config file prior to 1.7.0, * we check to see if the user is upgrading if his config files are in the old location, * since we moved them in 1.7.0. This code takes care of moving them. */ QDir oldLocation = QDir(QDir::homePath()); #ifdef __WINDOWS__ QFileInfo* pre170Config = new QFileInfo(oldLocation.filePath("mixxx.cfg")); #else QFileInfo* pre170Config = new QFileInfo(oldLocation.filePath(".mixxx.cfg")); #endif if (pre170Config->exists()) { // Move the files to their new location QDir newLocation = QDir(settingsPath); if (!newLocation.exists()) { qDebug() << "Creating new settings directory" << newLocation.absolutePath(); newLocation.mkpath("."); } QString errorText = "Error moving your %1 file %2 to the new location %3: \n"; #ifdef __WINDOWS__ QString oldFilePath = oldLocation.filePath("mixxxtrack.xml"); #else QString oldFilePath = oldLocation.filePath(".mixxxtrack.xml"); #endif QString newFilePath = newLocation.filePath("mixxxtrack.xml"); QFile* oldFile = new QFile(oldFilePath); if (oldFile->exists()) { if (oldFile->copy(newFilePath)) { oldFile->remove(); } else { if (oldFile->error()==14) qDebug() << errorText.arg("library", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("library", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } delete oldFile; #ifdef __WINDOWS__ oldFilePath = oldLocation.filePath("mixxxbpmschemes.xml"); #else oldFilePath = oldLocation.filePath(".mixxxbpmscheme.xml"); #endif newFilePath = newLocation.filePath("mixxxbpmscheme.xml"); oldFile = new QFile(oldFilePath); if (oldFile->exists()) { if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("settings", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("settings", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } delete oldFile; #ifdef __WINDOWS__ oldFilePath = oldLocation.filePath("MixxxMIDIBindings.xml"); #else oldFilePath = oldLocation.filePath(".MixxxMIDIBindings.xml"); #endif newFilePath = newLocation.filePath("MixxxMIDIBindings.xml"); oldFile = new QFile(oldFilePath); if (oldFile->exists()) { qWarning() << "The MIDI mapping file format has changed in this version of Mixxx. You will need to reconfigure your MIDI controller. See the Wiki for full details on the new format."; if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("MIDI mapping", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("MIDI mapping", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } // Tidy up delete oldFile; #ifdef __WINDOWS__ QFile::remove(oldLocation.filePath("MixxxMIDIDevice.xml")); // Obsolete file, so just delete it #else QFile::remove(oldLocation.filePath(".MixxxMIDIDevice.xml")); // Obsolete file, so just delete it #endif #ifdef __WINDOWS__ oldFilePath = oldLocation.filePath("mixxx.cfg"); #else oldFilePath = oldLocation.filePath(".mixxx.cfg"); #endif newFilePath = newLocation.filePath(SETTINGS_FILE); oldFile = new QFile(oldFilePath); if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("configuration", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("configuration", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } delete oldFile; } // Tidy up delete pre170Config; // End pre-1.7.0 code /*************************************************************************** * Post-1.7.0 upgrade code * * Add entries to the IF ladder below if anything needs to change from the * previous to the current version. This allows for incremental upgrades * in case a user upgrades from a few versions prior. ****************************************************************************/ // Read the config file from home directory UserSettingsPointer config(new ConfigObject<ConfigValue>( QDir(settingsPath).filePath(SETTINGS_FILE))); QString configVersion = config->getValueString(ConfigKey("[Config]","Version")); if (configVersion.isEmpty()) { #ifdef __APPLE__ qDebug() << "Config version is empty, trying to read pre-1.9.0 config"; // Try to read the config from the pre-1.9.0 final directory on OS X (we moved it in 1.9.0 final) QScopedPointer<QFile> oldConfigFile(new QFile(QDir::homePath().append("/").append(".mixxx/mixxx.cfg"))); if (oldConfigFile->exists() && ! CmdlineArgs::Instance().getSettingsPathSet()) { qDebug() << "Found pre-1.9.0 config for OS X"; // Note: We changed SETTINGS_PATH in 1.9.0 final on OS X so it must be hardcoded to ".mixxx" here for legacy. config = UserSettingsPointer(new ConfigObject<ConfigValue>( QDir::homePath().append("/.mixxx/mixxx.cfg"))); // Just to be sure all files like logs and soundconfig go with mixxx.cfg // TODO(XXX) Trailing slash not needed anymore as we switches from String::append // to QDir::filePath elsewhere in the code. This is candidate for removal. CmdlineArgs::Instance().setSettingsPath(QDir::homePath().append("/.mixxx/")); configVersion = config->getValueString(ConfigKey("[Config]","Version")); } else { #elif __WINDOWS__ qDebug() << "Config version is empty, trying to read pre-1.12.0 config"; // Try to read the config from the pre-1.12.0 final directory on Windows (we moved it in 1.12.0 final) QScopedPointer<QFile> oldConfigFile(new QFile(QDir::homePath().append("/Local Settings/Application Data/Mixxx/mixxx.cfg"))); if (oldConfigFile->exists() && ! CmdlineArgs::Instance().getSettingsPathSet()) { qDebug() << "Found pre-1.12.0 config for Windows"; // Note: We changed SETTINGS_PATH in 1.12.0 final on Windows so it must be hardcoded to "Local Settings/Application Data/Mixxx/" here for legacy. config = UserSettingsPointer(new ConfigObject<ConfigValue>( QDir::homePath().append("/Local Settings/Application Data/Mixxx/mixxx.cfg"))); // Just to be sure all files like logs and soundconfig go with mixxx.cfg // TODO(XXX) Trailing slash not needed anymore as we switches from String::append // to QDir::filePath elsewhere in the code. This is candidate for removal. CmdlineArgs::Instance().setSettingsPath(QDir::homePath().append("/Local Settings/Application Data/Mixxx/")); configVersion = config->getValueString(ConfigKey("[Config]","Version")); } else { #endif // This must have been the first run... right? :) qDebug() << "No version number in configuration file. Setting to" << MIXXX_VERSION; config->set(ConfigKey("[Config]","Version"), ConfigValue(MIXXX_VERSION)); m_bFirstRun = true; return config; #ifdef __APPLE__ } #elif __WINDOWS__ } #endif } // If it's already current, stop here if (configVersion == MIXXX_VERSION) { qDebug() << "Configuration file is at the current version" << MIXXX_VERSION; return config; } // Allows for incremental upgrades in case someone upgrades from a few versions prior // (I wish we could do a switch on a QString.) /* // Examples, since we didn't store the version number prior to v1.7.0 if (configVersion.startsWith("1.6.0")) { qDebug() << "Upgrading from v1.6.0 to 1.6.1..."; // Upgrade tasks go here configVersion = "1.6.1"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.6.1")); } if (configVersion.startsWith("1.6.1")) { qDebug() << "Upgrading from v1.6.1 to 1.7.0..."; // Upgrade tasks go here configVersion = "1.7.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.7.0")); } */ // We use the following blocks to detect if this is the first time // you've run the latest version of Mixxx. This lets us show // the promo tracks stats agreement stuff for all users that are // upgrading Mixxx. if (configVersion.startsWith("1.7")) { qDebug() << "Upgrading from v1.7.x..."; // Upgrade tasks go here // Nothing to change, really configVersion = "1.8.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.8.0")); } if (configVersion.startsWith("1.8.0~beta1") || configVersion.startsWith("1.8.0~beta2")) { qDebug() << "Upgrading from v1.8.0~beta..."; // Upgrade tasks go here configVersion = "1.8.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.8.0")); } if (configVersion.startsWith("1.8") || configVersion.startsWith("1.9.0beta1")) { qDebug() << "Upgrading from" << configVersion << "..."; // Upgrade tasks go here #ifdef __APPLE__ QString OSXLocation180 = QDir::homePath().append("/").append(".mixxx"); QString OSXLocation190 = settingsPath; QDir newOSXDir(OSXLocation190); newOSXDir.mkpath(OSXLocation190); QList<QPair<QString, QString> > dirsToMove; dirsToMove.push_back(QPair<QString, QString>(OSXLocation180, OSXLocation190)); dirsToMove.push_back(QPair<QString, QString>(OSXLocation180 + "/midi", OSXLocation190 + "midi")); dirsToMove.push_back(QPair<QString, QString>(OSXLocation180 + "/presets", OSXLocation190 + "presets")); QListIterator<QPair<QString, QString> > dirIt(dirsToMove); QPair<QString, QString> curPair; while (dirIt.hasNext()) { curPair = dirIt.next(); qDebug() << "Moving" << curPair.first << "to" << curPair.second; QDir oldSubDir(curPair.first); QDir newSubDir(curPair.second); newSubDir.mkpath(curPair.second); // Create the new destination directory QStringList contents = oldSubDir.entryList(QDir::Files | QDir::NoDotAndDotDot); QStringListIterator it(contents); QString cur; // Iterate over all the files in the source directory and copy them to the dest dir. while (it.hasNext()) { cur = it.next(); QString src = curPair.first + "/" + cur; QString dest = curPair.second + "/" + cur; qDebug() << "Copying" << src << "to" << dest; if (!QFile::copy(src, dest)) { qDebug() << "Failed to move file during upgrade."; } } // Rename the old directory. newOSXDir.rename(OSXLocation180, OSXLocation180 + "-1.8"); } // Reload the configuration file from the new location. // (We want to make sure we save to the new location...) config = UserSettingsPointer(new ConfigObject<ConfigValue>( QDir(settingsPath).filePath(SETTINGS_FILE))); #endif configVersion = "1.9.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.9.0")); } if (configVersion.startsWith("1.9") || configVersion.startsWith("1.10")) { qDebug() << "Upgrading from v1.9.x/1.10.x..."; bool successful = true; qDebug() << "Copying midi/ to controllers/"; QString midiPath = legacyUserPresetsPath(config); QString controllerPath = userPresetsPath(config); QDir oldDir(midiPath); QDir newDir(controllerPath); newDir.mkpath(controllerPath); // create the new directory QStringList contents = oldDir.entryList(QDir::Files | QDir::NoDotAndDotDot); QStringListIterator it(contents); QString cur; // Iterate over all the files in the source directory and copy them to the dest dir. while (it.hasNext()) { cur = it.next(); if (newDir.exists(cur)) { qDebug() << cur << "already exists in" << controllerPath << "Skipping."; continue; } QString src = oldDir.absoluteFilePath(cur); QString dest = newDir.absoluteFilePath(cur); qDebug() << "Copying" << src << "to" << dest; if (!QFile::copy(src, dest)) { qDebug() << "Failed to copy file during upgrade."; successful = false; } } bool reanalyze_choice = askReanalyzeBeats(); BeatDetectionSettings bpmSettings(config); bpmSettings.setReanalyzeWhenSettingsChange(reanalyze_choice); if (successful) { qDebug() << "Upgrade Successful"; configVersion = "1.11.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue(configVersion)); } else { qDebug() << "Upgrade Failed"; } } if (configVersion.startsWith("1.11")) { qDebug() << "Upgrading from v1.11.x..."; bool successful = false; { MixxxDb mixxxDb(config); const mixxx::DbConnectionPooler dbConnectionPooler( mixxxDb.connectionPool()); if (dbConnectionPooler.isPooling()) { QSqlDatabase dbConnection = mixxx::DbConnectionPooled(mixxxDb.connectionPool()); DEBUG_ASSERT(dbConnection.isOpen()); if (MixxxDb::initDatabaseSchema(dbConnection)) { TrackCollection tc(config); tc.connectDatabase(dbConnection); // upgrade to the multi library folder settings QString currentFolder = config->getValueString(PREF_LEGACY_LIBRARY_DIR); // to migrate the DB just add the current directory to the new // directories table // NOTE(rryan): We don't have to ask for sandbox permission to this // directory because the normal startup integrity check in Library will // notice if we don't have permission and ask for access. Also, the // Sandbox isn't setup yet at this point in startup because it relies on // the config settings path and this function is what loads the config // so it's not ready yet. successful = tc.getDirectoryDAO().addDirectory(currentFolder); tc.disconnectDatabase(); } } } // ask for library rescan to activate cover art. We can later ask for // this variable when the library scanner is constructed. m_bRescanLibrary = askReScanLibrary(); // Versions of mixxx until 1.11 had a hack that multiplied gain by 1/2, // which was compensation for another hack that set replaygain to a // default of 6. We've now removed all of the hacks, so subtracting // 6 from everyone's replay gain should keep things consistent for // all users. int oldReplayGain = config->getValue( ConfigKey("[ReplayGain]", "InitialReplayGainBoost"), 6); int newReplayGain = math_max(-6, oldReplayGain - 6); config->set(ConfigKey("[ReplayGain]", "InitialReplayGainBoost"), ConfigValue(newReplayGain)); // if everything until here worked fine we can mark the configuration as // updated if (successful) { configVersion = MIXXX_VERSION; config->set(ConfigKey("[Config]","Version"), ConfigValue(MIXXX_VERSION)); } else { qDebug() << "Upgrade failed!\n"; } } if (configVersion.startsWith("1.12") || configVersion.startsWith("2.0") || configVersion.startsWith("2.1.0")) { // No special upgrade required, just update the value. configVersion = MIXXX_VERSION; config->set(ConfigKey("[Config]","Version"), ConfigValue(MIXXX_VERSION)); } if (configVersion == MIXXX_VERSION) qDebug() << "Configuration file is now at the current version" << MIXXX_VERSION; else { qWarning() << "Configuration file is at version" << configVersion << "instead of the current" << MIXXX_VERSION; } return config; }
// We return the ConfigObject here because we have to make changes to the // configuration and the location of the file may change between releases. ConfigObject<ConfigValue>* Upgrade::versionUpgrade(const QString& settingsPath) { /* Pre-1.7.0: * * Since we didn't store version numbers in the config file prior to 1.7.0, * we check to see if the user is upgrading if his config files are in the old location, * since we moved them in 1.7.0. This code takes care of moving them. */ QString oldLocation = QDir::homePath().append("/%1"); #ifdef __WINDOWS__ QFileInfo* pre170Config = new QFileInfo(oldLocation.arg("mixxx.cfg")); #else QFileInfo* pre170Config = new QFileInfo(oldLocation.arg(".mixxx.cfg")); #endif if (pre170Config->exists()) { // Move the files to their new location QString newLocation = settingsPath; if (!QDir(newLocation).exists()) { qDebug() << "Creating new settings directory" << newLocation; QDir().mkpath(newLocation); } newLocation.append("%1"); QString errorText = "Error moving your %1 file %2 to the new location %3: \n"; #ifdef __WINDOWS__ QString oldFilePath = oldLocation.arg("mixxxtrack.xml"); #else QString oldFilePath = oldLocation.arg(".mixxxtrack.xml"); #endif QString newFilePath = newLocation.arg("mixxxtrack.xml"); QFile* oldFile = new QFile(oldFilePath); if (oldFile->exists()) { if (oldFile->copy(newFilePath)) { oldFile->remove(); m_bUpgraded = true; } else { if (oldFile->error()==14) qDebug() << errorText.arg("library", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("library", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } delete oldFile; #ifdef __WINDOWS__ oldFilePath = oldLocation.arg("mixxxbpmschemes.xml"); #else oldFilePath = oldLocation.arg(".mixxxbpmscheme.xml"); #endif newFilePath = newLocation.arg("mixxxbpmscheme.xml"); oldFile = new QFile(oldFilePath); if (oldFile->exists()) { if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("settings", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("settings", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } delete oldFile; #ifdef __WINDOWS__ oldFilePath = oldLocation.arg("MixxxMIDIBindings.xml"); #else oldFilePath = oldLocation.arg(".MixxxMIDIBindings.xml"); #endif newFilePath = newLocation.arg("MixxxMIDIBindings.xml"); oldFile = new QFile(oldFilePath); if (oldFile->exists()) { qWarning() << "The MIDI mapping file format has changed in this version of Mixxx. You will need to reconfigure your MIDI controller. See the Wiki for full details on the new format."; if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("MIDI mapping", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("MIDI mapping", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } } // Tidy up delete oldFile; QFile::remove(oldLocation.arg(".MixxxMIDIDevice.xml")); // Obsolete file, so just delete it #ifdef __WINDOWS__ oldFilePath = oldLocation.arg("mixxx.cfg"); #else oldFilePath = oldLocation.arg(".mixxx.cfg"); #endif newFilePath = newLocation.arg(SETTINGS_FILE); oldFile = new QFile(oldFilePath); if (oldFile->copy(newFilePath)) oldFile->remove(); else { if (oldFile->error()==14) qDebug() << errorText.arg("configuration", oldFilePath, newFilePath) << "The destination file already exists."; else qDebug() << errorText.arg("configuration", oldFilePath, newFilePath) << "Error #" << oldFile->error(); } delete oldFile; } // Tidy up delete pre170Config; // End pre-1.7.0 code /*************************************************************************** * Post-1.7.0 upgrade code * * Add entries to the IF ladder below if anything needs to change from the * previous to the current version. This allows for incremental upgrades * incase a user upgrades from a few versions prior. ****************************************************************************/ // Read the config file from home directory ConfigObject<ConfigValue> *config = new ConfigObject<ConfigValue>(settingsPath + SETTINGS_FILE); QString configVersion = config->getValueString(ConfigKey("[Config]","Version")); if (configVersion.isEmpty()) { #ifdef __APPLE__ qDebug() << "Config version is empty, trying to read pre-1.9.0 config"; //Try to read the config from the pre-1.9.0 final directory on OS X (we moved it in 1.9.0 final) QFile* oldFile = new QFile(QDir::homePath().append("/").append(".mixxx/mixxx.cfg")); if (oldFile->exists()) { qDebug() << "Found pre-1.9.0 config for OS X"; config = new ConfigObject<ConfigValue>(QDir::homePath().append("/").append(".mixxx/mixxx.cfg")); //Note: We changed SETTINGS_PATH in 1.9.0 final on OS X so it must be hardcoded to ".mixxx" here for legacy. configVersion = config->getValueString(ConfigKey("[Config]","Version")); delete oldFile; } else { #endif //This must have been the first run... right? :) qDebug() << "No version number in configuration file. Setting to" << VERSION; config->set(ConfigKey("[Config]","Version"), ConfigValue(VERSION)); m_bFirstRun = true; return config; #ifdef __APPLE__ } #endif } // If it's already current, stop here if (configVersion == VERSION) { qDebug() << "Configuration file is at the current version" << VERSION; return config; } // Allows for incremental upgrades incase someone upgrades from a few versions prior // (I wish we could do a switch on a QString.) /* // Examples, since we didn't store the version number prior to v1.7.0 if (configVersion.startsWith("1.6.0")) { qDebug() << "Upgrading from v1.6.0 to 1.6.1..."; // Upgrade tasks go here configVersion = "1.6.1"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.6.1")); } if (configVersion.startsWith("1.6.1")) { qDebug() << "Upgrading from v1.6.1 to 1.7.0..."; // Upgrade tasks go here configVersion = "1.7.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.7.0")); } */ //We use the following blocks to detect if this is the first time //you've run the latest version of Mixxx. This lets us show //the promo tracks stats agreement stuff for all users that are //upgrading Mixxx. if (configVersion.startsWith("1.7")) { qDebug() << "Upgrading from v1.7.x..."; // Upgrade tasks go here // Nothing to change, really configVersion = "1.8.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.8.0")); } if (configVersion.startsWith("1.8.0~beta1") || configVersion.startsWith("1.8.0~beta2")) { qDebug() << "Upgrading from v1.8.0~beta..."; // Upgrade tasks go here configVersion = "1.8.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.8.0")); } if (configVersion.startsWith("1.8") || configVersion.startsWith("1.9.0beta1")) { qDebug() << "Upgrading from" << configVersion << "..."; // Upgrade tasks go here #ifdef __APPLE__ QString OSXLocation180 = QDir::homePath().append("/").append(".mixxx"); QString OSXLocation190 = settingsPath; QDir newOSXDir(OSXLocation190); newOSXDir.mkpath(OSXLocation190); QList<QPair<QString, QString> > dirsToMove; dirsToMove.push_back(QPair<QString, QString>(OSXLocation180, OSXLocation190)); dirsToMove.push_back(QPair<QString, QString>(OSXLocation180 + "/midi", OSXLocation190 + "midi")); dirsToMove.push_back(QPair<QString, QString>(OSXLocation180 + "/presets", OSXLocation190 + "presets")); QListIterator<QPair<QString, QString> > dirIt(dirsToMove); QPair<QString, QString> curPair; while (dirIt.hasNext()) { curPair = dirIt.next(); qDebug() << "Moving" << curPair.first << "to" << curPair.second; QDir oldSubDir(curPair.first); QDir newSubDir(curPair.second); newSubDir.mkpath(curPair.second); //Create the new destination directory QStringList contents = oldSubDir.entryList(QDir::Files | QDir::NoDotAndDotDot); QStringListIterator it(contents); QString cur; //Iterate over all the files in the source directory and copy them to the dest dir. while (it.hasNext()) { cur = it.next(); QString src = curPair.first + "/" + cur; QString dest = curPair.second + "/" + cur; qDebug() << "Copying" << src << "to" << dest; if (!QFile::copy(src, dest)) { qDebug() << "Failed to move file during upgrade."; } } //Rename the old directory. newOSXDir.rename(OSXLocation180, OSXLocation180 + "-1.8"); } //Reload the configuration file from the new location. //(We want to make sure we save to the new location...) config = new ConfigObject<ConfigValue>(settingsPath + SETTINGS_FILE); #endif configVersion = "1.9.0"; config->set(ConfigKey("[Config]","Version"), ConfigValue("1.9.0")); } if (configVersion.startsWith("1.9") || configVersion.startsWith("1.10")) { qDebug() << "Upgrading from v1.9.x/1.10.x..."; bool successful = true; qDebug() << "Copying midi/ to controllers/"; QString midiPath = legacyUserPresetsPath(config); QString controllerPath = userPresetsPath(config); QDir oldDir(midiPath); QDir newDir(controllerPath); newDir.mkpath(controllerPath); // create the new directory QStringList contents = oldDir.entryList(QDir::Files | QDir::NoDotAndDotDot); QStringListIterator it(contents); QString cur; //Iterate over all the files in the source directory and copy them to the dest dir. while (it.hasNext()) { cur = it.next(); if (newDir.exists(cur)) { qDebug() << cur << "already exists in" << controllerPath << "Skipping."; continue; } QString src = oldDir.absoluteFilePath(cur); QString dest = newDir.absoluteFilePath(cur); qDebug() << "Copying" << src << "to" << dest; if (!QFile::copy(src, dest)) { qDebug() << "Failed to copy file during upgrade."; successful = false; } } bool reanalyze_choice = askReanalyzeBeats(); config->set(ConfigKey(BPM_CONFIG_KEY, BPM_REANALYZE_WHEN_SETTINGS_CHANGE), ConfigValue(reanalyze_choice)); if (successful) { qDebug() << "Upgrade Successful"; configVersion = "1.11.0"; m_bUpgraded = true; config->set(ConfigKey("[Config]","Version"), ConfigValue(configVersion)); } else { qDebug() << "Upgrade Failed"; } } if (configVersion.startsWith("1.11")) { qDebug() << "Upgrading from v1.11.x..."; // upgrade to the multi library folder settings QString currentFolder = config->getValueString(PREF_LEGACY_LIBRARY_DIR); // to migrate the DB just add the current directory to the new // directories table TrackCollection tc(config); DirectoryDAO directoryDAO = tc.getDirectoryDAO(); // NOTE(rryan): We don't have to ask for sandbox permission to this // directory because the normal startup integrity check in Library will // notice if we don't have permission and ask for access. Also, the // Sandbox isn't setup yet at this point in startup because it relies on // the config settings path and this function is what loads the config // so it's not ready yet. bool successful = directoryDAO.addDirectory(currentFolder); // ask for library rescan to activate cover art. We can later ask for // this variable when the library scanner is constructed. m_bRescanLibrary = askReScanLibrary(); // if everything until here worked fine we can mark the configuration as // updated if (successful) { configVersion = VERSION; m_bUpgraded = true; config->set(ConfigKey("[Config]","Version"), ConfigValue(VERSION)); } else { qDebug() << "Upgrade failed!\n"; } } if (configVersion == VERSION) qDebug() << "Configuration file is now at the current version" << VERSION; else { /* Way too verbose, this confuses the hell out of Linux users when they see this: qWarning() << "Configuration file is at version" << configVersion << "and I don't know how to upgrade it to the current" << VERSION << "\n (That means a function to do this needs to be added to upgrade.cpp.)" << "\n-> Leaving the configuration file version as-is."; */ qWarning() << "Configuration file is at version" << configVersion << "instead of the current" << VERSION; } return config; }
QScriptValue DirPrototype::temp() const { return newDir(QDir::temp()); }
void K3bDataUrlAddingDialog::slotAddUrls() { if( m_bCanceled ) return; // add next url KURL url = m_urlQueue.first().first; K3bDirItem* dir = m_urlQueue.first().second; m_urlQueue.remove( m_urlQueue.begin() ); // // HINT: // we only use QFileInfo::absFilePath() and QFileInfo::isHidden() // both do not cause QFileInfo to stat, thus no speed improvement // can come from removing QFileInfo usage here. // QFileInfo info(url.path()); QString absFilePath( info.absFilePath() ); QString resolved( absFilePath ); bool valid = true; k3b_struct_stat statBuf, resolvedStatBuf; bool isSymLink = false; bool isDir = false; bool isFile = false; ++m_filesHandled; #if 0 m_infoLabel->setText( url.path() ); if( m_totalFiles == 0 ) m_counterLabel->setText( QString("(%1)").arg(m_filesHandled) ); else m_counterLabel->setText( QString("(%1/%2)").arg(m_filesHandled).arg(m_totalFiles) ); #endif // // 1. Check if we want and can add the url // if( !url.isLocalFile() ) { valid = false; m_nonLocalFiles.append( url.path() ); } else if( k3b_lstat( QFile::encodeName(absFilePath), &statBuf ) != 0 ) { valid = false; m_notFoundFiles.append( url.path() ); } else if( !m_encodingConverter->encodedLocally( QFile::encodeName( url.path() ) ) ) { valid = false; m_invalidFilenameEncodingFiles.append( url.path() ); } else { isSymLink = S_ISLNK(statBuf.st_mode); isFile = S_ISREG(statBuf.st_mode); isDir = S_ISDIR(statBuf.st_mode); // symlinks are always readable and can always be added to a project // but we need to know if the symlink points to a directory if( isSymLink ) { resolved = K3b::resolveLink( absFilePath ); k3b_stat( QFile::encodeName(resolved), &resolvedStatBuf ); isDir = S_ISDIR(resolvedStatBuf.st_mode); } else { if( ::access( QFile::encodeName( absFilePath ), R_OK ) != 0 ) { valid = false; m_unreadableFiles.append( url.path() ); } else if( isFile && (unsigned long long)statBuf.st_size >= 0xFFFFFFFFULL ) { if ( !k3bcore->externalBinManager()->binObject( "mkisofs" )->hasFeature( "no-4gb-limit" ) ) { valid = false; m_tooBigFiles.append( url.path() ); } } } // FIXME: if we do not add hidden dirs the progress gets messed up! // // check for hidden and system files // if( valid ) { if( info.isHidden() && !addHiddenFiles() ) valid = false; if( S_ISCHR(statBuf.st_mode) || S_ISBLK(statBuf.st_mode) || S_ISFIFO(statBuf.st_mode) || S_ISSOCK(statBuf.st_mode) ) if( !addSystemFiles() ) valid = false; if( isSymLink ) if( S_ISCHR(resolvedStatBuf.st_mode) || S_ISBLK(resolvedStatBuf.st_mode) || S_ISFIFO(resolvedStatBuf.st_mode) || S_ISSOCK(resolvedStatBuf.st_mode) ) if( !addSystemFiles() ) valid = false; } } // // 2. Handle the url // QString newName = url.fileName(); // filenames cannot end in backslashes (mkisofs problem. See comments in k3bisoimager.cpp (escapeGraftPoint())) bool bsAtEnd = false; while( newName[newName.length()-1] == '\\' ) { newName.truncate( newName.length()-1 ); bsAtEnd = true; } if( bsAtEnd ) m_mkisofsLimitationRenamedFiles.append( url.path() + " -> " + newName ); // backup dummy name if( newName.isEmpty() ) newName = "1"; K3bDirItem* newDirItem = 0; // // The source is valid. Now check if the project already contains a file with that name // and if so handle it properly // if( valid ) { if( K3bDataItem* oldItem = dir->find( newName ) ) { // // reuse an existing dir // if( oldItem->isDir() && isDir ) newDirItem = dynamic_cast<K3bDirItem*>(oldItem); // // we cannot replace files in the old session with dirs and vice versa (I think) // files are handled in K3bFileItem constructor and dirs handled above // else if( oldItem->isFromOldSession() && isDir != oldItem->isDir() ) { if( !getNewName( newName, dir, newName ) ) valid = false; } else if( m_bExistingItemsIgnoreAll ) valid = false; else if( oldItem->localPath() == resolved ) { // // Just ignore if the same file is added again // valid = false; } else if( m_bExistingItemsReplaceAll ) { // if we replace an item from an old session the K3bFileItem constructor takes care // of replacing the item if( !oldItem->isFromOldSession() ) delete oldItem; } // // Let the user choose // else { switch( K3bMultiChoiceDialog::choose( i18n("File already exists"), i18n("<p>File <em>%1</em> already exists in " "project folder <em>%2</em>.") .arg(newName) .arg('/' + dir->k3bPath()), QMessageBox::Warning, this, 0, 6, KGuiItem( i18n("Replace"), QString::null, i18n("Replace the existing file") ), KGuiItem( i18n("Replace All"), QString::null, i18n("Always replace existing files") ), KGuiItem( i18n("Ignore"), QString::null, i18n("Keep the existing file") ), KGuiItem( i18n("Ignore All"), QString::null, i18n("Always keep the existing file") ), KGuiItem( i18n("Rename"), QString::null, i18n("Rename the new file") ), KStdGuiItem::cancel() ) ) { case 2: // replace all m_bExistingItemsReplaceAll = true; // fallthrough case 1: // replace // if we replace an item from an old session the K3bFileItem constructor takes care // of replacing the item if( !oldItem->isFromOldSession() ) delete oldItem; break; case 4: // ignore all m_bExistingItemsIgnoreAll = true; // fallthrough case 3: // ignore valid = false; break; case 5: // rename if( !getNewName( newName, dir, newName ) ) valid = false; break; case 6: // cancel slotCancel(); return; } } } } // // One more thing to warn the user about: We cannot follow links to folders since that // would change the doc. So we simply ask the user what to do with a link to a folder // if( valid ) { // let's see if this link starts a loop // that means if it points to some folder above this one // if so we cannot follow it anyway if( isDir && isSymLink && !absFilePath.startsWith( resolved ) ) { bool followLink = dir->doc()->isoOptions().followSymbolicLinks() || m_bFolderLinksFollowAll; if( !followLink && !m_bFolderLinksAddAll ) { switch( K3bMultiChoiceDialog::choose( i18n("Adding link to folder"), i18n("<p>'%1' is a symbolic link to folder '%2'." "<p>If you intend to make K3b follow symbolic links you should consider letting K3b do this now " "since K3b will not be able to do so afterwards because symbolic links to folders inside a " "K3b project cannot be resolved." "<p><b>If you do not intend to enable the option <em>follow symbolic links</em> you may safely " "ignore this warning and choose to add the link to the project.</b>") .arg(absFilePath) .arg(resolved ), QMessageBox::Warning, this, 0, 5, i18n("Follow link now"), i18n("Always follow links"), i18n("Add link to project"), i18n("Always add links"), KStdGuiItem::cancel() ) ) { case 2: m_bFolderLinksFollowAll = true; case 1: followLink = true; break; case 4: m_bFolderLinksAddAll = true; case 3: followLink = false; break; case 5: slotCancel(); return; } } if( followLink ) { absFilePath = resolved; isSymLink = false; // count the files in the followed dir if( m_dirSizeJob->active() ) m_dirSizeQueue.append( KURL::fromPathOrURL(absFilePath) ); else { m_progressWidget->setTotalSteps( 0 ); m_dirSizeJob->setUrls( KURL::fromPathOrURL(absFilePath) ); m_dirSizeJob->start(); } } } } // // Project valid also (we overwrite or renamed) // now create the new item // if( valid ) { // // Set the volume id from the first added url // only if the doc was not changed yet // if( m_urls.count() == 1 && !dir->doc()->isModified() && !dir->doc()->isSaved() ) { dir->doc()->setVolumeID( K3b::removeFilenameExtension( newName ) ); } if( isDir && !isSymLink ) { if( !newDirItem ) { // maybe we reuse an already existing dir newDirItem = new K3bDirItem( newName , dir->doc(), dir ); newDirItem->setLocalPath( url.path() ); // HACK: see k3bdiritem.h } QDir newDir( absFilePath ); int dirFilter = QDir::All|QDir::Hidden|QDir::System; QStringList dlist = newDir.entryList( dirFilter ); const QString& dot = KGlobal::staticQString( "." ); const QString& dotdot = KGlobal::staticQString( ".." ); dlist.remove( dot ); dlist.remove( dotdot ); for( QStringList::Iterator it = dlist.begin(); it != dlist.end(); ++it ) { m_urlQueue.append( qMakePair( KURL::fromPathOrURL(absFilePath + '/' + *it), newDirItem ) ); } } else { (void)new K3bFileItem( &statBuf, &resolvedStatBuf, url.path(), dir->doc(), dir, newName ); } } if( m_urlQueue.isEmpty() ) { m_dirSizeJob->cancel(); m_progressWidget->setProgress( 100 ); accept(); } else { updateProgress(); QTimer::singleShot( 0, this, SLOT(slotAddUrls()) ); } }
void RecoMuonValHistoPublisher(char* newFile="NEW_FILE",char* refFile="REF_FILE") { //gROOT->ProcessLine(".x HistoCompare_Tracks.C"); gROOT ->Reset(); gROOT ->SetBatch(); //========= settings ==================== char* dataType = "DATATYPE"; gROOT->SetStyle("Plain"); gStyle->SetPadGridX(kTRUE); gStyle->SetPadGridY(kTRUE); gStyle->SetPadRightMargin(0.07); gStyle->SetPadLeftMargin(0.13); //gStyle->SetTitleXSize(0.07); //gStyle->SetTitleXOffset(0.6); //tyle->SetTitleYSize(0.3); //gStyle->SetLabelSize(0.6) //gStyle->SetTextSize(0.5); char* refLabel("REF_LABEL, REF_RELEASE REFSELECTION"); char* newLabel("NEW_LABEL, NEW_RELEASE NEWSELECTION"); Float_t maxPT=1500.; char* fastSim = "IS_FSIM"; //============================================= delete gROOT->GetListOfFiles()->FindObject(refFile); delete gROOT->GetListOfFiles()->FindObject(newFile); //INPUT FILE IS DEFINED HERE, passed from python wrapper TText* te = new TText(); TFile * sfile = new TFile(newFile); TDirectory * sdir=gDirectory; TFile * rfile = new TFile(refFile); TDirectory * rdir=gDirectory; //check datatype if (dataType == "RECO") { if(sfile->cd("DQMData/Run 1/Muons/Run summary")) {;} else { cout << " Muon Histos for " << dataType << " not found" << endl; return; } } else { cout << " Data type " << dataType << " not allowed: only RECO is considered" << endl; return; } sdir=gDirectory; TIter nextkey( sdir->GetListOfKeys() ); TList *sl = new TList(); TKey *key, *oldkey=0; cout << "- New DQM muon reco collections: " << endl; while ( key = (TKey*)nextkey() ) { TObject *obj = key->ReadObj(); if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) { TString theName = obj->GetName(); if (theName.Contains("RecoMuonV")) { cout << " -> " << theName << endl; sl->Add(obj); } } } if (sl->GetSize()>0) { TString collname2 =sl->At(0)->GetName(); } else { cout << " No DQM muon reco histos found in NEW file " << endl; return; } if (dataType == "RECO") { if(rfile->cd("DQMData/Run 1/Muons/Run summary")) {;} else { cout << " Muon Histos for " << dataType << " not found" << endl; return; } } rdir=gDirectory; TIter nextkeyr( rdir->GetListOfKeys() ); TList *rl = new TList(); TKey *keyr, *oldkeyr=0; cout << "- Ref DQM muon reco collections: " << endl; while ( keyr = (TKey*)nextkeyr() ) { TObject *obj = keyr->ReadObj(); if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) { TString theName = obj->GetName(); if (theName.Contains("RecoMuonV")) { cout << " -> " << theName << endl; rl->Add(obj); } } } if (rl->GetSize()>0) { TString collname1=rl->At(0)->GetName(); } else { cout << " No DQM muon reco histos found in REF file " << endl; return; } TCanvas *canvas; TH1F *sh1,*rh1; TH1F *sh2,*rh2; TH1F *sh3,*rh3; TH1F *sh4,*rh4; TH1F *sh5,*rh5; TH1F *sh6,*rh6; TIter iter_r( rl ); TIter iter_s( sl ); TKey * myKey1, *myKey2; while ( (myKey1 = (TKey*)iter_r()) ) { TString myName = myKey1->GetName(); collname1 = myName; myKey2 = (TKey*)iter_s(); if (!myKey2) continue; collname2 = myKey2->GetName(); if ( (collname1 != collname2) && (collname1+"FS" != collname2) && (collname1 != collname2+"FS") ) { cout << " Different collection names, please check: " << collname1 << " : " << collname2 << endl; continue; } TString newDir("NEW_RELEASE/NEWSELECTION/NEW_LABEL/"); newDir+=myName; gSystem->mkdir(newDir,kTRUE); //rh1 = 0; //sh1 = 0; //===== For each monitored type as defined in muonValidation_cff.py //===== reco muon distributions: GLB rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt",rh1); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt",sh1); rh1->GetYaxis()->SetTitle("GlobalMuon(GLB) #Delta p_{T}/p_{T}"); rh1->GetYaxis()->SetTitleSize(0.05); rh1->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrP",rh2); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrP",sh2); rh2->GetYaxis()->SetTitle("GlobalMuon(GLB) #Delta p/p"); rh2->GetYaxis()->SetTitleSize(0.05); rh2->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Eta_Sigma",rh3); if (!rh3) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)rh3); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Eta_Sigma",sh3); if (!sh3) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)sh3); rh3->GetYaxis()->SetTitle("GlobalMuon(GLB) #Delta p_{T}/p_{T} vs #sigma(#eta)"); rh3->GetYaxis()->SetTitleSize(0.05); rh3->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Pt_Sigma",rh4); if (!rh4) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)rh4); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Pt_Sigma",sh4); if (!sh4) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)sh4); rh4->GetYaxis()->SetTitle("GlobalMuon(GLB) #Delta p_{T}/p_{T} vs #sigma(p_{T})"); rh4->GetYaxis()->SetTitleSize(0.05); rh4->GetYaxis()->SetTitleOffset(1.2); canvas = new TCanvas("RecHistosGlb","Distributions for GlobalMuons (GLB)",1000,1050); // Normalize to the same number of "new" events: NormalizeHistograms(rh1,sh1); NormalizeHistograms(rh2,sh2); plot4histos(canvas, sh1,rh1,sh2,rh2, sh3,rh3,sh4,rh4, te,"UU",-1); canvas->cd(); l = new TLegend(0.20,0.48,0.90,0.53); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); canvas->Print(newDir+"/muonRecoGlb.pdf"); delete l; delete canvas; //==== efficiencies and fractions GLB rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/EffP",rh1); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/EffP",sh1); //if(! rh1 && sh1) continue; rh1->GetYaxis()->SetTitle("GlobalMuon(GLB) #epsilon vs. p"); rh1->GetYaxis()->SetTitleSize(0.05); rh1->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/EffEta",rh2); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/EffEta",sh2); rh2->GetYaxis()->SetTitle("GlobalMuon(GLB) #epsilon vs. #eta"); rh2->GetYaxis()->SetTitleSize(0.05); rh2->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/FractP",rh3); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/FractP",sh3); rh3->GetYaxis()->SetTitle("GlobalMuon(GLB) fraction vs. p"); rh3->GetYaxis()->SetTitleSize(0.05); rh3->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/FractEta",rh4); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Glb"+fastSim+"/FractEta",sh4); rh4->GetYaxis()->SetTitle("GlobalMuon(GLB) fraction vs. #eta"); rh4->GetYaxis()->SetTitleSize(0.05); rh4->GetYaxis()->SetTitleOffset(1.2); canvas = new TCanvas("RecEffHistosGlb","Distributions for GlobalMuons (GLB), efficiencies and fractions",1000,1050); plot4histos(canvas, sh1,rh1,sh2,rh2, sh3,rh3,sh4,rh4, te,"UU",-1); canvas->cd(); l = new TLegend(0.20,0.48,0.90,0.53); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); canvas->Print(newDir+"/muonRecoGlbEff.pdf"); delete l; delete canvas; //===== reco muon distributions: GLBPF rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt",rh1); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt",sh1); // if(! rh1 && sh1) continue; rh1->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #Delta p_{T}/p_{T}"); rh1->GetYaxis()->SetTitleSize(0.05); rh1->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrP",rh2); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrP",sh2); rh2->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #Delta p/p"); rh2->GetYaxis()->SetTitleSize(0.05); rh2->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Eta_Sigma",rh3); if (!rh3) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)rh3); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Eta_Sigma",sh3); if (!sh3) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)sh3); rh3->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #Delta p_{T}/p_{T} vs #sigma(#eta)"); rh3->GetYaxis()->SetTitleSize(0.05); rh3->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Pt_Sigma",rh4); if (!rh4) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)rh4); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Pt_Sigma",sh4); if (!sh4) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)sh4); rh4->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #Delta p_{T}/p_{T} vs #sigma(p_{T})"); rh4->GetYaxis()->SetTitleSize(0.05); rh4->GetYaxis()->SetTitleOffset(1.2); canvas = new TCanvas("RecHistosGlbPF","Distributions for PFGlobalMuons (GLBPF)",1000,1050); // Normalize to the same number of "new" events: NormalizeHistograms(rh1,sh1); NormalizeHistograms(rh2,sh2); plot4histos(canvas, sh1,rh1,sh2,rh2, sh3,rh3,sh4,rh4, te,"UU",-1); canvas->cd(); l = new TLegend(0.20,0.48,0.90,0.53); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); canvas->Print(newDir+"/muonRecoGlbPF.pdf"); delete l; delete canvas; //==== efficiencies and fractions GLBPF rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/EffP",rh1); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/EffP",sh1); //if(! rh1 && sh1) continue; rh1->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #epsilon vs. p"); rh1->GetYaxis()->SetTitleSize(0.05); rh1->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/EffEta",rh2); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/EffEta",sh2); rh2->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) #epsilon vs. #eta"); rh2->GetYaxis()->SetTitleSize(0.05); rh2->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/FractP",rh3); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/FractP",sh3); rh3->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) fraction vs. p"); rh3->GetYaxis()->SetTitleSize(0.05); rh3->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/FractEta",rh4); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_GlbPF"+fastSim+"/FractEta",sh4); rh4->GetYaxis()->SetTitle("PFGlobalMuon(GLBPF) fraction vs. #eta"); rh4->GetYaxis()->SetTitleSize(0.05); rh4->GetYaxis()->SetTitleOffset(1.2); canvas = new TCanvas("RecEffHistosGlbPF","Distributions for PFGlobalMuons (GLBPF), efficiencies and fractions",1000,1050); plot4histos(canvas, sh1,rh1,sh2,rh2, sh3,rh3,sh4,rh4, te,"UU",-1); canvas->cd(); l = new TLegend(0.20,0.48,0.90,0.53); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); canvas->Print(newDir+"/muonRecoGlbPFEff.pdf"); delete l; delete canvas; //===== reco muon distributions: STA rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt",rh1); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt",sh1); // if(! rh1 && sh1) continue; rh1->GetYaxis()->SetTitle("StandAloneMuon(STA) #Delta p_{T}/p_{T}"); rh1->GetYaxis()->SetTitleSize(0.05); rh1->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrP",rh2); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrP",sh2); rh2->GetYaxis()->SetTitle("StandAloneMuon(STA) #Delta p/p"); rh2->GetYaxis()->SetTitleSize(0.05); rh2->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Eta_Sigma",rh3); if (!rh3) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)rh3); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Eta_Sigma",sh3); if (!sh3) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)sh3); rh3->GetYaxis()->SetTitle("StandAloneMuon(STA) #Delta p_{T}/p_{T} vs #sigma(#eta)"); rh3->GetYaxis()->SetTitleSize(0.05); rh3->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Pt_Sigma",rh4); if (!rh4) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)rh4); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Pt_Sigma",sh4); if (!sh4) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)sh4); rh4->GetYaxis()->SetTitle("StandAloneMuon(STA) #Delta p_{T}/p_{T} vs #sigma(p_{T})"); rh4->GetYaxis()->SetTitleSize(0.05); rh4->GetYaxis()->SetTitleOffset(1.2); canvas = new TCanvas("RecHistosSta","Distributions for StandAloneMuons (STA)",1000,1050); // Normalize to the same number of "new" events: NormalizeHistograms(rh1,sh1); NormalizeHistograms(rh2,sh2); plot4histos(canvas, sh1,rh1,sh2,rh2, sh3,rh3,sh4,rh4, te,"UU",-1); canvas->cd(); l = new TLegend(0.20,0.48,0.90,0.53); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); canvas->Print(newDir+"/muonRecoSta.pdf"); delete l; delete canvas; //==== efficiencies and fractions STA rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/EffP",rh1); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/EffP",sh1); // if(! rh1 && sh1) continue; rh1->GetYaxis()->SetTitle("StandAloneMuon(STA) #epsilon vs. p"); rh1->GetYaxis()->SetTitleSize(0.05); rh1->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/EffEta",rh2); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/EffEta",sh2); rh2->GetYaxis()->SetTitle("StandAloneMuon(STA) #epsilon vs. #eta"); rh2->GetYaxis()->SetTitleSize(0.05); rh2->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/FractP",rh3); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/FractP",sh3); rh3->GetYaxis()->SetTitle("StandAloneMuon(STA) fraction vs. p"); rh3->GetYaxis()->SetTitleSize(0.05); rh3->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/FractEta",rh4); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Sta"+fastSim+"/FractEta",sh4); rh4->GetYaxis()->SetTitle("StandAloneMuon(STA) fraction vs. #eta"); rh4->GetYaxis()->SetTitleSize(0.05); rh4->GetYaxis()->SetTitleOffset(1.2); canvas = new TCanvas("RecEffHistosSta","Distributions for StandAloneMuons (STA), efficiencies and fractions",1000,1050); plot4histos(canvas, sh1,rh1,sh2,rh2, sh3,rh3,sh4,rh4, te,"UU",-1); canvas->cd(); l = new TLegend(0.20,0.48,0.90,0.53); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); canvas->Print(newDir+"/muonRecoStaEff.pdf"); delete l; delete canvas; //===== reco muon distributions: TRK rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt",rh1); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt",sh1); // if(! rh1 && sh1) continue; rh1->GetYaxis()->SetTitle("TrackerMuon(TRK) #Delta p_{T}/p_{T}"); rh1->GetYaxis()->SetTitleSize(0.05); rh1->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrP",rh2); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrP",sh2); rh2->GetYaxis()->SetTitle("TrackerMuon(TRK) #Delta p/p"); rh2->GetYaxis()->SetTitleSize(0.05); rh2->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Eta_Sigma",rh3); if (!rh3) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)rh3); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Eta_Sigma",sh3); if (!sh3) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)sh3); rh3->GetYaxis()->SetTitle("TrackerMuon(TRK) #Delta p_{T}/p_{T} vs #sigma(#eta)"); rh3->GetYaxis()->SetTitleSize(0.05); rh3->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Pt_Sigma",rh4); if (!rh4) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)rh4); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Pt_Sigma",sh4); if (!sh4) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)sh4); rh4->GetYaxis()->SetTitle("TrackerMuon(TRK) #Delta p_{T}/p_{T} vs #sigma(p_{T})"); rh4->GetYaxis()->SetTitleSize(0.05); rh4->GetYaxis()->SetTitleOffset(1.2); canvas = new TCanvas("RecHistosTrk","Distributions for TrackerMuons (TRK)",1000,1050); // Normalize to the same number of "new" events: NormalizeHistograms(rh1,sh1); NormalizeHistograms(rh2,sh2); plot4histos(canvas, sh1,rh1,sh2,rh2, sh3,rh3,sh4,rh4, te,"UU",-1); canvas->cd(); l = new TLegend(0.20,0.48,0.90,0.53); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); canvas->Print(newDir+"/muonRecoTrk.pdf"); delete l; delete canvas; //==== efficiencies and fractions TRK rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/EffP",rh1); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/EffP",sh1); // if(! rh1 && sh1) continue; rh1->GetYaxis()->SetTitle("TrackerMuon(TRK) #epsilon vs. p"); rh1->GetYaxis()->SetTitleSize(0.05); rh1->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/EffEta",rh2); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/EffEta",sh2); rh2->GetYaxis()->SetTitle("TrackerMuon(TRK) #epsilon vs. #eta"); rh2->GetYaxis()->SetTitleSize(0.05); rh2->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/FractP",rh3); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/FractP",sh3); rh3->GetYaxis()->SetTitle("TrackerMuon(TRK) fraction vs. p"); rh3->GetYaxis()->SetTitleSize(0.05); rh3->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/FractEta",rh4); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Trk"+fastSim+"/FractEta",sh4); rh4->GetYaxis()->SetTitle("TrackerMuon(TRK) fraction vs. #eta"); rh4->GetYaxis()->SetTitleSize(0.05); rh4->GetYaxis()->SetTitleOffset(1.2); canvas = new TCanvas("RecEffHistosTrk","Distributions for TrackerMuons (TRK), efficiencies and fractions",1000,1050); plot4histos(canvas, sh1,rh1,sh2,rh2, sh3,rh3,sh4,rh4, te,"UU",-1); canvas->cd(); l = new TLegend(0.20,0.48,0.90,0.53); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); canvas->Print(newDir+"/muonRecoTrkEff.pdf"); delete l; delete canvas; // //===== reco muon distributions: Tight Muons // rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt",rh1); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt",sh1); // if(! rh1 && sh1) continue; rh1->GetYaxis()->SetTitle("Tight Muon #Delta p_{T}/p_{T}"); rh1->GetYaxis()->SetTitleSize(0.05); rh1->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrP",rh2); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrP",sh2); rh2->GetYaxis()->SetTitle("Tight Muon #Delta p/p"); rh2->GetYaxis()->SetTitleSize(0.05); rh2->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Eta_Sigma",rh3); if (!rh3) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)rh3); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Eta_Sigma",sh3); if (!sh3) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Eta_Sigma",(TProfile*)sh3); rh3->GetYaxis()->SetTitle("Tight Muon #Delta p_{T}/p_{T} vs #sigma(#eta)"); rh3->GetYaxis()->SetTitleSize(0.05); rh3->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Pt_Sigma",rh4); if (!rh4) rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)rh4); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Pt_Sigma",sh4); if (!sh4) sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/ErrPt_vs_Pt_Sigma",(TProfile*)sh4); rh4->GetYaxis()->SetTitle("Tigh Muon) #Delta p_{T}/p_{T} vs #sigma(p_{T})"); rh4->GetYaxis()->SetTitleSize(0.05); rh4->GetYaxis()->SetTitleOffset(1.2); canvas = new TCanvas("RecHistosTgt","Distributions for Tight Muons",1000,1050); // Normalize to the same number of "new" events: NormalizeHistograms(rh1,sh1); NormalizeHistograms(rh2,sh2); plot4histos(canvas, sh1,rh1,sh2,rh2, sh3,rh3,sh4,rh4, te,"UU",-1); canvas->cd(); l = new TLegend(0.20,0.48,0.90,0.53); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); canvas->Print(newDir+"/muonRecoTgt.pdf"); delete l; delete canvas; //==== efficiencies and fractions Tight Muons rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/EffP",rh1); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/EffP",sh1); // if(! rh1 && sh1) continue; rh1->GetYaxis()->SetTitle("Tight Muon #epsilon vs. p"); rh1->GetYaxis()->SetTitleSize(0.05); rh1->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/EffEta",rh2); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/EffEta",sh2); rh2->GetYaxis()->SetTitle("Tight Muon #epsilon vs. #eta"); rh2->GetYaxis()->SetTitleSize(0.05); rh2->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/FractP",rh3); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/FractP",sh3); rh3->GetYaxis()->SetTitle("Tight Muon fraction vs. p"); rh3->GetYaxis()->SetTitleSize(0.05); rh3->GetYaxis()->SetTitleOffset(1.2); rdir->GetObject(collname1+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/FractEta",rh4); sdir->GetObject(collname2+"/RecoMuon_MuonAssoc_Tgt"+fastSim+"/FractEta",sh4); rh4->GetYaxis()->SetTitle("Tight Muon fraction vs. #eta"); rh4->GetYaxis()->SetTitleSize(0.05); rh4->GetYaxis()->SetTitleOffset(1.2); canvas = new TCanvas("RecEffHistosTgt","Distributions for Tight Muons, efficiencies and fractions",1000,1050); plot4histos(canvas, sh1,rh1,sh2,rh2, sh3,rh3,sh4,rh4, te,"UU",-1); canvas->cd(); l = new TLegend(0.20,0.48,0.90,0.53); l->SetTextSize(0.016); l->SetLineColor(1); l->SetLineWidth(1); l->SetLineStyle(1); l->SetFillColor(0); l->SetBorderSize(3); l->AddEntry(rh1,refLabel,"LPF"); l->AddEntry(sh1,newLabel,"LPF"); l->Draw(); canvas->Print(newDir+"/muonRecoTgtEff.pdf"); delete l; delete canvas; // // Merge pdf histograms together into larger files, and name them based on the collection names // gSystem->Exec("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf " +newDir+"/muonRecoGlb.pdf " +newDir+"/muonRecoGlbEff.pdf " +newDir+"/muonRecoGlbPF.pdf " +newDir+"/muonRecoGlbPFEff.pdf " +newDir+"/muonRecoSta.pdf " +newDir+"/muonRecoStaEff.pdf " +newDir+"/muonRecoTrk.pdf " +newDir+"/muonRecoTrkEff.pdf " +newDir+"/muonRecoTgt.pdf " +newDir+"/muonRecoTgtEff.pdf "); gSystem->Exec("mv merged.pdf "+newDir+"/../"+myName+".pdf"); gSystem->Exec("rm -r "+newDir); } // end of "while loop" }
void Optimization::createSubExecs(QList<QList<ModModelPlus*> > & subModels, QList<BlockSubstitutions*> & subBlocks) { subModels.clear(); subBlocks.clear(); QMultiMap<QString,QString> map; // <orgComponent,subcomponent> QMap<QString,QString> mapModel; //<orgComponent,model> // fill map for(int i=0; i < _blockSubstitutions->getSize();i++) { BlockSubstitution *curBlockSub = _blockSubstitutions->getAt(i); if(!curBlockSub->_subComponent.isEmpty()) { map.insert(curBlockSub->_orgComponent,curBlockSub->_subComponent); mapModel.insert(curBlockSub->_orgComponent,curBlockSub->_model); } } int nbOrgs = map.uniqueKeys().size(); //adding non-moving cases for each orgComponent for(int i = 0; i<nbOrgs; i ++) { map.insert(map.uniqueKeys().at(i),map.uniqueKeys().at(i)); } //build first index and maximum index QList<int> index, maxIndex; nbOrgs = map.uniqueKeys().size(); for(int i = 0; i<nbOrgs; i ++) { index.push_back(0); QList<QString> subs = map.values(map.uniqueKeys().at(i)); maxIndex.push_back(subs.size()-1); } QStringList models = mapModel.values(); models.removeDuplicates(); // storing genuine mo file paths QStringList oldMoFilePaths; for(int iM=0;iM<models.size();iM++) { oldMoFilePaths.push_back(_omProject->modModelPlus(models.at(iM))->moFilePath()); } int iCase=0; bool oneChange; while(!index.isEmpty()) { // Display case (for debug) QString msg = "CASE " + QString::number(iCase) + "\n"; for(int i=0; i < index.size(); i++) { msg += map.uniqueKeys().at(i); msg += " -> "; msg += map.values(map.uniqueKeys().at(i)).at(index.at(i)); msg+=","; } msg.remove(msg.size()-1,1); msg +="\n \n"; InfoSender::instance()->debug(msg); // create folder QString newName = "case_"+QString::number(iCase); QString newFolder = saveFolder()+ QDir::separator() + "SubModels" + QDir::separator() + newName; QDir dir(saveFolder()); dir.mkpath(newFolder); QDir newDir(newFolder); // clone mo files and load them // and create corresponding modmodelplus QStringList newMoPaths; QStringList newMmoPaths; QMap<QString,ModModelPlus*> newModModels; for(int iM=0;iM<oldMoFilePaths.size();iM++) { QFileInfo oldMoFileInfo(oldMoFilePaths.at(iM)); QFile oldMoFile(oldMoFilePaths.at(iM)); QString newMoPath = newDir.filePath(oldMoFileInfo.fileName()); QString newMmoPath = newMoPath; newMmoPath = newMmoPath.replace(".mo",".mmo"); newDir.remove(newMoPath); oldMoFile.copy(newMoPath); newMoPaths.append(newMoPath); newMmoPaths.append(newMmoPath); // load file (! will replace previously loaded) _omProject->loadMoFile(newMoPath,false,true); // create new modModelPlus ModModelPlus* newModModelPlus = new ModModelPlus(_omProject,models.at(iM)); newModModelPlus->setMmoFilePath(newMmoPath); newModModels.insert(models.at(iM),newModModelPlus); } // apply blocksubs BlockSubstitutions *curSubBlocks = new BlockSubstitutions(); QMap<QString,bool> changes; // <model,hasChanged> changes.clear(); for(int i=0; i<index.size();i++) { QString replacedComp = map.uniqueKeys().at(i); QString replacingComp = map.values(map.uniqueKeys().at(i)).at(index.at(i)); if(replacedComp != replacingComp) { BlockSubstitution* blockSub = _blockSubstitutions->find(replacedComp,replacingComp); if(blockSub) { ModModelPlus* corrNewModModelPlus = newModModels.value(blockSub->_model); oneChange = corrNewModModelPlus->applyBlockSub(blockSub,true) || oneChange ; curSubBlocks->push_back(blockSub); changes.insert(blockSub->_model,true); } } } QStringList modelsToCompile = changes.keys(true);// those which have been modified bool compilationOk = true; for(int iM=0;iM<modelsToCompile.size();iM++) { ModModelPlus* modelPlus = newModModels.value(modelsToCompile.at(iM)); compilationOk = modelPlus->compile(ctrl(modelsToCompile.at(iM))) && compilationOk; } if(compilationOk) { // store subModel and subBlocks subModels.push_back(newModModels.values()); subBlocks.push_back(curSubBlocks); _foldersToCopy << newFolder; InfoSender::instance()->send( Info(ListInfo::SUBMODELADDED,newName)); } else { InfoSender::instance()->send( Info(ListInfo::SUBMODELNOTADDED,newName)); } iCase++; index = LowTools::nextIndex(index,maxIndex); } // reload genuine mo file if(iCase>0) { for(int i=0;i<oldMoFilePaths.size();i++) _omProject->loadMoFile(oldMoFilePaths.at(i),false,true); } }
void RecoMuonValHistoPublisher(const char* newFile="NEW_FILE",const char* refFile="REF_FILE") { cout << ">> Starting RecoMuonValHistoPublisher(" << newFile << "," << refFile << ")..." << endl; //==== To be replaced from python ==================== const char* dataType = "DATATYPE"; const char* refLabel("REF_LABEL, REF_RELEASE REFSELECTION"); const char* newLabel("NEW_LABEL, NEW_RELEASE NEWSELECTION"); const char* fastSim = "IS_FSIM"; // ==== Initial settings and loads //gROOT->ProcessLine(".x HistoCompare_Tracks.C"); //gROOT ->Reset(); gROOT ->SetBatch(); gErrorIgnoreLevel = kWarning; // Get rid of the info messages SetGlobalStyle(); // ==== Some cleaning... is this needed? delete gROOT->GetListOfFiles()->FindObject(refFile); delete gROOT->GetListOfFiles()->FindObject(newFile); // ==== Opening files, moving to the right branch and getting the list of sub-branches cout << ">> Openning file, moving to the right branch and getting sub-branches..." << endl; cout << ">> Finding sources..." << endl; TFile* sfile = new TFile(newFile); TList* sl = getListOfBranches(dataType, sfile, "RecoMuonV"); if (!sl) { cout << "ERROR: Could not find keys!!!" << endl; cerr << "ERROR: Could not find keys!!!" << endl; return; } TDirectory* sdir = gDirectory; for (unsigned int i = 0; i < sl->GetEntries(); i++) cout << " + " << sl->At(i)->GetName() << endl; cout << ">> Finding references..." << endl; TFile* rfile = new TFile(refFile); TList* rl = getListOfBranches(dataType, rfile, "RecoMuonV"); if (!rl) { cout << "ERROR: Could not find keys!!!" << endl; cerr << "ERROR: Could not find keys!!!" << endl; return; } TDirectory* rdir = gDirectory; for (unsigned int i = 0; i < sl->GetEntries(); i++) cout << " + " << sl->At(i)->GetName() << endl; Float_t maxPT; TString File = newFile; if (File.Contains("SingleMuPt1000") ||File.Contains("WpM")||File.Contains("ZpMM") ) maxPT=1400.; else if(File.Contains("SingleMuPt10")) {maxPT = 70.;} else if (File.Contains("SingleMuPt100")) {maxPT = 400.;} else maxPT = 400.; TIter iter_r( rl ); TIter iter_s( sl ); TKey* rKey = 0; TKey* sKey = 0; TString rcollname; TString scollname; while ( (rKey = (TKey*)iter_r()) ) { TString myName = rKey->GetName(); #ifdef DEBUG cout << "DEBUG: Checking key " << myName << endl; #endif rcollname = myName; sKey = (TKey*)iter_s(); if (!sKey) continue; scollname = sKey->GetName(); if ( (rcollname != scollname) && (rcollname+"FS" != scollname) && (rcollname != scollname+"FS") ) { cerr << "ERROR: Different collection names, please check: " << rcollname << " : " << scollname << endl; cout << "ERROR: Different collection names, please check: " << rcollname << " : " << scollname << endl; continue; } // ==== Now let's go for the plotting... cout << ">> Comparing plots in " << myName << "..." << endl; cerr << ">> Comparing plots in " << myName << "..." << endl; TString newDir("NEW_RELEASE/NEWSELECTION/NEW_LABEL/"); newDir+=myName; gSystem->mkdir(newDir,kTRUE); bool resolx = false; bool *resol = &resolx; bool logy [] = {false, false, false, false }; bool doKolmo [] = {true, true, true, true }; Double_t minx [] = {-1E100, -1E100, -1E100, 5., -1E100, -1E100 }; Double_t maxx [] = {-1E100, -1E100,-1E100, maxPT, -1E100, -1E100 }; Double_t norm [] = {0.,0.,-999.,-999.,0.,0.}; //Normalize to first histogram //===== reco muon distributions: GLB //TString baseh = Form("RecoMuon_MuonAssoc_Glb%s/",fastSim); const char* plots1[] = {"RecoMuon_MuonAssoc_Glb/ErrPt", "RecoMuon_MuonAssoc_Glb/ErrP", "RecoMuon_MuonAssoc_Glb/ErrPt_vs_Eta_Sigma", "RecoMuon_MuonAssoc_Glb/ErrPt_vs_Pt_Sigma"}; const char* plotst1[] = {"GlobalMuon(GLB) #Delta p_{T}/p_{T}", "GlobalMuon(GLB) #Delta p/p", "GlobalMuon(GLB) #Delta p_{T}/p_{T} vs #sigma(#eta)", "GlobalMuon(GLB) #Delta p_{T}/p_{T} vs #sigma(p_{T})"}; Plot4Histograms(newDir + "/muonRecoGlb.pdf", rdir, sdir, rcollname, scollname, "RecHistosGlb", "Distributions for GlobalMuons (GLB)", refLabel, newLabel, plots1, plotst1, logy, doKolmo, norm,resol,minx,maxx); //==== efficiencies and fractions GLB const char* plots2 [] = {"RecoMuon_MuonAssoc_Glb/EffP", "RecoMuon_MuonAssoc_Glb/EffEta", "RecoMuon_MuonAssoc_Glb/FractP", "RecoMuon_MuonAssoc_Glb/FractEta"}; const char* plotst2[] = {"GlobalMuon(GLB) #epsilon vs. p", "GlobalMuon(GLB) #epsilon vs. #eta", "GlobalMuon(GLB) fraction vs. p", "GlobalMuon(GLB) fraction vs. #eta"}; Double_t minx1 [] = {5., -1E100, 5., -1E100, -1E100, -1E100 }; Double_t maxx1 [] = {maxPT, -1E100,maxPT, -1E100, -1E100, -1E100 }; Double_t norm2 [] = {-999.,-999.,-999.,-999.,-999.,-999.}; //Normalize to first histogram Plot4Histograms(newDir + "/muonRecoGlbEff.pdf", rdir, sdir, rcollname, scollname, "RecEffHistosGlb", "Distributions for GlobalMuons (GLB), efficiencies and fractions", refLabel, newLabel, plots2, plotst2, logy, doKolmo,norm2,resol,minx1,maxx1); /* //===== reco muon distributions: GLBPF baseh = Form("RecoMuon_MuonAssoc_GlbPF%s/",fastSim); const char* plots3[] = {(baseh + "ErrPt").Data(), (baseh + "ErrP").Data(), (baseh + "ErrPt_vs_Eta_Sigma").Data(), (baseh + "ErrPt_vs_Pt_Sigma").Data()}; const char* plotst3[] = {"PFGlobalMuon(GLBPF) #Delta p_{T}/p_{T}", "PFGlobalMuon(GLBPF) #Delta p/p", "PFGlobalMuon(GLBPF) #Delta p_{T}/p_{T} vs #sigma(#eta)", "PFGlobalMuon(GLBPF) #Delta p_{T}/p_{T} vs #sigma(p_{T})"}; Plot4Histograms(newDir + "/muonRecoGlbPF.pdf", rdir, sdir, rcollname, scollname, "RecHistosGlbPF", "Distributions for PFGlobalMuons (GLBPF)", refLabel, newLabel, plots3, plotst3, logy, doKolmo, norm); //==== efficiencies and fractions GLBPF const char* plots4 [] = {(baseh + "EffP").Data(), (baseh + "EffEta").Data(), (baseh + "FractP").Data(), (baseh + "FractEta").Data()}; const char* plotst4[] = {"PFGlobalMuon(GLBPF) #epsilon vs. p", "PFGlobalMuon(GLBPF) #epsilon vs. #eta", "PFGlobalMuon(GLBPF) fraction vs. p", "PFGlobalMuon(GLBPF) fraction vs. #eta"}; Plot4Histograms(newDir + "/muonRecoGlbPFEff.pdf", rdir, sdir, rcollname, scollname, "RecEffHistosGlbPF", "Distributions for PFGlobalMuons (GLBPF), efficiencies and fractions", refLabel, newLabel, plots4, plotst4, logy, doKolmo, norm); */ //===== reco muon distributions: STA //baseh = Form("RecoMuon_MuonAssoc_Sta%s/",fastSim); const char* plots5 [] = {"RecoMuon_MuonAssoc_Sta/ErrPt", "RecoMuon_MuonAssoc_Sta/ErrP", "RecoMuon_MuonAssoc_Sta/ErrPt_vs_Eta_Sigma", "RecoMuon_MuonAssoc_Sta/ErrPt_vs_Pt_Sigma"}; const char* plotst5[] = {"StandAloneMuon(STA) #Delta p_{T}/p_{T}", "StandAloneMuon(STA) #Delta p/p", "StandAloneMuon(STA) #Delta p_{T}/p_{T} vs #sigma(#eta)", "StandAloneMuon(STA) #Delta p_{T}/p_{T} vs #sigma(p_{T})"}; Plot4Histograms(newDir + "/muonRecoSta.pdf", rdir, sdir, rcollname, scollname, "RecHistosSta", "Distributions for StandAloneMuons (STA)", refLabel, newLabel, plots5, plotst5, logy, doKolmo, norm,resol, minx,maxx); //==== efficiencies and fractions STA const char* plots6 [] = {"RecoMuon_MuonAssoc_Sta/EffP", "RecoMuon_MuonAssoc_Sta/EffEta", "RecoMuon_MuonAssoc_Sta/FractP", "RecoMuon_MuonAssoc_Sta/FractEta"}; const char* plotst6[] = {"StandAloneMuon(STA) #epsilon vs. p", "StandAloneMuon(STA) #epsilon vs. #eta", "StandAloneMuon(STA) fraction vs. p", "StandAloneMuon(STA) fraction vs. #eta"}; Plot4Histograms(newDir + "/muonRecoStaEff.pdf", rdir, sdir, rcollname, scollname, "RecEffHistosSta", "Distributions for StandAloneMuons (STA), efficiencies and fractions", refLabel, newLabel, plots6, plotst6, logy, doKolmo, norm2,resol,minx1,maxx1); //===== reco muon distributions: TRK //baseh = Form("RecoMuon_MuonAssoc_Trk%s/",fastSim); const char* plots7 [] = {"RecoMuon_MuonAssoc_Trk/ErrPt", "RecoMuon_MuonAssoc_Trk/ErrP", "RecoMuon_MuonAssoc_Trk/ErrPt_vs_Eta_Sigma", "RecoMuon_MuonAssoc_Trk/ErrPt_vs_Pt_Sigma"}; const char* plotst7[] = {"TrackerMuon(TRK) #Delta p_{T}/p_{T}", "TrackerMuon(TRK) #Delta p/p", "TrackerMuon(TRK) #Delta p_{T}/p_{T} vs #sigma(#eta)", "TrackerMuon(TRK) #Delta p_{T}/p_{T} vs #sigma(p_{T})"}; Plot4Histograms(newDir + "/muonRecoTrk.pdf", rdir, sdir, rcollname, scollname, "RecHistosTrk", "Distributions for TrackerMuons (TRK)", refLabel, newLabel, plots7, plotst7, logy, doKolmo, norm,resol,minx,maxx); //==== efficiencies and fractions TRK const char* plots8 [] = {"RecoMuon_MuonAssoc_Trk/EffP", "RecoMuon_MuonAssoc_Trk/EffEta", "RecoMuon_MuonAssoc_Trk/FractP", "RecoMuon_MuonAssoc_Trk/FractEta"}; const char* plotst8[] = {"TrackerMuon(TRK) #epsilon vs. p", "TrackerMuon(TRK) #epsilon vs. #eta", "TrackerMuon(TRK) fraction vs. p", "TrackerMuon(TRK) fraction vs. #eta"}; Plot4Histograms(newDir + "/muonRecoTrkEff.pdf", rdir, sdir, rcollname, scollname, "RecEffHistosTrk", "Distributions for TrackerMuons (TRK), efficiencies and fractions", refLabel, newLabel, plots8, plotst8, logy, doKolmo, norm2,resol,minx1,maxx1); // //===== reco muon distributions: Tight Muons // //baseh = Form("RecoMuon_MuonAssoc_Tgt%s/",fastSim); const char* plots9 [] = {"RecoMuon_MuonAssoc_Tgt/ErrPt", "RecoMuon_MuonAssoc_Tgt/ErrP", "RecoMuon_MuonAssoc_Tgt/ErrPt_vs_Eta_Sigma", "RecoMuon_MuonAssoc_Tgt/ErrPt_vs_Pt_Sigma"}; const char* plotst9[] = {"Tight Muon #Delta p_{T}/p_{T}", "Tight Muon #Delta p/p", "Tight Muon #Delta p_{T}/p_{T} vs #sigma(#eta)", "Tight Muon #Delta p_{T}/p_{T} vs #sigma(p_{T})"}; Plot4Histograms(newDir + "/muonRecoTgt.pdf", rdir, sdir, rcollname, scollname, "RecHistosTgt", "Distributions for Tight Muons", refLabel, newLabel, plots9, plotst9, logy, doKolmo, norm,resol,minx,maxx); //==== efficiencies and fractions Tight Muons const char* plots10 [] = {"RecoMuon_MuonAssoc_Tgt/EffP", "RecoMuon_MuonAssoc_Tgt/EffEta", "RecoMuon_MuonAssoc_Tgt/FractP", "RecoMuon_MuonAssoc_Tgt/FractEta"}; const char* plotst10[] = {"Tight Muon #epsilon vs. p", "Tight Muon #epsilon vs. #eta", "Tight Muon fraction vs. p", "Tight Muon fraction vs. #eta"}; Plot4Histograms(newDir + "/muonRecoTgtEff.pdf", rdir, sdir, rcollname, scollname, "RecEffHistosTgt", "Distributions for Tight Muons, efficiencies and fractions", refLabel, newLabel, plots10, plotst10, logy, doKolmo, norm2,resol,minx1,maxx1); // // Merge pdf histograms together into larger files, and name them based on the collection names // TString mergefile = "merged_recomuonval.pdf"; // File name where partial pdfs will be merged TString destfile = newDir + "/../" + myName + ".pdf"; // Destination file name TString gscommand = "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="+ mergefile + " " +newDir+"/muonRecoGlb.pdf " +newDir+"/muonRecoGlbEff.pdf " // +newDir+"/muonRecoGlbPF.pdf " // +newDir+"/muonRecoGlbPFEff.pdf " +newDir+"/muonRecoSta.pdf " +newDir+"/muonRecoStaEff.pdf " +newDir+"/muonRecoTrk.pdf " +newDir+"/muonRecoTrkEff.pdf " +newDir+"/muonRecoTgt.pdf " +newDir+"/muonRecoTgtEff.pdf "; cout << ">> Merging partial pdfs to " << mergefile << "..." << endl; #ifdef DEBUG cout << "DEBUG: ...with command \"" << gscommand << "\"" << endl; #endif gSystem->Exec(gscommand); cout << ">> Moving " << mergefile << " to " << destfile << "..." << endl; gSystem->Rename(mergefile, destfile); cout << " ... Done" << endl; cout << ">> Deleting partial pdf files" << endl; gSystem->Exec("rm -r "+newDir); } // end of "while loop" cout << ">> Removing the relval files from ROOT before closing..." << endl; gROOT->GetListOfFiles()->Remove(sfile); gROOT->GetListOfFiles()->Remove(rfile); #ifdef DEBUG cout << "DEBUG: Exiting!" << endl; cerr << "DEBUG: Exiting!" << endl; #endif }
void Postprocessing_UpdateRainyGlassStep(float deltaTime) { rain->time += deltaTime; const float dropletSpeed = 0.7f; const float dropletMinSpawnSize = 0.01f; const float dropletMaxSpawnSize = 0.02f; const float dropletMaxSize = 0.05f; const float newDirPercentage = 0.2f; const float minNextChangeTime = 0.05f; const float maxNextChangeTime = 0.5f; std::vector<RainyGlass::Droplet>& droplets = rain->droplets; // Kill old droplets for (unsigned int i = 0; i < droplets.size(); ) { RainyGlass::Droplet& d = droplets[i]; if (d.pos.y > 1.0f + d.size * 0.5f) { d = droplets.back(); droplets.pop_back(); } else i++; } // Spawn new droplets if (rain->time - rain->lastSpawnTime > rain->spawnFrequency && droplets.size() < rain->maxDroplets) { rain->lastSpawnTime = rain->time; RainyGlass::Droplet& d = vector_add(droplets); d.size = Random::GetFloat(dropletMinSpawnSize, dropletMaxSpawnSize); d.pos.Set(Random::GetFloat(0, 1), 0 - d.size); d.velocity.Set(Random::GetFloat(-0.4f, 0.0f), Random::GetFloat(1.0f, 1.0f)); d.velocity.Normalize(); d.velocity *= dropletSpeed * (d.size / dropletMaxSize); d.nextVelocityChangeTime = rain->time + Random::GetFloat(minNextChangeTime, maxNextChangeTime); } // Update existing droplets std::vector<RainyGlass::Droplet>::iterator dropletsEnd = droplets.end(); for (std::vector<RainyGlass::Droplet>::iterator it = droplets.begin(); it != dropletsEnd; ++it) { if (it->nextVelocityChangeTime <= rain->time) { Vec2 newDir(Random::GetFloat(-1, 1), Random::GetFloat(0.5f, 1.0f)); newDir.Normalize(); it->velocity.Normalize(); it->velocity = Vec2::Lerp(it->velocity, newDir, newDirPercentage); it->velocity.Normalize(); it->velocity *= dropletSpeed * (it->size / dropletMaxSize); it->nextVelocityChangeTime = rain->time + Random::GetFloat(minNextChangeTime, maxNextChangeTime); } it->pos += it->velocity * deltaTime; } rain->rainEvaporation += deltaTime; }
void TrackValHistoPublisher(const char* newFile="NEW_FILE",const char* refFile="REF_FILE") { cout << ">> Starting TrackValHistoPublisher(" << newFile << "," << refFile << ")..." << endl; //==== To be replaced from python ==================== const char* dataType = "DATATYPE"; const char* refLabel("REF_LABEL, REF_RELEASE REFSELECTION"); const char* newLabel("NEW_LABEL, NEW_RELEASE NEWSELECTION"); // ==== Initial settings and loads //gROOT->ProcessLine(".x HistoCompare_Tracks.C"); //gROOT ->Reset(); gROOT ->SetBatch(); gErrorIgnoreLevel = kWarning; // Get rid of the info messages SetGlobalStyle(); Float_t maxPT; TString File = newFile; if (File.Contains("SingleMuPt1000") ||File.Contains("WpM")||File.Contains("ZpMM") ) maxPT=1400.; else if (File.Contains("SingleMuPt100")) {maxPT = 400.;} else if(File.Contains("SingleMuPt10")) {maxPT = 70.;} else maxPT = 400.; bool ctf=1; bool resol = false; // ==== Some cleaning... is this needed? delete gROOT->GetListOfFiles()->FindObject(refFile); delete gROOT->GetListOfFiles()->FindObject(newFile); // ==== Opening files, moving to the right branch and getting the list of sub-branches cout << ">> Openning file, moving to the right branch and getting sub-branches..." << endl; cout << ">> Finding sources..." << endl; TFile * sfile = new TFile(newFile); TList* sl = GetListOfBranches(dataType, sfile); if (!sl) { cout << "ERROR: Could not find keys!!!" << endl; cerr << "ERROR: Could not find keys!!!" << endl; return; } TDirectory* sdir = gDirectory; for (unsigned int i = 0; i < sl->GetEntries(); i++) cout << " + " << sl->At(i)->GetName() << endl; cout << ">> Finding references..." << endl; TFile * rfile = new TFile(refFile); TList* rl = GetListOfBranches(dataType, rfile); if (!rl) { cout << "ERROR: Could not find keys!!!" << endl; cerr << "ERROR: Could not find keys!!!" << endl; return; } TDirectory* rdir = gDirectory; for (unsigned int i = 0; i < sl->GetEntries(); i++) cout << " + " << sl->At(i)->GetName() << endl; //==== Find if the collection has muon associator or track associator cout << ">> Find if the collection has muon associator or track associator..." << endl; bool hasOnlyMuonAssociatorInRef = true; bool hasOnlyMuonAssociatorInSig = true; bool hasOnlyTrackAssociatorInRef = true; bool hasOnlyTrackAssociatorInSig = true; TIter iter_r0( rl ); TIter iter_s0( sl ); TKey* rKey = 0; TKey* sKey = 0; /*while ( (rKey = (TKey*)iter_r0()) ) { TString myName = rKey->GetName(); if ( !(myName.Contains("TkAsso")) && !(myName.Contains("MuonAssociation")) ) { hasOnlyMuonAssociatorInRef = false; } if ( !(myName.Contains("TkAsso")) && (myName.Contains("MuonAssociation")) ) { hasOnlyTrackAssociatorInRef = false; } } while ( (sKey = (TKey*)iter_s0()) ) { TString myName = sKey->GetName(); if ( !(myName.Contains("TkAsso")) && !(myName.Contains("MuonAssociation")) ) { hasOnlyMuonAssociatorInSig = false; } if ( !(myName.Contains("TkAsso")) && (myName.Contains("MuonAssociation")) ) { hasOnlyTrackAssociatorInSig = false; } } */ bool considerOnlyMuonAssociator = hasOnlyMuonAssociatorInRef || hasOnlyMuonAssociatorInSig; cout << " + Has Only Muon Associator (reference): " << hasOnlyMuonAssociatorInRef << endl; cout << " + Has Only Muon Associator (signal): " << hasOnlyMuonAssociatorInSig << endl; cout << " + Has Only Track Associator (reference): " << hasOnlyTrackAssociatorInRef << endl; cout << " + Has Only Track Associator (signal): " << hasOnlyTrackAssociatorInSig << endl; cout << " + Consider only Muon Associator: " << considerOnlyMuonAssociator << endl; //==== Iterate now over histograms and collections cout << ">> Iterating over histograms and collections..." << endl; TIter iter_r( rl ); TIter iter_s( sl ); TString scollname; TString rcollname; TKey *myNext2=0; while ( (rKey = (TKey*)iter_r()) ) { TString myName = rKey->GetName(); #ifdef DEBUG cout << "DEBUG: Checking key " << myName << endl; #endif /* if (!(myName.Contains("TkAsso")) && considerOnlyMuonAssociator && hasOnlyTrackAssociatorInRef) { if (myName.Contains("TrackAssociation")) myName.ReplaceAll("TrackAssociation","MuonAssociation"); else myName.ReplaceAll("Association","MuonAssociation"); } while (considerOnlyMuonAssociator && !(myName.Contains("TkAsso")) && !(myName.Contains("MuonAssociation")) ) { rKey = (TKey*)iter_r(); myName = rKey->GetName(); }*/ rcollname = myName; // ==> extractedGlobalMuons are in a different position wrt globalMuons: if (myNext2) { sKey = myNext2; myNext2 = 0; } else { sKey = (TKey*)iter_s(); } if (!sKey) continue; TString myName2 = sKey->GetName(); /* this was thought for when there are different names */ if (myName2 != myName) { myNext2 = (TKey*)iter_s(); TKey* myTemp = sKey; sKey = myNext2; myName2 = sKey->GetName(); myNext2 = myTemp; if(myName2 != myName) {myNext2 = (TKey*)iter_s(); TKey* myTemp = sKey; sKey = myNext2; myName2 = sKey->GetName(); myNext2 = myTemp; } } scollname=myName2; #ifdef DEBUG cout << "DEBUG: Comparing " << rcollname << " and " << scollname << endl; #endif if ( (myName == myName2) || (myName+"FS" == myName2) || (myName == myName2+"FS" ) || (myName.Contains("extractedGlobalMuons") && myName2.Contains("globalMuons") ) || (myName.Contains("globalMuons") && myName2.Contains("extractedGlobalMuons") ) ) { rcollname = rKey->GetName(); scollname = sKey->GetName(); } else if ( (rcollname != scollname) && (rcollname+"FS" != scollname) && (rcollname != scollname+"FS") ) { bool goodAsWell = false; if (rcollname.BeginsWith("StandAloneMuons_UpdAtVtx") && scollname.BeginsWith("StandAloneMuons_UpdAtVtx")) { if (rcollname.Contains("MuonAssociation")==scollname.Contains("MuonAssociation")){} goodAsWell = true; } if (rcollname.BeginsWith("hltL2Muons_UpdAtVtx") && scollname.BeginsWith("hltL2Muons_UpdAtVtx")) { if (rcollname.Contains("MuonAssociation")==scollname.Contains("MuonAssociation")){} goodAsWell = true; } if (rcollname.BeginsWith("hltL3Tk") && scollname.BeginsWith("hltL3Tk")) { if (rcollname.Contains("MuonAssociation")==scollname.Contains("MuonAssociation")){} goodAsWell = true; } // TString isGood = (goodAsWell? "good": "NOT good"); // cout << " -- The two collections: " << rcollname << " : " << scollname << " -> " << isGood << endl; if (! goodAsWell) { if (rcollname.Contains("SET") && !scollname.Contains("SET")) { while (rcollname.Contains("SET")) { if ((rKey = (TKey*)iter_r())) rcollname = rKey->GetName(); } } else if (scollname.Contains("SET") && !rcollname.Contains("SET")) { while (scollname.Contains("SET")) { if ((sKey = (TKey*)iter_s())) scollname = sKey->GetName(); } } if (rcollname.Contains("dyt") && !scollname.Contains("dyt")) { while (rcollname.Contains("dyt")) { if ((rKey = (TKey*)iter_r())) rcollname = rKey->GetName(); } } else if (scollname.Contains("dyt") && !rcollname.Contains("dyt")) { while (scollname.Contains("dyt")) { if ((sKey = (TKey*)iter_s())) scollname = sKey->GetName(); } } if (rcollname.Contains("refitted") && !scollname.Contains("refitted")) { while (rcollname.Contains("refitted")) { if ((rKey = (TKey*)iter_r())) rcollname = rKey->GetName(); } } else if (scollname.Contains("refitted") && !rcollname.Contains("refitted")) { while (scollname.Contains("refitted")) { if ((sKey = (TKey*)iter_s())) scollname = sKey->GetName(); } } if ( (rcollname != scollname) && (rcollname+"FS" != scollname) && (rcollname != scollname+"FS") ) { cout << " Different collection names, please check: " << rcollname << " : " << scollname << endl; continue; } else { // cout << " The NEW collections: " << rcollname << " : " << scollname << endl; myName = rKey->GetName(); } } } // ==== Now let's go for the plotting... // cout << ">> Comparing plots in " << myName << "..." << endl; //cerr << ">> Comparing plots in " << myName << "..." << endl; TString newDir("NEW_RELEASE/NEWSELECTION/NEW_LABEL/"); newDir+=myName; gSystem->mkdir(newDir,kTRUE); bool logyfalse [] = {false, false, false, false, false, false }; bool doKolmo [] = {true, true, true, true, true, true }; Double_t norm [] = {-999.,-999.,-999.,-999.,-999.,-999.}; Double_t minx [] = {-1E100, -1E100, 5., 5., -1E100, -1E100 }; Double_t maxx [] = {-1E100, -1E100, maxPT, maxPT, -1E100, -1E100 }; Double_t miny [] = {0.5, -1E100, 0, -1E100, 0.5, -1E100 }; Double_t maxy [] = {1.0125, -1E100, 1.025, -1E100, 1.0125, -1E100 }; ////////////////////////////////////// /////////// CTF ////////////////////// ////////////////////////////////////// if (ctf) { //===== building const char* plots0[] = {"effic", "fakerate", "efficPt", "fakeratePt"}; const char* plotsl0[] = {"efficiency vs #eta", "fakerate vs #eta", "efficiency vs Pt", "fakerate vs Pt"}; bool logy0 [] = {false, false, false, false }; Plot4Histograms(newDir + "/building.pdf", rdir, sdir, rcollname, scollname, "Seeds", "Efficiency Vs Pt and Vs #eta", refLabel, newLabel, plots0, plotsl0, logy0, doKolmo, norm,0,minx,maxx,miny,maxy); cout<<"HICE EL HISTO "<<endl; const char* plots1[] = { "effic_vs_hit", "fakerate_vs_hit","effic_vs_phi","fakerate_vs_phi"}; const char* plotsl1[] = { "efficiency vs hits", "fakerate vs hits","efficiency vs #phi","fakerate vs #phi"}; bool logy [] = {false, false, false, false }; Plot4Histograms(newDir + "/building2.pdf", rdir, sdir, rcollname, scollname, "Seeds2", "Efficiency vs hits and #phi", refLabel, newLabel, plots1, plotsl1, logy, doKolmo, norm, 0,minx,maxx,miny,maxy); cout<<"HICE EL HISTO "<<endl; // ====== hits and pt const char* plots2 [] = { "hits_eta", "hits", "num_simul_pT","num_reco_pT"}; const char* plotsl2 [] = { "nhits vs eta", "number of hits per track", "Number of Pt Simulated","Pt of Reco tracks"}; Double_t norm2 [] = {0.,0.,0.,0.,0.,0.}; // Double_t minx2 [] = {-1E100, -1E100, 0, 0, -1E100, -1E100 }; // Double_t maxx2 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; // Double_t miny2 [] = {0.5, -1E100, 0., -1E100, 0.5, -1E100 }; // Double_t maxy2 [] = {1.0125, -1E100, -1E100, -1E100, -1E100, -1E100 }; Plot4Histograms(newDir + "/hitsAndPt.pdf", rdir, sdir, rcollname, scollname, "hits", "Pt", refLabel, newLabel, plots2, plotsl2, logyfalse, doKolmo, norm2,0,minx,maxx); //===== tuning bool logy3 [] = {false, true, false, true }; bool doKolmo3 [] = {true, true, true, true }; const char* plots3 [] = {"chi2","chi2_prob","chi2mean", "ptres_vs_eta_Mean"}; Plot4Histograms(newDir + "/tuning.pdf", rdir, sdir, rcollname, scollname, "IsoHistos2", "HCAL, HO Deposits", refLabel, newLabel, plots3, 0, logy3, doKolmo3,norm2,0); //===== pulls const char* plots4 [] = {"pullPt", "pullQoverp", "pullPhi", "pullTheta", "pullDxy","pullDz"}; const char* plotsl4 [] = {"Pt Pull", "Q/P Pull", "#Phi Pull", "#theta Pull", "Dxy Pull","Dz Pull"}; // Double_t minx4 [] = {-10, -10, -10, -10, -10, -10 }; // Double_t maxx4 [] = {10,10,10, 10, 10, 10 }; // Double_t miny4 [] = {0., -1E100, 0., -1E100, 0, -1E100 }; // Double_t maxy4 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; Plot6Histograms(newDir + "/Pulls.pdf", rdir, sdir, rcollname, scollname, "Pullsdis", "Pull Distributions", refLabel, newLabel, plots4, plotsl4, logyfalse, doKolmo, norm2,0); //===== residuals const char* plots5 [] = {"ptres_vs_eta", "etares_vs_eta", "phires_vs_eta", "cotThetares_vs_eta", "dxyres_vs_eta","dzres_vs_eta"}; const char* plotsl5 [] = {"p_{t} resolution", "#eta resolution", "#Phi resolution", "cot(#theta) resolution", "Dxy resolution","Dz resolution"}; // Double_t minx5 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; // Double_t maxx5 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; // Double_t miny5 [] = {0., -1E100, 0., -1E100, 0, -1E100 }; // Double_t maxy5 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; resol= true; Plot6Histograms(newDir + "/residuals.pdf", rdir, sdir, rcollname, scollname, "residualdis", "residuals vs Pt", refLabel, newLabel, plots5, plotsl5, logyfalse, doKolmo, norm2,&resol); //===== resolutions vs eta const char* plots6 [] = {"phires_vs_eta_Sigma", "cotThetares_vs_eta_Sigma", "dxyres_vs_eta_Sigma", "dzres_vs_eta_Sigma", "ptres_vs_eta_Sigma"}; const char* plotsl6 [] = {"#sigma(#delta #phi) [rad]", "#sigma(#delta cot(#theta))", "#sigma(#delta d_{0}) [cm]", "#sigma(#delta z_{0}) [cm]", "#sigma(#delta p_{t}/p_{t})"}; // Double_t minx6 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; // Double_t maxx6 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; // Double_t miny6 [] = {0., -1E100, 0., -1E100, 0, -1E100 }; // Double_t maxy6 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; Plot5Histograms(newDir + "/residualsEta.pdf", rdir, sdir, rcollname, scollname, "residualsdisEta", "residuals vs Eta", refLabel, newLabel, plots6, plotsl6, logyfalse, doKolmo, norm,0); // //===== mean values vs eta const char* plots7 [] = {"phires_vs_eta_Mean", "cotThetares_vs_eta_Mean", "dxyres_vs_eta_Mean", "dzres_vs_eta_Mean", "ptres_vs_eta_Mean"}; const char* plotsl7 [] = {"#delta #phi [rad]", "#delta cot(#theta)", "#delta d_{0} [cm]", "#delta z_{0} [cm]", "#delta p_{t}/p_{t}"}; // Double_t minx7 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; // Double_t maxx7 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; // Double_t miny7 [] = {0., -1E100, 0., -1E100, 0, -1E100 }; // Double_t maxy7 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; Plot5Histograms(newDir + "/meanvaluesEta.pdf", rdir, sdir, rcollname, scollname, "meanvaluesEtadis", "mean values vs eta", refLabel, newLabel, plots7, plotsl7, logyfalse, doKolmo,norm,0); // //===== resolutions vs pt // const char* plots8 [] = {"phires_vs_pt_Sigma", "cotThetares_vs_pt_Sigma", "dxyres_vs_pt_Sigma", "dzres_vs_pt_Sigma", "ptres_vs_pt_Sigma","ptres_vs_pt_Sigma"}; const char* plotsl8 [] = {"#sigma(#delta #phi) [rad]", "#sigma(#delta cot(#theta))", "#sigma(#delta d_{0}) [cm]", "#sigma(#delta z_{0}) [cm]", "#sigma(#delta p_{t}/p_{t})"}; Double_t minx8 [] = {5., 5., 5., 5., 5., 5.}; Double_t maxx8 [] = {maxPT,maxPT,maxPT,maxPT,maxPT,maxPT}; // Double_t miny8 [] = {0., -1E100, 0., -1E100, 0, -1E100 }; // Double_t maxy8 [] = {-1E100, -1E100, -1E100, -1E100, -1E100, -1E100 }; Plot5Histograms(newDir + "/resolutionsPt.pdf", rdir, sdir, rcollname, scollname, "resolutionsPtdis", "resolution vs pt", refLabel, newLabel, plots8, plotsl8, logyfalse, doKolmo, norm,0,minx8,maxx8); } // end of "if CTF" //// Merge pdf histograms together into larger files, and name them based on the collection names TString mergefile = "merged_tracks.pdf"; // File name where partial pdfs will be merged TString destfile = newDir + "/../" + myName + ".pdf"; // Destination file name TString gscommand = "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=" + mergefile + " " + newDir + "/building.pdf " + newDir + "/building2.pdf " + newDir + "/hitsAndPt.pdf " + newDir + "/tuning.pdf " + newDir + "/Pulls.pdf " + newDir + "/residuals.pdf " + newDir + "/residualsEta.pdf " + newDir + "/meanvaluesEta.pdf " + newDir + "/resolutionsPt.pdf "; cout << ">> Merging partial pdfs to " << mergefile << "..." << endl; #ifdef DEBUG cout << "DEBUG: ...with command \"" << gscommand << "\"" << endl; #endif gSystem->Exec(gscommand); cout << ">> Moving " << mergefile << " to " << destfile << "..." << endl; gSystem->Rename(mergefile, destfile); cout << ">> Deleting partial pdf files" << endl; gSystem->Exec("rm -rf "+newDir); cout << " ... Done" << endl; } // end of "while loop" cout << ">> Removing the relval files from ROOT before closing..." << endl; gROOT->GetListOfFiles()->Remove(sfile); gROOT->GetListOfFiles()->Remove(rfile); #ifdef DEBUG cout << "DEBUG: Exiting!" << endl; cerr << "DEBUG: Exiting!" << endl; #endif }
Desktopwidget::Desktopwidget (QWidget *parent) : QSplitter (parent) { _model = new Dirmodel (); // _model->setLazyChildCount (true); _dir = new Dirview (this); _dir->setModel (_model); _contents = new Desktopmodel (this); QWidget *group = createToolbar(); _view = new Desktopview (group); QVBoxLayout *lay = new QVBoxLayout (group); lay->setContentsMargins (0, 0, 0, 0); lay->setSpacing (2); lay->addWidget (_toolbar); lay->addWidget (_view); connect (_view, SIGNAL (itemPreview (const QModelIndex &, int, bool)), this, SLOT (slotItemPreview (const QModelIndex &, int, bool))); #ifdef USE_PROXY _proxy = new Desktopproxy (this); _proxy->setSourceModel (_contents); _view->setModel (_proxy); // printf ("contents=%p, proxy=%p\n", _contents, _proxy); // set up the model converter _modelconv = new Desktopmodelconv (_contents, _proxy); // setup another one for Desktopmodel, which only allows assertions _modelconv_assert = new Desktopmodelconv (_contents, _proxy, false); #else _proxy = 0; _view->setModel (_contents); _modelconv = new Desktopmodelconv (_contents); // setup another one for Desktopmodel, which only allows assertions _modelconv_assert = new Desktopmodelconv (_contents, false); #endif _view->setModelConv (_modelconv); _contents->setModelConv (_modelconv_assert); _delegate = new Desktopdelegate (_modelconv, this); _view->setItemDelegate (_delegate); connect (_delegate, SIGNAL (itemClicked (const QModelIndex &, int)), this, SLOT (slotItemClicked (const QModelIndex &, int))); connect (_delegate, SIGNAL (itemPreview (const QModelIndex &, int, bool)), this, SLOT (slotItemPreview (const QModelIndex &, int, bool))); connect (_delegate, SIGNAL (itemDoubleClicked (const QModelIndex &)), this, SLOT (openStack (const QModelIndex &))); connect (_contents, SIGNAL (undoChanged ()), this, SIGNAL (undoChanged ())); connect (_contents, SIGNAL (dirChanged (QString&, QModelIndex&)), this, SLOT (slotDirChanged (QString&, QModelIndex&))); connect (_contents, SIGNAL (beginningScan (const QModelIndex &)), this, SLOT (slotBeginningScan (const QModelIndex &))); connect (_contents, SIGNAL (endingScan (bool)), this, SLOT (slotEndingScan (bool))); connect (_contents, SIGNAL(updateRepositoryList (QString &, bool)), this, SLOT(slotUpdateRepositoryList (QString &, bool))); // position the items when the model is reset, otherwise things // move and look ugly for a while connect (_contents, SIGNAL (modelReset ()), _view, SLOT (setPositions ())); createPage(); // and when there are no selected items connect (_view, SIGNAL (pageLost()), _page, SLOT (slotReset ())); _parent = parent; _pendingMatch = QString::null; _updating = false; // setup the preview timer _timer = new QTimer (); _timer->setSingleShot (true); connect (_timer, SIGNAL(timeout()), this, SLOT(updatePreview())); connect (_dir, SIGNAL (clicked (const QModelIndex&)), this, SLOT (dirSelected (const QModelIndex&))); connect (_dir, SIGNAL (activated (const QModelIndex&)), this, SLOT (dirSelected (const QModelIndex&))); connect (_model, SIGNAL(droppedOnFolder(const QMimeData *, QString &)), this, SLOT(slotDroppedOnFolder(const QMimeData *, QString &))); /* notice when the current directory is fully displayed so we can handle any pending action */ connect (_contents, SIGNAL (updateDone()), this, SLOT (slotUpdateDone())); // connect signals from the directory tree connect (_dir->_new, SIGNAL (triggered ()), this, SLOT (newDir ())); connect (_dir->_rename, SIGNAL (triggered ()), this, SLOT (renameDir ())); connect (_dir->_delete, SIGNAL (triggered ()), this, SLOT (deleteDir ())); connect (_dir->_refresh, SIGNAL (triggered ()), this, SLOT (refreshDir ())); connect (_dir->_add_recent, SIGNAL (triggered ()), this, SLOT (addToRecent ())); connect (_dir->_add_repository, SIGNAL (triggered ()), this, SLOT (slotAddRepository ())); connect (_dir->_remove_repository, SIGNAL (triggered ()), this, SLOT (slotRemoveRepository ())); setStretchFactor(indexOf(_dir), 0); QList<int> size; if (!getSettingsSizes ("desktopwidget/", size)) { size.append (200); size.append (1000); size.append (400); } setSizes (size); connect (_view, SIGNAL (popupMenu (QModelIndex &)), this, SLOT (slotPopupMenu (QModelIndex &))); // allow top level to see our view messages connect (_view, SIGNAL (newContents (QString)), this, SIGNAL (newContents (QString))); addActions(); /* unfortunately when we first run maxview it starts with the main window un-maximised. This means that scrollToLast() doesn't quite scroll far enough for the maximised view which appears soon afterwards. As a hack for the moment, we do another scroll 1 second after starting up */ QTimer::singleShot(1000, _view, SLOT (scrollToLast())); }
glm::vec3 Ray::trace(glm::vec3 rayOrig, glm::vec3 rayDir, float depth, int bounces) { // ---------------------------------------------- // Compare ray with every object in scene // Find the smallest distance to an object // ---------------------------------------------- float t0, t1, tNear = INF; Surface *s = nullptr; // Pointer to closest object for (auto &o : *scene->objects) { if (o->intersects(rayOrig, rayDir, t0, t1)) { if (t0 < tNear) { tNear = t0; s = o; } } } // ---------------------------------------------- // We have found an object // ---------------------------------------------- if (s != nullptr) { // If the closes object is a light, return light color if (s->isLight()) return s->color; // p is the point of intersection glm::vec3 directIllumination (0.0); glm::vec3 indirectIllumination (0.0); glm::vec3 p = rayOrig + rayDir * tNear; glm::vec3 normal = s->getNormal(p); glm::vec3 r = rayDir - 2 * glm::dot(rayDir, normal) * normal; // reflected direction // ---------------------------------------------- // Indirect illumination // If the object is reflective or refractive, calculate new ray(s) // ---------------------------------------------- if (s->isRefractive()) { // If the object is refractive, create refractive ray // Calculate new refractive ray // Need to do a flip if we are inside the object //glm::vec3 n = normal; //const float index = 1/1.5; //Sphere *temp = static_cast <Sphere*>(s); //if (glm::length(temp->getCenter() - p) < temp->getRadius()) n = -n; //glm::vec3 t = glm::normalize(glm::refract(rayDir, n, index)); Ray ray(scene); //indirectIllumination += ray.trace(p, t, depth, bounces); // Calculate reflective ray for both refracive and reflective materials // Trace reflective ray indirectIllumination += ray.trace(p, r, depth, bounces++); indirectIllumination /= (float)bounces; } // ---------------------------------------------- // Indirect illumination // Material is diffuse, do Monte Carlo stuff // ---------------------------------------------- else if(bounces < scene->maxBounces) { // Russian roulette float r1 = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); float r2 = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); float absorption = 0.5; // Ray is scattered if (static_cast <float> (rand()) / static_cast <float> (RAND_MAX) > absorption) { // New random direction over hemisphere float inclination = 2.0 * M_PI * r1; float azimuth = acos(2.0 * r2 - 1.0); float u = cos(azimuth); float x = sqrt(1 - u * u) * cos(inclination); float y = sqrt(1 - u * u) * sin(inclination); float z = u; // New direction. If it points the wrong way, change direction glm::vec3 newDir(x, y, z); if (glm::dot(normal, newDir) < 0) newDir = -newDir; // pdf - over hemisphere // cos - relationship between normal and the direction reflected light will come from // BRDF - Lambertian or Oren-Nayar float pdf = 1.0 / 2.0 * M_PI; float cos = glm::dot(normal, newDir); float BRDF = s->isOren() ? OrenNayarBRDF(newDir, glm::normalize(-scene->cameraDir), normal) : glm::dot(normal, newDir); Ray ray(scene); indirectIllumination = ray.trace(p, newDir, depth, bounces++) * cos * BRDF / pdf; indirectIllumination /= ((1 - absorption)); } } // ---------------------------------------------- // Direct illumination // Calculate shadow rays // ---------------------------------------------- int shadowRays = 4; for (int i = 0; i < scene->lights->size(); i++) { Sphere *l = scene->lights->at(i); // Pointer to current light glm::vec3 tempColor(0.0); // Total color per light float unobstructedRays = 0.0; for (int j = 0; j < shadowRays; j++) { bool shaded = false; glm::vec3 pDir = findRandomDirection(p, l); // Vector towards light float dist = glm::length(pDir); pDir = glm::normalize(pDir); // Shoot shadow ray(s) to random position on light (not random now though) for (auto &o : *scene->objects) if (o->intersects(p, pDir, t0, t1)) if (t0 < dist && !o->isLight()) shaded = true; if (!shaded) { unobstructedRays++; float lightIntensity = 2.2 * 1.0/255.0; float BRDF = s->isOren() ? OrenNayarBRDF(pDir, glm::normalize(-scene->cameraDir), normal) : glm::dot(normal, pDir); // TODO: N(light) must be calculated properly // radianceTransfer = dot(N(object), shadowRay) * dot(N(light), -shadowRay) float radianceTransfer = glm::dot(normal, pDir) * glm::dot(-pDir, -pDir); float pdfk = 2.0 * M_PI * l->getRadius() * l->getRadius(); // pdf over sphere (lights are halved spheres) float pdfyk = 0.5; // Chance to pick one of the light sources // Direct illumination = light * BRDF * radiance transfer / pdfk * pdfyk tempColor += l->color * lightIntensity * BRDF * radianceTransfer / (pdfk * pdfyk) * s->color; } } directIllumination += tempColor * (1.0f/(float)shadowRays); } // ---------------------------------------------- // Add direct and indirect light and return color // ---------------------------------------------- return (indirectIllumination * 2.0 + directIllumination / M_PI); } // Didn't find any object that intersects return glm::vec3(0.0, 0.0, 0.0); }