CMS 3D CMS Logo

DiscretePFInputsIO.h
Go to the documentation of this file.
1 #ifndef L1Trigger_Phase2L1ParticleFlow_DiscretePFInputsIO_H
2 #define L1Trigger_Phase2L1ParticleFlow_DiscretePFInputsIO_H
3 
4 #include <cassert>
5 #include <cstdlib>
6 #include <cstdio>
7 
8 #include "DiscretePFInputs.h"
9 
10 namespace l1tpf_impl {
11  void writeToFile(const CaloCluster &c, FILE *file) {
12  fwrite(&c.hwPt, 2, 1, file);
13  fwrite(&c.hwEmPt, 2, 1, file);
14  fwrite(&c.hwPtErr, 2, 1, file);
15  fwrite(&c.hwEta, 2, 1, file);
16  fwrite(&c.hwPhi, 2, 1, file);
17  fwrite(&c.hwFlags, 2, 1, file);
18  fwrite(&c.isEM, 1, 1, file);
19  // used is not written out
20  // src is not written out
21  }
22  void readFromFile(CaloCluster &c, FILE *file) {
23  fread(&c.hwPt, 2, 1, file);
24  fread(&c.hwEmPt, 2, 1, file);
25  fread(&c.hwPtErr, 2, 1, file);
26  fread(&c.hwEta, 2, 1, file);
27  fread(&c.hwPhi, 2, 1, file);
28  fread(&c.hwFlags, 2, 1, file);
29  fread(&c.isEM, 1, 1, file);
30  c.used = false;
31  c.src = nullptr;
32  }
33 
34  void writeToFile(const InputTrack &t, FILE *file) {
35  fwrite(&t.hwInvpt, 2, 1, file);
36  fwrite(&t.hwVtxEta, 4, 1, file);
37  fwrite(&t.hwVtxPhi, 4, 1, file);
38  fwrite(&t.hwCharge, 1, 1, file);
39  fwrite(&t.hwZ0, 2, 1, file);
40  fwrite(&t.hwChi2, 2, 1, file);
41  fwrite(&t.hwStubs, 2, 1, file);
42  fwrite(&t.hwFlags, 2, 1, file);
43  // src is not written out
44  }
45  void readFromFile(InputTrack &t, FILE *file) {
46  fread(&t.hwInvpt, 2, 1, file);
47  fread(&t.hwVtxEta, 4, 1, file);
48  fread(&t.hwVtxPhi, 4, 1, file);
49  fread(&t.hwCharge, 1, 1, file);
50  fread(&t.hwZ0, 2, 1, file);
51  fread(&t.hwChi2, 2, 1, file);
52  fread(&t.hwStubs, 2, 1, file);
53  fread(&t.hwFlags, 2, 1, file);
54  t.src = nullptr;
55  }
56  void writeToFile(const PropagatedTrack &t, FILE *file) {
57  writeToFile(static_cast<const InputTrack &>(t), file);
58  fwrite(&t.hwPt, 2, 1, file);
59  fwrite(&t.hwPtErr, 2, 1, file);
60  fwrite(&t.hwCaloPtErr, 2, 1, file);
61  fwrite(&t.hwEta, 2, 1, file);
62  fwrite(&t.hwPhi, 2, 1, file);
63  // muonLink, used, fromPV are transient
64  }
66  readFromFile(static_cast<InputTrack &>(t), file);
67  fread(&t.hwPt, 2, 1, file);
68  fread(&t.hwPtErr, 2, 1, file);
69  fread(&t.hwCaloPtErr, 2, 1, file);
70  fread(&t.hwEta, 2, 1, file);
71  fread(&t.hwPhi, 2, 1, file);
72  t.muonLink = false;
73  t.used = false;
74  t.fromPV = false;
75  }
76 
77  void writeToFile(const Muon &m, FILE *file) {
78  fwrite(&m.hwPt, 2, 1, file);
79  fwrite(&m.hwEta, 2, 1, file);
80  fwrite(&m.hwPhi, 2, 1, file);
81  fwrite(&m.hwFlags, 2, 1, file);
82  fwrite(&m.hwCharge, 1, 1, file);
83  }
84  void readFromFile(Muon &m, FILE *file) {
85  fread(&m.hwPt, 2, 1, file);
86  fread(&m.hwEta, 2, 1, file);
87  fread(&m.hwPhi, 2, 1, file);
88  fread(&m.hwFlags, 2, 1, file);
89  fread(&m.hwCharge, 1, 1, file);
90  m.src = nullptr;
91  }
92 
93  void writeToFile(const float &pug, FILE *file) { fwrite(&pug, sizeof(float), 1, file); }
94  void readFromFile(float &pug, FILE *file) { fread(&pug, sizeof(float), 1, file); }
95 
96  template <typename T>
97  void writeManyToFile(const std::vector<T> &objs, FILE *file) {
98  uint32_t number = objs.size();
99  fwrite(&number, 4, 1, file);
100  for (uint32_t i = 0; i < number; ++i)
101  writeToFile(objs[i], file);
102  }
103 
104  template <typename T>
105  void readManyFromFile(std::vector<T> &objs, FILE *file) {
106  uint32_t number;
107  fread(&number, 4, 1, file);
108  objs.resize(number);
109  for (uint32_t i = 0; i < number; ++i)
110  readFromFile(objs[i], file);
111  }
112 
113  void writeToFile(const InputRegion &r, FILE *file) {
114  assert(4 == sizeof(float));
115  fwrite(&r.etaCenter, 4, 1, file);
116  fwrite(&r.etaMin, 4, 1, file);
117  fwrite(&r.etaMax, 4, 1, file);
118  fwrite(&r.phiCenter, 4, 1, file);
119  fwrite(&r.phiHalfWidth, 4, 1, file);
120  fwrite(&r.etaExtra, 4, 1, file);
121  fwrite(&r.phiExtra, 4, 1, file);
122  writeManyToFile(r.calo, file);
123  writeManyToFile(r.emcalo, file);
124  writeManyToFile(r.track, file);
125  writeManyToFile(r.muon, file);
126  }
127  void readFromFile(InputRegion &r, FILE *file) {
128  assert(4 == sizeof(float));
129  fread(&r.etaCenter, 4, 1, file);
130  fread(&r.etaMin, 4, 1, file);
131  fread(&r.etaMax, 4, 1, file);
132  fread(&r.phiCenter, 4, 1, file);
133  fread(&r.phiHalfWidth, 4, 1, file);
134  fread(&r.etaExtra, 4, 1, file);
135  fread(&r.phiExtra, 4, 1, file);
136  readManyFromFile(r.calo, file);
137  readManyFromFile(r.emcalo, file);
138  readManyFromFile(r.track, file);
139  readManyFromFile(r.muon, file);
140  }
141 
142 } // namespace l1tpf_impl
143 #endif
l1tpf_impl::readFromFile
void readFromFile(CaloCluster &c, FILE *file)
Definition: DiscretePFInputsIO.h:22
mps_fire.i
i
Definition: mps_fire.py:428
l1tpf_impl::PropagatedTrack
Definition: DiscretePFInputs.h:119
l1tpf_impl
Definition: BitwisePFAlgo.h:8
cms::cuda::assert
assert(be >=bs)
Muon
Definition: Muon.py:1
contentValuesFiles.number
number
Definition: contentValuesFiles.py:53
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
l1tpf_impl::readManyFromFile
void readManyFromFile(std::vector< T > &objs, FILE *file)
Definition: DiscretePFInputsIO.h:105
l1tpf_impl::writeManyToFile
void writeManyToFile(const std::vector< T > &objs, FILE *file)
Definition: DiscretePFInputsIO.h:97
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
l1tpf_impl::InputTrack
Definition: DiscretePFInputs.h:82
alignCSCRings.r
r
Definition: alignCSCRings.py:93
l1tpf_impl::CaloCluster
Definition: DiscretePFInputs.h:25
HLTEGTnPMonitor_cfi.objs
objs
Definition: HLTEGTnPMonitor_cfi.py:1018
l1tpf_impl::InputRegion
Definition: DiscretePFInputs.h:223
l1tpf_impl::writeToFile
void writeToFile(const CaloCluster &c, FILE *file)
Definition: DiscretePFInputsIO.h:11
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
DiscretePFInputs.h