Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:44:23

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 
0033 class ShallowTree : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0034 private:
0035   void analyze(const edm::Event&, const edm::EventSetup&) override;
0036 
0037   template <class T>
0038   void eat(edm::BranchDescription const* desc) {
0039     consumes<T>(edm::InputTag(desc->moduleLabel(), desc->productInstanceName()));
0040   }
0041 
0042   class BranchConnector {
0043   public:
0044     virtual ~BranchConnector(){};
0045     virtual void connect(const edm::Event&) = 0;
0046   };
0047 
0048   template <class T>
0049   class TypedBranchConnector : public BranchConnector {
0050   private:
0051     std::string ml;   //module label
0052     std::string pin;  //product instance name
0053     T object_;
0054     T* object_ptr_;
0055 
0056   public:
0057     TypedBranchConnector(edm::BranchDescription const*, std::string, TTree*);
0058     void connect(const edm::Event&) override;
0059   };
0060 
0061   edm::Service<TFileService> fs_;
0062   TTree* tree_;
0063   std::vector<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