Beispiel #1
0
        public void TTreeWithZeroEntries()
        {
            // Test a full round trip for a really simple CSV dump.
            var rootFile = TestUtils.CreateFileOfInt(10);

            // Simple query that will return nothing.
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => new customObjectAllValidTypes()
            {
                vDouble = (double)e.run, vBool = e.run == 10, vInt = (int)e.run
            })
            .Where(e => false)
            .AsTTree(outputROOTFile: new FileInfo("allguys.root"));
            var query = DummyQueryExectuor.LastQueryModel;

            // Run it.
            var exe = new TTreeQueryExecutor(new[] { rootFile }, "dude", typeof(ntuple), typeof(singleIntNtuple));

            exe.CleanupQuery = false;
            var result = exe.ExecuteScalar <FileInfo[]>(query);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Length);

            var fout = ROOTNET.NTFile.Open(result[0].FullName, "READ");
            var t    = fout.Get("DataTree") as NTTree;

            Assert.IsNotNull(t);
            Assert.AreEqual(0, t.GetEntries());
        }
        public void LocalBashCmdLineSendObjectsToSelector()
        {
            var rootFile = TestUtils.CreateFileOfInt(20);

            // Get a simple query that includes packing over a histogram.
            // The funny way we do the bin content is to make sure the histogram is accessed
            // in a query data dependent way - otherwise the system optimizes the histogram access
            // to the host!
            var q = new QueriableDummy <TestNtupe>();
            var h = new ROOTNET.NTH1F("hi", "there", 1, 0.0, 10.0);

            h.Directory = null;
            h.Fill(5, 3.0);
            GC.WaitForPendingFinalizers();
            var dude  = q.Select(i => h.GetBinContent(i.run != 1 ? 1 : i.run)).Where(i => i > 2.5).Count();
            var query = DummyQueryExectuor.LastQueryModel;

            // Ok, now we can actually see if we can make it "go".
            var exe = new TTreeQueryExecutor(new[] { rootFile.AsLocalBashUri() }, "dude", typeof(ntuple), typeof(TestNtupe));

            exe.CompileDebug = true;
            int result = exe.ExecuteScalar <int>(query);

            Assert.AreEqual(20, result);
        }
Beispiel #3
0
        public void BadObjectMultBy2()
        {
            // An end-to-end code test to see if we can generate code to multiply by 2.
            var q = new QueriableDummy <ntup>();

            var mym = new MyBrokenCode();
            var i   = q.Select(e => mym.MultBy2(e.run)).Where(x => x > 2).Count();
        }
Beispiel #4
0
        /// <summary>
        /// Create a query with an anonymous object.
        /// </summary>
        private static void QueryTupleAnonyoumsObject()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => new { col2 = (int)e.run + 1, col3 = e.run + 2, col1 = e.run })
            .AsTTree(outputROOTFile: new FileInfo("hi.root"));
        }
Beispiel #5
0
        /// <summary>
        /// A tuple with two doubles.
        /// </summary>
        private static void QueryTupleSevenDoubles()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => Tuple.Create(e.run, e.run, e.run, e.run, e.run, e.run, e.run))
            .AsCSV(new FileInfo("hi.csv"), "firstCol", "second Col", "col3", "col4", "col5", "col6", "col7");
        }
Beispiel #6
0
        /// <summary>
        /// Create a AsCSV from an anonymous object.
        /// </summary>
        private static void QuerySimpleSingleRunWithCustomObject()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => new { Col2 = e.run, Col1 = e.run * 2 })
            .AsCSV(new FileInfo("hi.csv"));
        }
Beispiel #7
0
        /// <summary>
        /// Generate a simple single run query
        /// </summary>
        private static void QuerySimpleSingleRun()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => e.run)
            .AsCSV(new FileInfo("hi.csv"), "firstCol");
        }
