public async Task TestForFilesInDifferentOrders() { var f1 = MakeRootFile("TestHitDriver1"); var f2 = MakeRootFile("TestHitDriver2"); var query = MakeQuery(0); /// Cache a result var h = new ROOTNET.NTH1F("hi", "there", 10, 0.0, 10.0) { Directory = null }; h.SetBinContent(1, 5.0); var q = new QueryResultCache(); var k1 = q.GetKey(new Uri[] { f1, f2 }, "test", null, null, query, dateChecker: u => File.GetLastWriteTime(u.LocalPath)); var k2 = q.GetKey(new Uri[] { f2, f1 }, "test", null, null, query, dateChecker: u => File.GetLastWriteTime(u.LocalPath)); await q.CacheItem(k1, new NTObject[] { h }.AsRunInfoArray()); // // Now, do the lookup, but with files in a different order. // var r1 = await q.Lookup <int>(k1, new DummySaver(), null); var r2 = await q.Lookup <int>(k2, new DummySaver(), null); Assert.IsTrue(r1.Item1, "expected hit for same key"); Assert.IsTrue(r2.Item1, "expected hit for second key with different files"); }
public async Task TestForSameResultHistosDiffNameTitle() { var f = MakeRootFile("TestForSameResultHistosDiffNameTitle"); var query = MakeQuery(2); var inputs = new object[0]; /// Cache a result var h = new ROOTNET.NTH1F("hi", "there", 10, 0.0, 10.0) { Directory = null }; h.SetBinContent(1, 5.0); var q = new QueryResultCache(); await q.CacheItem(q.GetKey(new Uri[] { f }, "test", inputs, null, query, dateChecker: u => File.GetLastWriteTime(u.LocalPath)), new NTObject[] { h }.AsRunInfoArray()); /// And make sure the lookup works now - make a different query, which is the same /// but with a slightly different query guy. var query1 = MakeQuery(4); var r = await Lookup <int>(q, f, "test", new object[0], null, query1, new DummySaver()); Assert.IsTrue(r.Item1, "Expected a cache hit"); }
public async Task TestForFileOutOfDateNoCheck() { var f = MakeRootFile("TestForFileOutOfDate"); var query = MakeQuery(0); /// Cache a result var h = new ROOTNET.NTH1F("hi", "there", 10, 0.0, 10.0) { Directory = null }; h.SetBinContent(1, 5.0); var q = new QueryResultCache(); await q.CacheItem(q.GetKey(new Uri[] { f }, "test", null, null, query, dateChecker: u => File.GetLastWriteTime(u.LocalPath)), new NTObject[] { h }.AsRunInfoArray()); /// Modify the file using (var w = File.CreateText(f.LocalPath)) { w.WriteLine("fork it!"); w.Close(); } /// And make sure the lookup fails now! var r = await Lookup <int>(q, f, "test", null, null, query, new DummySaver()); Assert.IsTrue(r.Item1, "altered file should not have triggered the re-check"); }
public async Task CacheCycledInteger() { // A simple query var query = MakeQuery(0); var f = new Uri("http://www.nytimes.com"); // Cache an integer var h1 = new ROOTNET.NTH1F("hi", "there", 1, 0.0, 10.0) { Directory = null }; h1.SetBinContent(1, 5.0); var h2 = new ROOTNET.NTH1F("hi", "there", 1, 0.0, 10.0) { Directory = null }; h2.SetBinContent(1, 2.0); var cacheCycles = new NTObject[][] { new NTObject[] { h1 }, new NTObject[] { h2 } }; var q = new QueryResultCache(); var date = DateTime.Now; await q.CacheItem(q.GetKey(new Uri[] { f }, "test", null, null, query, dateChecker: u => date), cacheCycles.AsRunInfoArray2D()); // Now, do the lookup. var r = await Lookup <int>(q, f, "test", null, null, query, new DummySaver(), generateAdder : () => new DummyIntAdder()); Assert.IsTrue(r.Item1, "expected hit"); Assert.AreEqual(7, r.Item2, "incorrect return value"); }
public async Task TestForFileOutOfDate() { var u = MakeRootFile("TestForFileOutOfDate"); var f = new FileInfo(u.LocalPath); var query = MakeQuery(0); /// Cache a result var h = new ROOTNET.NTH1F("hi", "there", 10, 0.0, 10.0) { Directory = null }; h.SetBinContent(1, 5.0); var q = new QueryResultCache(); await q.CacheItem(q.GetKey(new Uri[] { u }, "test", null, null, query, dateChecker: uf => File.GetLastWriteTime(uf.LocalPath)), new NTObject[] { h }.AsRunInfoArray()); /// Modify the file using (var w = f.CreateText()) { w.WriteLine("fork it!"); w.Close(); } f.Refresh(); await Task.Delay(250); /// And make sure the lookup fails now! var r = await Lookup <int>(q, u, "test", null, null, query, new DummySaver(), checkDates : true); Assert.IsFalse(r.Item1, "altered file should have made this fail"); // Next, update the cache and look to make sure that the cache returns a hit this time! await q.CacheItem(q.GetKey(new Uri[] { u }, "test", null, null, query, dateChecker: uf => File.GetLastWriteTime(uf.LocalPath)), new NTObject[] { h }.AsRunInfoArray()); r = await Lookup <int>(q, u, "test", null, null, query, new DummySaver(), checkDates : true); Assert.IsTrue(r.Item1, "altered file should have made this fail"); }
public async Task TestForDiffHistos() { var f = MakeRootFile("TestForTreeNameChanges"); var query = MakeQuery(0); /// Histogram that is feed as input var hInput = new ROOTNET.NTH1F("ops", "notthere", 10, 0.0, 30.0) { Directory = null }; hInput.SetBinContent(2, 5.0); var inputs = new object[] { hInput }; /// Cache a result var h = new ROOTNET.NTH1F("hi", "there", 10, 0.0, 10.0) { Directory = null }; h.SetBinContent(1, 5.0); var q = new QueryResultCache(); await q.CacheItem(q.GetKey(new Uri[] { f }, "test", inputs, null, query, dateChecker: u => File.GetLastWriteTime(u.LocalPath)), new NTObject[] { h }.AsRunInfoArray()); /// And make sure the lookup works now! var hInputLookup = new ROOTNET.NTH1F("ops", "notthere", 10, 0.0, 30.0) { Directory = null }; hInputLookup.SetBinContent(2, 5.5); var r = await Lookup <int>(q, f, "test", new object[] { hInputLookup }, null, query, new DummySaver()); Assert.IsFalse(r.Item1, "Cache should have been there"); }
public async Task TestForNonTObjectCaching() { var f = MakeRootFile("TestForNonTObjectCaching"); var query = MakeQuery(0); /// Cache a result var h = new ROOTNET.NTLorentzVector(1.0, 2.0, 3.0, 4.0); var q = new QueryResultCache(); await q.CacheItem(q.GetKey(new Uri[] { f }, "test", null, null, query, dateChecker: u => File.GetLastWriteTime(u.LocalPath)), new NTObject[] { h }.AsRunInfoArray()); /// And make sure the lookup gets back the same object! var r = await Lookup <NTLorentzVector>(q, f, "test", null, null, query, new DummyHistoSaver()); Assert.IsTrue(r.Item1, "SHould get back the same object"); Assert.IsNotNull(r.Item2, "tlz should not be null"); Assert.AreEqual(1.0, r.Item2.X(), "x value"); Assert.AreEqual(2.0, r.Item2.Y(), "y value"); Assert.AreEqual(4.0, r.Item2.T(), "t value"); }
/// <summary> /// Look to see if we can figure out what the hit is on this Uri. /// </summary> /// <param name="queryIndex"></param> /// <param name="f"></param> private async Task TestForCachingOnUri(int queryIndex, Uri f) { var query = MakeQuery(queryIndex); /// Cache a result var h = new ROOTNET.NTH1F("hi", "there", 10, 0.0, 10.0) { Directory = null }; h.SetBinContent(1, 5.0); var q = new QueryResultCache(); var k = q.GetKey(new Uri[] { f }, "test", null, null, query, dateChecker: u => File.GetLastWriteTime(u.LocalPath)); await q.CacheItem(k, (new NTObject[] { h }).AsRunInfoArray()); var r = await Lookup <int>(q, f, "test", null, null, query, new DummySaver()); Assert.IsTrue(r.Item1, "expected hit"); Assert.AreEqual(5, r.Item2, "incorrect return value"); }
public async Task TestNoStuckInOpenFile() { // When we load up and return a cache, we are storing a histogram in the file - make sure it comes back w/out errors. var f = MakeRootFile("TestHitDriver"); var query = MakeQuery(0); // Cache a result var h = new ROOTNET.NTH1F("hi", "there", 10, 0.0, 10.0) { Directory = null }; h.SetBinContent(1, 5.0); var q = new QueryResultCache(); await q.CacheItem(q.GetKey(new Uri[] { f }, "test", null, null, query, dateChecker: u => File.GetLastWriteTime(u.LocalPath)), new NTObject[] { h }.AsRunInfoArray()); // Do the lookup. var r = await Lookup <ROOTNET.Interface.NTH1F>(q, f, "test", null, null, query, new DummyHistoSaver()); Assert.IsTrue(r.Item1, "expected hit"); Assert.AreEqual("hi", r.Item2.Name, "improper histogram came back"); }
public async Task TestForTreeNameChanges() { var f = MakeRootFile("TestForTreeNameChanges"); var query = MakeQuery(0); /// Cache a result var h = new ROOTNET.NTH1F("hi", "there", 10, 0.0, 10.0) { Directory = null }; h.SetBinContent(1, 5.0); var q = new QueryResultCache(); await q.CacheItem(q.GetKey(new Uri[] { f }, "test", null, null, query, dateChecker: u => File.GetLastWriteTime(u.LocalPath)), new NTObject[] { h }.AsRunInfoArray()); /// And make sure the lookup fails now! var r = await Lookup <int>(q, f, "test1", null, null, query, new DummySaver()); Assert.IsFalse(r.Item1, "different tree should have made this fail"); }
public async Task CacheCycleDuplicateCycles() { // We cannot give a list of items to cache that have the same // cycle number. // A simple query var query = MakeQuery(0); var f = new Uri("http://www.nytimes.com"); // Cache an integer var h1 = new ROOTNET.NTH1F("hi", "there", 1, 0.0, 10.0) { Directory = null }; h1.SetBinContent(1, 5.0); var h2 = new ROOTNET.NTH1F("hi", "there", 1, 0.0, 10.0) { Directory = null }; h2.SetBinContent(1, 2.0); var cacheCycles = new RunInfo[][] { new [] { new RunInfo() { _cycle = 0, _result = h1 } }, new [] { new RunInfo() { _cycle = 0, _result = h2 } } }; var q = new QueryResultCache(); var date = DateTime.Now; await q.CacheItem(q.GetKey(new Uri[] { f }, "test", null, null, query, dateChecker: u => date), cacheCycles); }
public async Task CacheWithVeryLongSourceFilename() { // A simple query var query = MakeQuery(0); var f = new Uri("http://www.nytimes.com/mc15_1111111111111111111111111111111111111111111111111111111111111111111111111113TeV_304810_MadGraphPythia8EvtGen_A14NNPDF23LO_HSS_LLP_mH400_mS50_lt5m_merge_DAOD_EXOT15_e5102_s2698_r7772_r7676_p2877?nFiles=1"); // Cache an integer var h = new ROOTNET.NTH1F("hi", "there", 1, 0.0, 10.0) { Directory = null }; h.SetBinContent(1, 5.0); var q = new QueryResultCache(); var date = DateTime.Now; await q.CacheItem(q.GetKey(new Uri[] { f }, "test", null, null, query, dateChecker: u => date), new NTObject[] { h }.AsRunInfoArray()); // Now, do the lookup. var r = await Lookup <int>(q, f, "test", null, null, query, new DummySaver()); Assert.IsTrue(r.Item1, "expected hit"); Assert.AreEqual(5, r.Item2, "incorrect return value"); }