1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#ifndef Shallow_Tree_h
#define Shallow_Tree_h
/** \class ShallowTree
*
* Makes a tree out of C++ standard types and vectors of C++ standard types
*
* This class, which is an EDAnalyzer, takes the same "keep" and
* "drop" outputCommands parameter as the PoolOutputSource, making a
* tree of the selected variables, which it obtains from the EDM
* tree.
*
* See the file python/test_cfg.py for an example configuration.
*
* See the file doc/README for more detailed documentation, including
* advantages, disadvantages, and use philosophy.
*
* \author Burt Betchart - University of Rochester <burton.andrew.betchart@cern.ch>
*/
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include <string>
#include <vector>
#include <TTree.h>
#include <memory>
class ShallowTree : public edm::one::EDAnalyzer<edm::one::SharedResources> {
private:
void analyze(const edm::Event&, const edm::EventSetup&) override;
template <class T>
void eat(edm::ProductDescription const& desc) {
consumes<T>(edm::InputTag(desc.moduleLabel(), desc.productInstanceName()));
}
class BranchConnector {
public:
virtual ~BranchConnector() {}
virtual void connect(const edm::Event&) = 0;
};
template <class T>
class TypedBranchConnector : public BranchConnector {
private:
std::string ml_; //module label
std::string pin_; //product instance name
T object_;
T* object_ptr_;
public:
TypedBranchConnector(edm::ProductDescription const*, std::string, TTree*);
void connect(const edm::Event&) override;
};
TTree* tree_;
std::vector<std::unique_ptr<BranchConnector>> connectors_;
public:
explicit ShallowTree(const edm::ParameterSet& iConfig); // : pset(iConfig) {}
enum LEAFTYPE {
BOOL = 1,
BOOL_V,
SHORT,
SHORT_V,
U_SHORT,
U_SHORT_V,
INT,
INT_V,
U_INT,
U_INT_V,
FLOAT,
FLOAT_V,
DOUBLE,
DOUBLE_V,
LONG,
LONG_V,
U_LONG,
U_LONG_V,
CHAR,
CHAR_V,
U_CHAR,
U_CHAR_V
};
};
#endif
|