Beispiel #8
0
        /// <summary>
        /// Generate a simple single run query
        /// </summary>
        private static void QueryNothingLeft()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => e.run)
            .Where(e => e > 100000000)
            .AsCSV(new FileInfo("hi.csv"), "firstCol");
        }
Beispiel #9
0
        public void PrettyPrintSimpleQuery()
        {
            var q = new QueriableDummy<ntup>();

            var r = q.Select(rq => rq.run * 2).PrettyPrintQuery();
            Console.WriteLine(r);
            Assert.IsTrue(r.Contains("select"));
            Assert.IsTrue(r.Contains("[rq].run * 2"));
        }
Beispiel #10
0
        public void PrettyPrintHideTuples()
        {
            var q = new QueriableDummy<ntup>();

            var r = q.Select(rq => Tuple.Create(rq.run * 2, 1)).Select(rq => rq.Item1).PrettyPrintQuery();
            Console.WriteLine(r);
            Assert.IsFalse(r.Contains("Tuple"));
            Assert.IsTrue(r.Contains("[rq].run * 2"));

        }
Beispiel #11
0
        /// <summary>
        /// Generage a query that fills all variable type.
        /// </summary>
        private static void QueryTupleAllTypes()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => new customObjectAllValidTypes()
            {
                vDouble = (double)e.run, vBool = e.run == 10, vInt = (int)e.run
            })
            .AsTTree(outputROOTFile: new FileInfo("allguys.root"));
        }
Beispiel #12
0
        private static void QueryTupleOurCustomObject()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => new ourCustomObject()
            {
                col1 = e.run, col2 = (int)e.run, col3 = e.run
            })
            .AsCSV(new FileInfo("hi.csv"));
        }
Beispiel #13
0
        /// <summary>
        /// Build a simple query to make sure unsigned ints work.
        /// </summary>
        private static void QueryUnsignedINTS()
        {
            var Q = new QueriableDummy <singleIntNtuple>();

            Q
            .Select(e => new unsignedInts()
            {
                run = (uint)e.run, run2 = (uint)e.run, run3 = (ulong)e.run, run4 = (ushort)e.run
            })
            .AsCSV(new FileInfo("hi.csv"));
        }
Beispiel #14
0
        /// <summary>
        /// We forget to initalize a varaible. Use to make sure the system gives a good
        /// error so the user can figure out what is going on.
        /// </summary>
        private static void QueryTupleOurCustomObjectMissingVar()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => new ourCustomObject()
            {
                col2 = (int)e.run + 1, col3 = e.run + 2
            })
            .AsTTree(outputROOTFile: new FileInfo("hi.root"));
        }
Beispiel #15
0
        /// <summary>
        /// Simple query for a customized object.
        /// </summary>
        private static void QueryTupleOurCustomObjectTitleAndNameDefaultFile()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => new ourCustomObject()
            {
                col1 = e.run, col2 = (int)e.run + 1, col3 = e.run + 2
            })
            .AsTTree("PhysicsTree", "Data that we've written for a physics tree");
        }
Beispiel #16
0
        /// <summary>
        /// Generate a tree against a byte, a type that we don't currently support.
        /// </summary>
        private static void QueryTupleWithBadType()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => new customObjectWithByte()
            {
                Var1 = (byte)(e.run + 1)
            })
            .AsTTree("DataTree", "not going to happen", null, "c1", "c2");
        }
Beispiel #17
0
        public void SimpleMultBy2()
        {
            // An end-to-end code test to see if we can generate code to multiply by 2.
            var q = new QueriableDummy <ntup>();

            var mym = new MyCode();
            var i   = q.Select(e => mym.MultBy2(e.run)).Where(x => x > 2).Count();

            DummyQueryExectuor.FinalResult.DumpCodeToConsole();
            Assert.IsTrue(DummyQueryExectuor.FinalResult.DumpCode().Where(l => l.Contains("*2")).Any());
        }
