/// <summary>
 /// Generate a proxy file. Capture the item first.
 /// </summary>
 /// <param name="rootFiles"></param>
 /// <param name="treeName"></param>
 /// <param name="queryDirectory"></param>
 /// <returns></returns>
 public override Task <FileInfo> GenerateProxyFile(Uri[] rootFiles, string treeName, DirectoryInfo queryDirectory)
 {
     SetConnectionString(rootFiles);
     TraceHelpers.TraceInfo(13, $"ExecuteQueuedQueriesForAScheme:  --> Proxy: {rootFiles[0].Host}", opt: TraceEventType.Start);
     return(base.GenerateProxyFile(rootFiles, treeName, queryDirectory));
 }
Example #2
0
 public WiqlVisitor(TraceHelpers log, Expression exp)
 {
     this.expression = exp;
     this.log        = log;
 }
Example #3
0
        /// <summary>
        /// The detailed code that runs the query.
        /// </summary>
        /// <param name="tSelectorClassName">Name of the TSelector object</param>
        /// <param name="outputFileInfo">Where the output results should be written for eventual reading</param>
        private async Task <Dictionary <string, ROOTNET.Interface.NTObject> > RunNtupleQuery(string tSelectorClassName, IEnumerable <KeyValuePair <string, object> > variablesToLoad,
                                                                                             string treeName, FileInfo[] rootFiles)
        {
            ///
            /// Create a new TSelector to run
            ///

            TraceHelpers.TraceInfo(18, "RunNtupleQuery: Startup - doing selector lookup");
            var cls = ROOTNET.NTClass.GetClass(tSelectorClassName);

            if (cls == null)
            {
                throw new InvalidOperationException("Unable find class '" + tSelectorClassName + "' in the ROOT TClass registry that was just successfully compiled - can't run ntuple query - major inconsistency");
            }

            var selector = cls.New() as ROOTNET.Interface.NTSelector;

            ///
            /// Create the chain and load file files into it.
            ///

            TraceHelpers.TraceInfo(19, "RunNtupleQuery: Creating the TChain");
            using (var tree = new ROOTNET.NTChain(treeName))
            {
                foreach (var f in rootFiles)
                {
                    tree.Add(f.FullName);
                }

                // If there are any objects we need to send to the selector, then send them on now
                TraceHelpers.TraceInfo(20, "RunNtupleQuery: Saving the objects we are going to ship over");
                var objInputList = new ROOTNET.NTList();
                selector.InputList = objInputList;

                using (await ROOTLock.LockAsync())
                {
                    ROOTNET.NTH1.AddDirectory(false);
                    foreach (var item in variablesToLoad)
                    {
                        var obj = item.Value as ROOTNET.Interface.NTNamed;
                        if (obj == null)
                        {
                            throw new InvalidOperationException("Can only deal with named objects");
                        }
                        var cloned = obj.Clone(item.Key);
                        objInputList.Add(cloned);
                    }
                }

                // Setup the cache for more efficient reading. We assume we are on a machine with plenty of memory
                // for this.
                tree.CacheSize = 1024 * 1024 * 100; // 100 MB cache
                if (LeafNames == null)
                {
                    tree.AddBranchToCache("*", true);
                }
                else
                {
                    foreach (var leaf in LeafNames)
                    {
                        tree.AddBranchToCache(leaf, true);
                    }
                }
                tree.StopCacheLearningPhase();

                // Always Do the async prefetching (this is off by default for some reason, but...).
                ROOTNET.Globals.gEnv.Value.SetValue("TFile.AsynchPrefetching", 1);

                // Finally, run the whole thing
                TraceHelpers.TraceInfo(21, "RunNtupleQuery: Running TSelector");
                if (Environment.BreakToDebugger)
                {
                    System.Diagnostics.Debugger.Break();
                }
                tree.Process(selector);
                TraceHelpers.TraceInfo(22, "RunNtupleQuery: Done");

                // If debug, dump some stats...
                if (Environment.CompileDebug)
                {
                    tree.PrintCacheStats();
                }

                //
                // Get the results and put them into a map for safe keeping!
                // Also, since we want the results to live beyond this guy, make sure that when
                // the selector is deleted the objects don't go away!
                //

                var results = new Dictionary <string, ROOTNET.Interface.NTObject>();
                foreach (var o in selector.OutputList)
                {
                    results[o.Name] = o;
                }
                selector.OutputList.SetOwner(false);

                return(results);
            }
        }