Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-31 02:18:54

0001 #ifndef Shallow_Tree_h
0002 #define Shallow_Tree_h
0003 
0004 /** \class ShallowTree
0005  * 
0006  *  Makes a tree out of C++ standard types and vectors of C++ standard types
0007  *
0008  *  This class, which is an EDAnalyzer, takes the same "keep" and
0009  *  "drop" outputCommands parameter as the PoolOutputSource, making a
0010  *  tree of the selected variables, which it obtains from the EDM
0011  *  tree.  
0012  *
0013  *  See the file python/test_cfg.py for an example configuration.
0014  *
0015  *  See the file doc/README for more detailed documentation, including
0016  *  advantages, disadvantages, and use philosophy.
0017  *  
0018  *  \author Burt Betchart - University of Rochester <burton.andrew.betchart@cern.ch>
0019  */
0020 
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ServiceRegistry/interface/Service.h"
0026 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0027 #include "FWCore/Utilities/interface/InputTag.h"
0028 
0029 #include <string>
0030 #include <vector>
0031 #include <TTree.h>
0032 #include <memory>
0033 
0034 class ShallowTree : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0035 private:
0036   void analyze(const edm::Event&, const edm::EventSetup&) override;
0037 
0038   template <class T>
0039   void eat(edm::ProductDescription const& desc) {
0040     consumes<T>(edm::InputTag(desc.moduleLabel(), desc.productInstanceName()));
0041   }
0042 
0043   class BranchConnector {
0044   public:
0045     virtual ~BranchConnector() {}
0046     virtual void connect(const edm::Event&) = 0;
0047   };
0048 
0049   template <class T>
0050   class TypedBranchConnector : public BranchConnector {
0051   private:
0052     std::string ml_;   //module label
0053     std::string pin_;  //product instance name
0054     T object_;
0055     T* object_ptr_;
0056 
0057   public:
0058     TypedBranchConnector(edm::ProductDescription const*, std::string, TTree*);
0059     void connect(const edm::Event&) override;
0060   };
0061 
0062   TTree* tree_;
0063   std::vector<std::unique_ptr<BranchConnector>> connectors_;
0064 
0065 public:
0066   explicit ShallowTree(const edm::ParameterSet& iConfig);  // : pset(iConfig) {}
0067 
0068   enum LEAFTYPE {
0069     BOOL = 1,
0070     BOOL_V,
0071     SHORT,
0072     SHORT_V,
0073     U_SHORT,
0074     U_SHORT_V,
0075     INT,
0076     INT_V,
0077     U_INT,
0078     U_INT_V,
0079     FLOAT,
0080     FLOAT_V,
0081     DOUBLE,
0082     DOUBLE_V,
0083     LONG,
0084     LONG_V,
0085     U_LONG,
0086     U_LONG_V,
0087     CHAR,
0088     CHAR_V,
0089     U_CHAR,
0090     U_CHAR_V
0091   };
0092 };
0093 
0094 #endif