Beispiel #18
0
        /// <summary>
        /// Reset the leaf names
        /// </summary>
        private static void QueryTupleOurCustomObjectCustomLeafNames()
        {
            var q = new QueriableDummy <singleIntNtuple>();

            q
            .Select(e => new ourCustomObject()
            {
                col1 = e.run, col2 = (int)e.run + 1, col3 = e.run + 2
            })
            .AsTTree("DataTree", "this is a test", null, "c1", "c2");
        }
Beispiel #19
0
        public void CacheObjectWhenCPPChanges()
        {
            TestUtils.ResetLINQLibrary();
            // Make sure that when the C++ code changes, the cache key for lookup of results will also change.
            var q     = new QueriableDummy <ntup>();
            var i     = q.Select(e => DoItClass.DoIt(e.run)).Where(x => x > 2).Count();
            var query = DummyQueryExectuor.LastQueryModel;

            // Look for a hash value.
            var str1 = FormattingQueryVisitor.Format(query);

            Console.WriteLine(str1);
            var m = Regex.Match(str1, @"DoIt([^\(]+)");

            Assert.IsTrue(m.Success);
        }
Beispiel #20
0
        public void CacheWhenCPPChanges()
        {
            // Make sure that when the C++ code changes, the cache key for lookup of results will also change.
            var q   = new QueriableDummy <ntup>();
            var mym = new MyModifiableCode();

            mym.LOC = new string[] { "int i = 0;", "MultBy2 = 10;" };
            var i     = q.Select(e => mym.MultBy2(e.run)).Where(x => x > 2).Count();
            var query = DummyQueryExectuor.LastQueryModel;

            // Set the LOC to something.
            var str1 = FormattingQueryVisitor.Format(query);

            mym.LOC = new string[] { "int j = 10;", "MultBy2 = 10;" };
            var str2 = FormattingQueryVisitor.Format(query);

            Console.WriteLine(str1);
            Console.WriteLine(str2);
            Assert.AreNotEqual(str1, str2);
        }
Beispiel #21
0
        public void SumInFutureQuery()
        {
            int numberOfIter = 10;

            var rootFile = TestUtils.CreateFileOfInt(numberOfIter);
            var q        = new QueriableDummy <TestNtupe>();
            var dude     = q.Select(evt => evt.run).Sum();
            var query    = DummyQueryExectuor.LastQueryModel;

            var exe = new TTreeQueryExecutor(new Uri[] { rootFile }, "dude", typeof(ntuple), typeof(TestNtupe));

            var result = exe.ExecuteScalarAsFuture <int>(query);

            Assert.IsNotNull(result, "future should exist!");
            Assert.IsFalse(result.HasValue, "future shoudl not have executed by now!");

            var val = result.Value;

            Assert.AreEqual(numberOfIter * 10, val, "incorrect result came back.");
            Assert.IsTrue(result.HasValue, "value should be marked by now!");
        }
Beispiel #22
0
 /// <summary>
 /// Create a query with an anonymous object.
 /// </summary>
 private static void QueryTupleAnonyoumsObject()
 {
     var q = new QueriableDummy<singleIntNtuple>();
     q
         .Select(e => new { col2 = (int)e.run + 1, col3 = e.run + 2, col1 = e.run})
         .AsTTree(outputROOTFile: new FileInfo("hi.root"));
 }
        public void SimpleMultBy2()
        {
            // An end-to-end code test to see if we can generate code to multiply by 2.
            var q = new QueriableDummy<ntup>();

            var mym = new MyCode();
            var i = q.Select(e => mym.MultBy2(e.run)).Where(x => x > 2).Count();

            DummyQueryExectuor.FinalResult.DumpCodeToConsole();
            Assert.IsTrue(DummyQueryExectuor.FinalResult.DumpCode().Where(l => l.Contains("*2")).Any());
        }
        public void BadObjectMultBy2()
        {
            // An end-to-end code test to see if we can generate code to multiply by 2.
            var q = new QueriableDummy<ntup>();

            var mym = new MyBrokenCode();
            var i = q.Select(e => mym.MultBy2(e.run)).Where(x => x > 2).Count();
        }
        public void CacheWhenIncludesChange()
        {
            // Make sure that when the C++ code changes, the cache key for lookup of results will also change.
            var q = new QueriableDummy<ntup>();
            var mym = new MyModifiableCode();
            mym.LOC = new string[] { "int i = 0;", "MultBy2 = 10;" };
            var i = q.Select(e => mym.MultBy2(e.run)).Where(x => x > 2).Count();
            var query = DummyQueryExectuor.LastQueryModel;

            // Set the LOC to something.
            mym.Includes = new string[] { "TMVAReader.h" };
            var str1 = FormattingQueryVisitor.Format(query);
            mym.Includes = new string[] { "TFile.h" };
            var str2 = FormattingQueryVisitor.Format(query);
            Console.WriteLine(str1);
            Console.WriteLine(str2);
            Assert.AreNotEqual(str1, str2);
        }
