Exemplo n.º 1
0
        /// <summary>
        /// Return all trees that are in a given directory. Make sure that if we have multiple
        /// cycles in the directory we only process the first one we encounter.
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        public IEnumerable <ROOTClassShell> ParseTDirectory(ROOTNET.Interface.NTDirectory dir)
        {
            var converter = new ParseTTree();

            converter.ProxyGenerationLocation = ProxyGenerationLocation;

            HashSet <string> seenTreeNames = new HashSet <string>();

            foreach (var key in dir.ListOfKeys.Cast <ROOTNET.Interface.NTKey>())
            {
                var c = ROOTNET.NTClass.GetClass(key.GetClassName());
                if (c != null)
                {
                    if (c.InheritsFrom("TTree"))
                    {
                        if (!seenTreeNames.Contains(key.Name))
                        {
                            seenTreeNames.Add(key.Name);
                            var t = key.ReadObj() as ROOTNET.Interface.NTTree;
                            if (t != null)
                            {
                                foreach (var cshell in converter.GenerateClasses(t))
                                {
                                    yield return(cshell);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new future directory container that will write its objects to the given root directory
        /// </summary>
        /// <remarks>
        /// In ROOT, when you create a new directory the gDirectory variable isn't changed; so the global directory
        /// will be unchanged by this operation.
        /// </remarks>
        /// <param name="dir"></param>
        public FutureTDirectory(ROOTNET.Interface.NTDirectory dir)
        {
            if (dir == null)
            {
                throw new ArgumentNullException("Can't create a new FutureTDirectory pointing to a null directory");
            }

            Directory = dir;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Search an input directory for a histogram or any ROOT object.
        /// </summary>
        /// <param name="?"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static object Get(ROOTNET.Interface.NTDirectory d, string path)
        {
            var h = d.Get(path);

            if (h == null)
            {
                throw new ArgumentException(string.Format("Unable to locate histogram '{0}' in directory '{1}'", path, d.Name));
            }
            return(h);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Attempt to find all the objects that are of type T or inherrit from T in the input file,
        /// and return them. Note that the file or owner of the directory needs to stay open as long as the sequence
        /// is being parsed!! This is an iterator, and processes on an as-need basis!!!
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rootDir"></param>
        /// <returns></returns>
        public static IEnumerable <T> FindAllOfType <T>(ROOTNET.Interface.NTDirectory rootDir)
            where T : ROOTNET.Interface.NTObject
        {
            var    objectKeys = rootDir.GetListOfKeys();
            string basename   = typeof(T).Name.Substring(1);

            foreach (var item in objectKeys.Cast <ROOTNET.Interface.NTKey>())
            {
                var c = ROOTNET.NTClass.GetClass(item.GetClassName());
                if (c.InheritsFrom(basename))
                {
                    yield return((T)item.ReadObj());
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Search an input directory for a histogram or any ROOT object whose name matches the regular expression name.
        /// Only does the matching in the current directory.
        /// </summary>
        /// <param name="d">Directory to search for</param>
        /// <param name="regularExpression"></param>
        /// <returns>List of objects that match the regular expression, including a zero length list.</returns>
        public static object[] GetAll(ROOTNET.Interface.NTDirectory d, string regularExpression)
        {
            var re = new Regex(regularExpression);

            var found = new List <object>();

            foreach (var key in d.ListOfKeys.Cast <ROOTNET.Interface.NTKey>())
            {
                if (!key.IsFolder() && re.Match(key.Name).Success)
                {
                    found.Add(d.Get(key.Name));
                }
            }
            return(found.ToArray());
        }
Exemplo n.º 6
0
 /// <summary>
 /// Do an immediate write to a root directory
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="obj"></param>
 /// <param name="dir"></param>
 public static void WriteToROOTDirectory <T>(this T obj, ROOTNET.Interface.NTDirectory dir)
     where T : ROOTNET.Interface.NTObject
 {
     obj.InternalWriteObject(dir);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Save a plot to a TDirectory. Return the plot so it can also be used in other
 /// places.
 ///
 /// Temp Fix: We need to set the object owner so that this object won't be cleaned up during
 /// GC, however, ROOT.NET doesn't support it yet. So instead we will just set it to null and
 /// return null for now. To be fixed when we update ROOT.NET.
 /// </summary>
 /// <param name="hist"></param>
 /// <param name="dir"></param>
 /// <returns></returns>
 public static ROOTNET.Interface.NTH1 SaveToROOTDirectory(this ROOTNET.Interface.NTH1 hist, ROOTNET.Interface.NTDirectory dir)
 {
     hist.InternalWriteObject(dir);
     return(null);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Add a histogram to a ROOT directory.
 /// </summary>
 /// <param name="dir"></param>
 /// <param name="h"></param>
 public static void Add(this ROOTNET.Interface.NTDirectory dir, ROOTNET.Interface.NTH1 h)
 {
     h.SetDirectory(dir);
 }
Exemplo n.º 9
0
 public void Save(ROOTNET.Interface.NTDirectory dir)
 {
     AsTObject.InternalWriteObject(dir);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Make pT and Eta histograms
        /// </summary>
        /// <param name="alljets"></param>
        /// <param name="p"></param>
        private static void MakeGenericHistos(IQueryable <ROOTNET.Interface.NBTagJet> alljets, string namePrefix, ROOTNET.Interface.NTDirectory dir)
        {
            var heta = alljets.ApplyToObject(new ROOTNET.NTH1F(namePrefix + "_eta", "\\Eta for " + namePrefix, 50, -5.0, 5.0), (h, x) => h.Fill(x.Eta()));

            heta.SetDirectory(dir);
            var hpt = alljets.ApplyToObject(new ROOTNET.NTH1F(namePrefix + "_pt", "p_{T} for " + namePrefix, 50, 0.0, 150.0), (h, x) => h.Fill(x.Pt() / 1000.0));

            hpt.SetDirectory(dir);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Write out an object. Eventually, with ROOTNET improvements this will work better and perahps
        /// won't be needed!
        /// </summary>
        /// <param name="obj">The object to be written. Assumed not null.</param>
        /// <param name="dir"></param>
        internal static void InternalWriteObject(this ROOTNET.Interface.NTObject obj, ROOTNET.Interface.NTDirectory dir)
        {
            if (obj == null)
            {
                Console.WriteLine("WARNING: Unable to write out null object to a TDirectory!");
                return;
            }

            using (ROOTLock.Lock())
            {
                if (obj is ROOTNET.Interface.NTH1 h)
                {
                    var copy = h.Clone();
                    dir.WriteTObject(copy); // Ugly from a memory pov, but...
                    copy.SetNull();
                }

                else
                {
                    dir.WriteTObject(obj);
                    obj.SetNull();
                }
            }
        }