File indexing completed on 2024-05-05 16:00:20

0001 /***************************************************************************
0002 File                 : samplefiles.C
0003 Project              : LabPlot
0004 Description          : ROOT script to create test files for ROOT importer
0005 -------------------------------------------------------------------------
0006 Copyright            : (C) 2018 by Christoph Roick (chrisito@gmx.de)
0007 ***************************************************************************/
0008 
0009 /***************************************************************************
0010 *                                                                         *
0011 *  This program is free software; you can redistribute it and/or modify   *
0012 *  it under the terms of the GNU General Public License as published by   *
0013 *  the Free Software Foundation; either version 2 of the License, or      *
0014 *  (at your option) any later version.                                    *
0015 *                                                                         *
0016 *  This program is distributed in the hope that it will be useful,        *
0017 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0018 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0019 *  GNU General Public License for more details.                           *
0020 *                                                                         *
0021 *   You should have received a copy of the GNU General Public License     *
0022 *   along with this program; if not, write to the Free Software           *
0023 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0024 *   Boston, MA  02110-1301  USA                                           *
0025 *                                                                         *
0026 ***************************************************************************/
0027 
0028 // ROOT test files are regenerated by calling 'root samplefiles.C'.
0029 // Note that creation date and random numbers will be different in the new files.
0030 
0031 void samplefiles()
0032 {
0033     TFile fBasic("basic_lz4.root", "RECREATE");
0034     fBasic.SetCompressionAlgorithm(ROOT::kLZ4);
0035 
0036     TH1D doubleHist("doubleHist", "", 100, -5., 5.);
0037     doubleHist.Sumw2();
0038     doubleHist.FillRandom("gaus", 10000);
0039     doubleHist.Write();
0040 
0041     TH1F floatHist("floatHist", "", 100, -5., 5.);
0042     floatHist.Sumw2();
0043     floatHist.FillRandom("gaus", 10000);
0044     floatHist.Write();
0045 
0046     TH1I intHist("intHist", "", 100, -5., 5.);
0047     intHist.Sumw2();
0048     intHist.FillRandom("gaus", 10000);
0049     intHist.Write();
0050 
0051     TH1S shortHist("shortHist", "", 100, -5., 5.);
0052     shortHist.Sumw2();
0053     shortHist.FillRandom("gaus", 10000);
0054     shortHist.Write();
0055 
0056     TH1C charHist("charHist", "", 100, -5., 5.);
0057     charHist.Sumw2();
0058     charHist.FillRandom("gaus", 1000);
0059     charHist.Write();
0060 
0061     fBasic.Close();
0062 
0063     TFile fAdvanced("advanced_zlib.root", "RECREATE");
0064     fAdvanced.SetCompressionAlgorithm(ROOT::kZLIB);
0065 
0066     vector<double> borders;
0067     for (size_t i = 0; i < 101; ++i)
0068         borders.push_back(0.09 * i - 5. + 1.e-4 * i * i);
0069 
0070     TH1D variableBinHist("variableBinHist", "", 100, borders.data());
0071     variableBinHist.Sumw2();
0072     variableBinHist.FillRandom("gaus", 10000);
0073     variableBinHist.Write();
0074     variableBinHist.FillRandom("gaus", 1000000);
0075     variableBinHist.Write();
0076 
0077     TTree tree("tree", "TTree title");
0078     double d;
0079     int i;
0080     struct {
0081         int a[2];
0082         Double_t d;
0083         float f;
0084     } s;
0085     tree.Branch("doubleTest", &d, "doubleTest/D");
0086     tree.Branch("intTest", &i, "intTest/I");
0087     tree.Branch("structTest", &s, "array[2]/I:double/D:float/F");
0088 
0089     for (size_t j = 0; j < 10; ++j) {
0090         d = j;
0091         i = j;
0092         s.f = 9 - j;
0093         s.a[0] = j; s.a[1] = 2 * j;
0094         s.d = s.f * s.f;
0095         tree.Fill();
0096     }
0097     tree.Write();
0098 
0099     TNtuple tuple("tuple", "TNtuple title", "x:y:z");
0100     tuple.Fill(1., 2., 3.);
0101     tuple.Write();
0102     tuple.Fill(3., 4., 5.);
0103     tuple.Write();
0104 
0105     fAdvanced.Close();
0106 
0107     ifstream infile("basic_lz4.root");
0108     ofstream outfile("broken_basic.root");
0109 
0110     char buffer[3000];
0111     infile.read(buffer, 3000);
0112     outfile.write(buffer, 3000);
0113 }