Beispiel #26
0
 /// <summary>
 /// We forget to initalize a varaible. Use to make sure the system gives a good
 /// error so the user can figure out what is going on.
 /// </summary>
 private static void QueryTupleOurCustomObjectMissingVar()
 {
     var q = new QueriableDummy<singleIntNtuple>();
     q
         .Select(e => new ourCustomObject() { col2 = (int)e.run + 1, col3 = e.run + 2 })
         .AsTTree(outputROOTFile: new FileInfo("hi.root"));
 }
Beispiel #27
0
 /// <summary>
 /// Generage a query that fills all variable type.
 /// </summary>
 private static void QueryTupleAllTypes()
 {
     var q = new QueriableDummy<singleIntNtuple>();
     q
         .Select(e => new customObjectAllValidTypes() { vDouble = (double)e.run, vBool = e.run == 10, vInt = (int)e.run })
         .AsTTree(outputROOTFile: new FileInfo("allguys.root"));
 }
        public void CacheObjectWhenCPPChanges()
        {
            TestUtils.ResetLINQLibrary();
            // Make sure that when the C++ code changes, the cache key for lookup of results will also change.
            var q = new QueriableDummy<ntup>();
            var i = q.Select(e => DoItClass.DoIt(e.run)).Where(x => x > 2).Count();
            var query = DummyQueryExectuor.LastQueryModel;

            // Look for a hash value.
            var str1 = FormattingQueryVisitor.Format(query);
            Console.WriteLine(str1);
            var m = Regex.Match(str1, @"DoIt([^\(]+)");
            Assert.IsTrue(m.Success);
        }
Beispiel #29
0
 /// <summary>
 /// Reset the leaf names
 /// </summary>
 private static void QueryTupleOurCustomObjectCustomLeafNames()
 {
     var q = new QueriableDummy<singleIntNtuple>();
     q
         .Select(e => new ourCustomObject() { col1 = e.run, col2 = (int)e.run + 1, col3 = e.run + 2 })
         .AsTTree("DataTree", "this is a test", null, "c1", "c2");
 }
Beispiel #30
0
 /// <summary>
 /// Generate a tree against a byte, a type that we don't currently support.
 /// </summary>
 private static void QueryTupleWithBadType()
 {
     var q = new QueriableDummy<singleIntNtuple>();
     q
         .Select(e => new customObjectWithByte() { Var1 = (byte)(e.run + 1) })
         .AsTTree("DataTree", "not going to happen", null, "c1", "c2");
 }
Beispiel #31
0
 /// <summary>
 /// Simple query for a customized object.
 /// </summary>
 private static void QueryTupleOurCustomObjectTitleAndNameDefaultFile()
 {
     var q = new QueriableDummy<singleIntNtuple>();
     q
         .Select(e => new ourCustomObject() { col1 = e.run, col2 = (int)e.run + 1, col3 = e.run + 2 })
         .AsTTree("PhysicsTree", "Data that we've written for a physics tree");
 }