Ejemplo n.º 1
0
int main(int argc, char **argv)
{
    // one or two input files
    assert(argc == 2 || argc == 3); // if not one or two input files -> abort

    std::auto_ptr<TFile> inFile(new TFile(argv[1]));
    assert(inFile.get());
    TH2D *th2 = dynamic_cast<TH2D*>(inFile->Get("jets"));
    assert(th2);
    th2->Sumw2();

    if (argc == 3) {
        std::auto_ptr<TFile> inFile2(new TFile(argv[2]));
        assert(inFile2.get());
        TH2D *th2b = dynamic_cast<TH2D*>(inFile2->Get("jets"));
        assert(th2b);
        th2b->Sumw2();
        th2->SetName("jets_ratio");
        th2->Divide(th2b); // if there is a second input file, divide the histogram of the b jet pt/eta through the histogram of the non-b jet pt/eta
    }

    TFile g("out.root", "RECREATE"); //rootfile with control plots
    //create histogram that will contain the eta values of the jets for a certain ptbin (the real value of eta is transformed between -1 and 1 because the Chebychev polynominial is only defined on that range)
    TH1D *th1[th2->GetNbinsY()];
    for(int i = 0; i < th2->GetNbinsY(); i++) {
        th1[i] = new TH1D(Form("ptslice%d", i), "slice",th2->GetNbinsX(), -1.0, +1.0); //number of bins related to number of etabins in histoJetEtaPt.C
        th1[i]->SetDirectory(0);
    }

///////////////// define the fitfunction for the eta distribution in a certain pt slice
    TF1 *cheb = new TF1("ChebS8", "[0] +"
                        "[1] * (2 * (x^2) - 1) + "
                        "[2] * (8 * (x^4) - 8 * (x^2) + 1) + "
                        "[3] * (32 * (x^6) - 48 * (x^4) + 18 * (x^2) - 1) + "
                        "[4] * (128 * (x^8) - 256 * (x^6) + 160 * (x^4) - 32 * (x^2) + 1) +"
                        "[5] * (512 * (x^10) - 1280 * (x^8) + 1120 * (x^6) - 400 * (x^4) + 50 * (x^2) - 1) +"
                        "[6] * (2048 * (x^12) - 6144 * (x^10) + 6912 * (x^8) - 3584 * (x^6) + 840 * (x^4) - 72 * (x^2) + 1)",
                        -1.0, +1.0);
    cheb->SetParLimits(0, 0.0, 100000.0);

///////////////// fit the etadistributions for each ptslice and fill the distributions of the fitcoefficients for the different pt slices
    TH1D *coeffs[7];
    for(int i = 0; i < 7; i++) {
        coeffs[i] = new TH1D(Form("coeff%d", i), "coeffs", th2->GetNbinsY()-2, 0.5, th2->GetNbinsY()-2 + 0.5); //for each coefficient create a histogram with the number of ptbins
        coeffs[i]->SetDirectory(0);
    }

    std::cout << "number of ptbins: " << th2->GetNbinsY() << std::endl;
    std::cout << "number of etabins: " << th2->GetNbinsX() << std::endl;

    for(int y = 1; y <= th2->GetNbinsY()-2; y++) { //loop over ptbins
        for(int x = 1; x <= th2->GetNbinsX(); x++) //loop over etabins
        {
            th1[y]->SetBinContent(x, th2->GetBinContent(x, y)); // weight!
        }
        th1[y]->SetDirectory(&g);
        th1[y]->Fit(cheb, "QRNB"); // fit the new histogram with the crazy fitfunction!
        th1[y]->Write();
        cheb->SetName(Form("cheb%d", y));
        cheb->Write();

        for(int i = 0; i < 7; i++) {
            coeffs[i]->SetBinContent(y, cheb->GetParameter(i));
            coeffs[i]->SetBinError(y, cheb->GetParError(i));
        }
    }

///////////////// fit the coefficients as function of pt
    double params[7][6];
    TF1 *pol[7];
    for(int i = 0; i < 7; i++) {
        //the following piece of code is not relevant: expo, arg and f1 not used afterwards and coeffs[i] is refitted with pol5
        /*coeffs[i]->Fit("expo", "Q0");
        TF1 *f1 = coeffs[i]->GetFunction("expo");
        double expo, arg;
        if (f1->GetParameter(0) >= -100000.0) {
        	expo = std::exp(f1->GetParameter(0));
        	arg = f1->GetParameter(1);
        } else {
        	coeffs[i]->Scale(-1.0);
        	coeffs[i]->Fit("expo", "Q0");
        	f1 = coeffs[i]->GetFunction("expo");
        	expo = -std::exp(f1->GetParameter(0));
        	arg = f1->GetParameter(1);
        	coeffs[i]->Scale(-1.0);
        }*/
        coeffs[i]->Fit("pol5", "0B");
        pol[i] = coeffs[i]->GetFunction("pol5");
        pol[i]->SetName(Form("pol%d", i));
        pol[i]->Write();
        for(int j = 0; j < 6; j++)
            params[i][j] = pol[i]->GetParameter(j);
    }

///////////////// store the fit"function" in the histogram and calculate the chi2
    double chi2 = 0.0;
    int ndf = 0;
    TH2D *th2c = new TH2D(*th2);
    th2c->SetName("fit");
    for(int y = 1; y <= th2->GetNbinsY(); y++) { // ptbins
        int ry = y > th2->GetNbinsY()-4 ? th2->GetNbinsY()-4 : y;
        for(int x = 1; x <= th2->GetNbinsX(); x++) { // etabins
            //std::cout << "original histo, now in ptbin y: " << y << " (ry: " << ry <<") and etabin x: " << x << std::endl;
            //using the coefficients of the fitted functions, the value is calculated (this value will be close to the original value in case 1 rootfile is given and will the close to the original value of the divided histograms if 2 rootfiles are given)
            double val = compute(params, (x - 0.5) /(0.5*(float) th2->GetNbinsX()) - 1.0, ry);
            //std::cout << "val " << val << " for " << (x - 0.5) / 25.0 - 1.0 << " and for ry: " << ry  << std::endl;
            if (val < 0)
                val = 0;
            double error = th2->GetBinError(x, y);
            if (error > 0 && val > 0) {
                double chi = th2->GetBinContent(x, y) - val;
                chi2 += chi * chi / val;
                ndf++;
            }
            th2c->SetBinContent(x, y, val);
        }
    }
    std::cout << "chi2/ndf(" << ndf << "): " << (chi2 / ndf) << std::endl;



///////////////// writing histos
    for(int i = 0; i < 7; i++)
    {
        coeffs[i]->SetDirectory(&g);
        coeffs[i]->Write();
    }
    th2->SetDirectory(&g);
    th2->Write(); //write the original histogram (or the result of the two histograms divided by eachother)
    th2c->SetDirectory(&g);
    th2c->Write(); //write the histogram with the new weights
    g.Close();

///////////////// writing relevant parameters for reweighting
    std::ofstream of("out.txt");
    of << std::setprecision(16);
    for(int i = 0; i < 7; i++)
        for(int j = 0; j < 6; j++)
            of << params[i][j] << (j < 5 ? "\t" : "\n");
    of.close();

    return 0;
}
Ejemplo n.º 2
0
int WindowApp::makeGradApplication(GtkWidget *widget, WindowApp *theApp)
{
	theApp->gradApp = true;
	/////////////////////////////////////////////////
	//--Creates new frame and adds it onto the window---//
	/////////////////////////////////////////////////
 	gtk_widget_destroy(theApp->student_window);
	gtk_widget_destroy(theApp->appFrame);
	theApp->appFrame = gtk_fixed_new();
	gtk_window_resize(GTK_WINDOW(theApp->window), 400,600);
	
//their general information, including student number, first and last names, email address, main research area
//(selected from a preconfigured list), program (MCS or PhD), and supervisor name
	theApp->combo =  gtk_combo_box_text_new();
	theApp->grad_research_combo =  gtk_combo_box_text_new();
	theApp->grad_program_combo =  gtk_combo_box_text_new();
	theApp->fName = gtk_entry_new();
	theApp->lName = gtk_entry_new();
	theApp->email = gtk_entry_new();
	theApp->grad_sup = gtk_entry_new();
	theApp->stuNum = gtk_entry_new();

	gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(theApp->grad_program_combo), "MCS");
	gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(theApp->grad_program_combo), "PHD");
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->grad_program_combo, 200, 300);


	char text[800];
	string courses[800];

	ifstream inFile("courses.txt", ios::in);

	if (!inFile) {
		cout<<"Could not open courses file"<<endl;
		return 0;
	}	
	while (!inFile.eof()) {
		inFile.getline(text, 800);
		
		gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(theApp->combo), text);
	}
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->combo, 200, 200);


	char text2[800];
	string areas[800];

	ifstream inFile2("gradResearch.txt", ios::in);

	if (!inFile2) {
		cout<<"Could not open Grad Research file"<<endl;
		return 0;
	}	
	while (!inFile2.eof()) {
		inFile2.getline(text2, 800);
		
		gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(theApp->grad_research_combo), text2);
	}
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->grad_research_combo, 200, 250);
	



	/////////////////////////////////////////////////
	//--Creates text Boxes and submit\cancel buttons---//
	/////////////////////////////////////////////////
	//theApp->combo = combo;
	
	
	
	/////////////////////////////////////////////////
	//--Puts text boxes onto the new frame---------//
	/////////////////////////////////////////////////
	
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->fName, 150, 340);
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lName, 150, 370);
	//gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->major, 150, 340);
	//gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->gpa, 150, 370);
	//gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->cgpa, 150, 400);
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->email, 150, 400);
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->grad_sup, 150, 430);
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->stuNum, 150, 460);

	/////////////////////////////////////////////////
	//--Puts labels onto the new frame---------//
	/////////////////////////////////////////////////

	theApp->lblpickCourse = gtk_label_new("Pick Course :");
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lblpickCourse, 30, 200); 
	theApp->lblpickArea = gtk_label_new("Study Area :");
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lblpickArea, 30, 250);
	theApp->lblpickProgram = gtk_label_new("Grad Program:");
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lblpickProgram, 30, 300);
	
	theApp->lblfName = gtk_label_new("First Name :");
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lblfName, 30, 340); 
	theApp->lbllName = gtk_label_new("Last Name :");
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lbllName, 30, 370);
	theApp->lblEmail = gtk_label_new("Email Address:");
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lblEmail, 30, 400);
	//theApp->lblGpa = gtk_label_new("GPA :");
	//gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lblGpa, 30, 370);
	//theApp->lblCgpa = gtk_label_new("CGPA :");
	//gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lblCgpa, 30, 400);
	theApp->lbl_grad_sup = gtk_label_new("Supervisor :");
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lbl_grad_sup, 30, 430);
	//theApp->lblYear = gtk_label_new("Year :");
	//gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lblYear, 30, 460);
	theApp->lblstuNum = gtk_label_new("Student Number :");
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->lblstuNum, 30, 460);

	

	/////////////////////////////////////////////////
	//--Puts buttons onto the new frame---------//
	/////////////////////////////////////////////////

	
	theApp->submit = gtk_button_new_with_label("Submit");
	theApp->cancel = gtk_button_new_with_label("Cancel");

	
	gtk_widget_set_size_request(theApp->submit, 80, 35);
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->submit, 50, 530);
	gtk_widget_set_size_request(theApp->cancel, 80, 35);
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->cancel, 200, 530);

	theApp->info_label = gtk_label_new("Please Enter Info Below");
	gtk_fixed_put(GTK_FIXED(theApp->appFrame), theApp->info_label, 150, 58);
	gtk_container_add(GTK_CONTAINER(theApp->window), theApp->appFrame);
	/////////////////////////////////////////////////
	//--Show all widgets on new frame---------//
	/////////////////////////////////////////////////
	gtk_widget_show_all(theApp->window);

	 
	

	g_signal_connect(theApp->submit, "clicked", G_CALLBACK(Control::getInfo), theApp);
	
	g_signal_connect(theApp->cancel, "clicked", G_CALLBACK(Control::submitToMain), theApp);
	g_signal_connect(GTK_COMBO_BOX(theApp->combo), "changed", G_CALLBACK   (WindowApp::relatedCourses2), theApp);
  	return 0;
}
Ejemplo n.º 3
0
bool BotanWrapper::EncryptFile(QString Source, QString Destination)
{
    QFileInfo name = Source;
    QString base = name.baseName();
    QString encrypted1 = eoutput + base + ".gg";
    QString encrypted2 = toutput + base + ".twofish";
    QFile e(encrypted1);
    QFile t(encrypted2);

    try
    {
        //Setup the key derive functions
        PKCS5_PBKDF2 pbkdf2(new HMAC(new Keccak_1600));
        const u32bit PBKDF2_ITERATIONS = 700000;
qDebug() << "create keys";
        //Create the KEY and IV
        KDF* kdf = get_kdf("KDF2(SHA-512)");
AutoSeeded_RNG rng;
qDebug() << "create salt";
        SecureVector<byte> salt(256);
           rng.randomize(&salt[0], salt.size());
           mSalt = salt;
qDebug() << "create master key";
        //Create the master key
        SecureVector<byte> mMaster = pbkdf2.derive_key(128, mPassword.toStdString(), &mSalt[0], mSalt.size(),PBKDF2_ITERATIONS).bits_of();
        SymmetricKey mKey = kdf->derive_key(32, mMaster, "salt1");
        InitializationVector mIV = kdf->derive_key(16, mMaster, "salt2");
qDebug() << "start encryption";
        string inFilename = Source.toStdString();
        string outFilename = encrypted1.toStdString();
        std::ifstream inFile(inFilename.c_str());
        std::ofstream outFile(outFilename.c_str());


        Pipe pipe(get_cipher("AES-256/EAX", mKey, mIV,ENCRYPTION),new DataSink_Stream(outFile));
                outFile.write((const char*)mSalt.begin(), mSalt.size());
        pipe.start_msg();
        inFile >> pipe;
        pipe.end_msg();


        outFile.flush();
        outFile.close();
        inFile.close();


        QMessageBox msgBox;


/*****************TWOFISH ENCRYPTION********************/

qDebug() << "Twofish";
        //Setup the key derive functions
        PKCS5_PBKDF2 pbkdf3(new HMAC(new Skein_512));

        //Create the KEY and IV
        KDF* kdf2 = get_kdf("KDF2(Whirlpool)");
        SecureVector<byte> salt2(256);
           rng.randomize(&salt2[0], salt2.size());
           mSalt2 = salt2;

        //Create the master key
        SecureVector<byte> mMaster2 = pbkdf3.derive_key(128, mPassword2.toStdString(), &mSalt2[0], mSalt2.size(),PBKDF2_ITERATIONS).bits_of();
        SymmetricKey mKey2 = kdf2->derive_key(32, mMaster2, "salt1");
        InitializationVector mIV2 = kdf2->derive_key(16, mMaster2, "salt2");

        string inFilename2 = encrypted1.toStdString();
        string outFilename2 = encrypted2.toStdString();
        std::ifstream inFile2(inFilename2.c_str());
        std::ofstream outFile2(outFilename2.c_str());

        Pipe pipe2(get_cipher("Twofish/CFB", mKey2, mIV2,ENCRYPTION),new DataSink_Stream(outFile2));
                outFile2.write((const char*)mSalt2.begin(), mSalt2.size());
        pipe2.start_msg();
        inFile2 >> pipe2;
        pipe2.end_msg();


        outFile2.flush();
        outFile2.close();
        inFile2.close();


/**************************SERPENT ENCRYPTION*****************/

        //Create the KEY and IV
        KDF* kdf3 = get_kdf("KDF2(Tiger)");

        SecureVector<byte> salt3(256);
           rng.randomize(&salt3[0], salt3.size());
           mSalt3 = salt3;

        //Create the master key
        SecureVector<byte> mMaster3 = pbkdf2.derive_key(128, mPassword3.toStdString(), &mSalt3[0], mSalt3.size(),PBKDF2_ITERATIONS).bits_of();
        SymmetricKey mKey3 = kdf3->derive_key(32, mMaster3, "salt1");
        InitializationVector mIV3 = kdf3->derive_key(16, mMaster3, "salt2");

        string inFilename3 = encrypted2.toStdString();
        string outFilename3 = Destination.toStdString();
        std::ifstream inFile3(inFilename3.c_str());
        std::ofstream outFile3(outFilename3.c_str());

qDebug() << "serpent";
        Pipe pipe3(get_cipher("Serpent/CBC/PKCS7", mKey3, mIV3,ENCRYPTION),new DataSink_Stream(outFile3));
                outFile3.write((const char*)mSalt3.begin(), mSalt3.size());
        pipe3.start_msg();
        inFile3 >> pipe3;
        pipe3.end_msg();


        outFile3.flush();
        outFile3.close();
        inFile3.close();


        msgBox.setText("Success!");
        msgBox.setInformativeText("File successfully encrypted!");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();


e.remove(); t.remove();


        return true;
    }
    catch(...)
    {
        return false;
    }
}
Ejemplo n.º 4
0
void Builder::ImportDeclarations(void)
{
    QString inFileName = config.workspace + "/" + project->name + "/source/" + project->name + ".cpp"; //main.cpp

    if (QFileInfo(inFileName).exists() == false) {
        return;
    }

    QFile inFile(inFileName);
    inFile.open(QFile::ReadOnly | QFile::Text);
    QTextStream in(&inFile);
    QString code = in.readAll();

    // Remove all single-line comments from the text that will be processed
    QStringList lines = code.split("\n");

    int i=0;
    while (i < lines.count()) {
        int p = lines[i].indexOf("//");
        if (p >= 0) {
            lines[i] = lines[i].right(p);
        }
        i++;
    }
    code = lines.join("\n");

    // remove all multi-line comments from the text that will be processed
    int p1 = code.indexOf("/*");
    //int watchDogMonitor = code.length();
    while (p1 >= 0) {
        QString left = code.left(p1);
        code = code.right(code.length() - p1);
        int p2 = code.indexOf("*/");
        if (p2 >=0) {
            QString right = code.right(code.length() - p2 - 2);
            code = left + right;
        } else {
            return; // could not find the end of a comment: break to avoid infinite loop
        }
        p1 = code.indexOf("/*");

        /*if (code.length() == watchDogMonitor) {
        	return; // exit to avoid an infinite loop
        }
        watchDogMonitor = code.length();*/
    }

    lines = code.split("\n");
    QStringList list;

    i=1;
    while (i < lines.count()) {
        if (lines[i].trimmed().indexOf("{") == 0) {
            lines[i-1] = " " + lines[i];
            lines.erase(lines.begin()+i);
        } else {
            i++;
        }
    }

    for (int i=0; i < lines.count(); i++) {
        //QRegExp rx("(\\ |\\,|\\(|\\)|\\.|\\:|\\t)"); //RegEx for ' ' or ',' or '.' or ':' or '\t'
        QRegExp rx("\\s"); //RegEx for all white spaces, including tab'
        bool ok = rx.isValid();
        QString line = lines[i].trimmed();
        int j = 0;
        while (j < line.size()) { //insert spaces
            if ( ( (line.at(j) == '(') || (line.at(j) == ')') ) || ( (line.at(j) == '{') || (line.at(j) == '}') ) ) {
                line.insert(j, " ");
                j++;
            }
            if ( ( (line.at(j) == ':') || (line.at(j) == ',') ) || ( (line.at(j) == ';') || (line.at(j) == ';') ) ) {
                line.insert(j, " ");
                j++;
            }
            j++;
        }
        QStringList words = line.split(rx);
        int w = 0;
        while (w < words.count()) {
            words[w] = words[w].trimmed().toUpper();
            if (words[w] == "") {
                words.erase(words.begin() + w);
            } else {
                w++;
            }
        }

        if (words.count() < 4) { // at least "TYPE", "FUNCTION_NAME", "(", ")"
            continue;
        }

        bool ignore = false;
        ignore = ignore || (words.indexOf("IF") >= 0);
        ignore = ignore || (words.indexOf("ELSE") >= 0);
        ignore = ignore || (words.indexOf("WHILE") >= 0);
        ignore = ignore || (words.indexOf("DO") >= 0);
        ignore = ignore || (words.indexOf("SWITCH") >= 0);
        ignore = ignore || (lines[i].indexOf(";") >= 0);
        ignore = ignore || (lines[i].indexOf(".") >= 0);
        ignore = ignore || (lines[i].indexOf("->") >= 0);
        ignore = ignore || (lines[i].indexOf("=") >= 0);
        ignore = ignore || (lines[i].indexOf("==") >= 0);
        ignore = ignore || (lines[i].indexOf("\"") >= 0); // any argument with " may be considered a call, and not a definition
        ignore = ignore || (lines[i].indexOf("'") >= 0); // idem

        // check if any argument is a number. If yes, then it shall be considered a function call, and not a definiton
        for (int j=0; j < words.count(); j++) {
            double num = words.at(j).toDouble();
            if (QString::number(num) == words.at(j)) {
                ignore = true;
                break;
            }
        }

        // if the first word is not an recognized data type, ignore
        bool validDataType = false;
        validDataType = validDataType || (words.at(0) == "VOID");
        validDataType = validDataType || (words.at(0) == "INT");
        validDataType = validDataType || (words.at(0) == "CHAR");
        validDataType = validDataType || (words.at(0) == "SHORT");
        validDataType = validDataType || (words.at(0) == "UNSIGNED");
        validDataType = validDataType || (words.at(0) == "SIGNED");
        validDataType = validDataType || (words.at(0) == "LONG");
        validDataType = validDataType || (words.at(0) == "FLOAT");
        validDataType = validDataType || (words.at(0) == "DOUBLE");
        validDataType = validDataType || (words.at(0) == "BYTE");
        validDataType = validDataType || (words.at(0) == "INT16");
        validDataType = validDataType || (words.at(0) == "INT32");
        validDataType = validDataType || (words.at(0) == "INT64");
        validDataType = validDataType || (words.at(0) == "BOOL");
        ignore = ignore || (validDataType == false);

        if (lines[i].indexOf("//") >= 0) {
            lines[i] = lines[i].left(lines[i].indexOf("//"));
        }

        if (ignore) {
            continue;
        }

        int p1 = lines[i].indexOf("(");
        int p2 = lines[i].indexOf(")");
        if ((p1 > 0) && (p2 > p1)) {
            QString def = lines[i].trimmed();
            int p = def.lastIndexOf(")");
            if (p >= 0) {
                def = def.left(p+1) + ";";
                list.append(def);
            }
        }
    }

    QString outFileName = config.workspace + "/" + project->name + "/source/mariamole_auto_generated.h";

    if (QFileInfo(outFileName).exists() == false) {
        return;
    }

    QFile inFile2(outFileName);
    inFile2.open(QFile::ReadOnly | QFile::Text);
    QTextStream in2(&inFile2);
    code = in2.readAll();

    QStringList header = code.split("\n");
    //QStringList alreadyAdded;
    int index = -1;// = header.count() - 2;
    bool foundBegin = false;
    int k=0;
    while (k < header.count()) {
        QString line = header[k].trimmed();
        if (line == "/*--MARIMOLE-DEF_END--*/") {
            foundBegin = false;
        }
        if (foundBegin) {
            header.erase(header.begin() + k);
        } else {
            ++k;
        }
        if (line == "/*--MARIMOLE-DEF_BEGIN--*/") {
            foundBegin = true;
            index = k;
        }
    }

    if (index < 0) {
        return;
    }

    for (int i=0; i < list.count(); i++) {
        header.insert(index, list[i]);
    }

    QFile outFile(outFileName);
    outFile.open(QFile::WriteOnly);
    QTextStream out(&outFile);
    out << header.join("\n");
}