CMS 3D CMS Logo

DAQSourceModelsScouting.h
Go to the documentation of this file.
1 #ifndef EventFilter_Utilities_DAQSourceModelsScouting_h
2 #define EventFilter_Utilities_DAQSourceModelsScouting_h
3 
4 #include <memory>
5 
9 
10 namespace scouting {
11  struct muon {
12  uint32_t f;
13  uint32_t s;
14  };
15 
16  struct block {
17  uint32_t bx;
18  uint32_t orbit;
19  muon mu[16];
20  };
21 
22  struct masks {
23  static constexpr uint32_t phiext = 0x3ff;
24  static constexpr uint32_t pt = 0x1ff;
25  static constexpr uint32_t qual = 0xf;
26  static constexpr uint32_t etaext = 0x1ff;
27  static constexpr uint32_t etaextv = 0xff;
28  static constexpr uint32_t etaexts = 0x100;
29  static constexpr uint32_t iso = 0x3;
30  static constexpr uint32_t chrg = 0x1;
31  static constexpr uint32_t chrgv = 0x1;
32  static constexpr uint32_t index = 0x7f;
33  static constexpr uint32_t phi = 0x3ff;
34  static constexpr uint32_t eta = 0x1ff;
35  static constexpr uint32_t etav = 0xff;
36  static constexpr uint32_t etas = 0x100;
37  static constexpr uint32_t phiv = 0x1ff;
38  static constexpr uint32_t phis = 0x200;
39  static constexpr uint32_t sv = 0x3;
40  };
41 
42  struct shifts {
43  static constexpr uint32_t phiext = 0;
44  static constexpr uint32_t pt = 10;
45  static constexpr uint32_t qual = 19;
46  static constexpr uint32_t etaext = 23;
47  static constexpr uint32_t iso = 0;
48  static constexpr uint32_t chrg = 2;
49  static constexpr uint32_t chrgv = 3;
50  static constexpr uint32_t index = 4;
51  static constexpr uint32_t phi = 11;
52  static constexpr uint32_t eta = 21;
53  static constexpr uint32_t rsv = 30;
54  };
55 
56  struct gmt_scales {
57  static constexpr float pt_scale = 0.5;
58  static constexpr float phi_scale = 2. * M_PI / 576.;
59  static constexpr float eta_scale = 0.0870 / 8; //9th MS bit is sign
60  static constexpr float phi_range = M_PI;
61  };
62 
63  struct header_shifts {
64  static constexpr uint32_t bxmatch = 24;
65  static constexpr uint32_t mAcount = 16;
66  static constexpr uint32_t orbitmatch = 8;
67  static constexpr uint32_t mBcount = 0;
68  };
69 
70  struct header_masks {
71  static constexpr uint32_t bxmatch = 0xff << header_shifts::bxmatch;
72  static constexpr uint32_t mAcount = 0xf << header_shifts::mAcount;
73  static constexpr uint32_t orbitmatch = 0xff << header_shifts::orbitmatch;
74  static constexpr uint32_t mBcount = 0xf;
75  };
76 
77 } //namespace scouting
78 
80 public:
81  DataModeScoutingRun2Muon(DAQSource* daqSource) : DataMode(daqSource) {
82  dummyLVec_ = std::make_unique<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>>();
83  }
84 
86 
87  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
88  void readEvent(edm::EventPrincipal& eventPrincipal) override;
89 
90  int dataVersion() const override { return detectedFRDversion_; }
91  void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
92  detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
93  }
94 
95  uint32_t headerSize() const override { return FRDHeaderVersionSize[detectedFRDversion_]; }
96 
97  bool versionCheck() const override { return detectedFRDversion_ <= FRDHeaderMaxVersion; }
98 
99  uint64_t dataBlockSize() const override { return event_->size(); }
100 
101  void makeDataBlockView(unsigned char* addr,
102  size_t maxSize,
103  std::vector<uint64_t> const& fileSizes,
104  size_t fileHeaderSize) override {
107  eventCached_ = false;
108  nextEventView();
109  eventCached_ = true;
110  }
111 
112  bool nextEventView() override;
113  bool checksumValid() override;
114  std::string getChecksumError() const override;
115 
116  bool isRealData() const override { return event_->isRealData(); }
117 
118  uint32_t run() const override { return event_->run(); }
119 
120  //true for scouting muon
121  bool dataBlockCompleted() const override { return true; }
122 
123  bool requireHeader() const override { return true; }
124 
125  bool fitToBuffer() const override { return true; }
126 
127  bool dataBlockInitialized() const override { return true; }
128 
129  void setDataBlockInitialized(bool) override{};
130 
131  void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override { return; }
132 
133  void makeDirectoryEntries(std::vector<std::string> const& baseDirs, std::string const& runDir) override {}
134 
135  std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName, bool) const override {
136  return std::make_pair(true, std::vector<std::string>());
137  }
138 
139  char* readPayloadPos() { return (char*)event_->payload(); }
140 
141 private:
142  void unpackOrbit(BXVector<l1t::Muon>* muons, char* buf, size_t len);
143 
144  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_;
145  uint16_t detectedFRDversion_ = 0;
146  size_t headerSize_ = 0;
147  std::unique_ptr<FRDEventMsgView> event_;
148 
149  std::unique_ptr<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>> dummyLVec_;
150 
151  unsigned char* dataBlockAddr_ = nullptr;
152  size_t dataBlockMax_ = 0;
153  bool eventCached_ = false;
154 };
155 
157 public:
158  DataModeScoutingRun2Multi(DAQSource* daqSource) : DataMode(daqSource) {
159  dummyLVec_ = std::make_unique<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>>();
160  }
161 
163 
164  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
165  void readEvent(edm::EventPrincipal& eventPrincipal) override;
166 
167  int dataVersion() const override { return detectedFRDversion_; }
168  void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
169  detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
170  }
171 
172  uint32_t headerSize() const override { return FRDHeaderVersionSize[detectedFRDversion_]; }
173 
174  bool versionCheck() const override { return detectedFRDversion_ <= FRDHeaderMaxVersion; }
175 
176  uint64_t dataBlockSize() const override {
177  //TODO: adjust to multiple objects
178  return events_[0]->size();
179  }
180 
181  void makeDataBlockView(unsigned char* addr,
182  size_t maxSize,
183  std::vector<uint64_t> const& fileSizes,
184  size_t fileHeaderSize) override {
185  fileHeaderSize_ = fileHeaderSize;
186  numFiles_ = fileSizes.size();
187  //add offset address for each file payload
188  startAddrs_.clear();
189  startAddrs_.push_back(addr);
190  dataBlockAddrs_.clear();
191  dataBlockAddrs_.push_back(addr);
192  dataBlockMaxAddrs_.clear();
193  dataBlockMaxAddrs_.push_back(addr + fileSizes[0] - fileHeaderSize);
194  auto fileAddr = addr;
195  for (unsigned int i = 1; i < fileSizes.size(); i++) {
196  fileAddr += fileSizes[i - 1];
197  startAddrs_.push_back(fileAddr);
198  dataBlockAddrs_.push_back(fileAddr);
199  dataBlockMaxAddrs_.push_back(fileAddr + fileSizes[i] - fileHeaderSize);
200  }
201 
203  blockCompleted_ = false;
204  //set event cached as we set initial address here
205  bool result = makeEvents();
206  assert(result);
207  eventCached_ = true;
209  }
210 
211  bool nextEventView() override;
212  bool checksumValid() override;
213  std::string getChecksumError() const override;
214 
215  bool isRealData() const override {
216  assert(!events_.empty());
217  return events_[0]->isRealData();
218  }
219 
220  uint32_t run() const override {
221  assert(!events_.empty());
222  return events_[0]->run();
223  }
224 
225  //true for DAQ3 FRD
226  bool dataBlockCompleted() const override { return blockCompleted_; }
227 
228  bool requireHeader() const override { return true; }
229 
230  bool dataBlockInitialized() const override { return dataBlockInitialized_; }
231 
233 
234  void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override { return; }
235 
236  void makeDirectoryEntries(std::vector<std::string> const& baseDirs, std::string const& runDir) override {
237  //receive directory paths for multiple input files ('striped')
238  }
239 
240  std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName,
241  bool fileListMode) const override;
242 
243 private:
244  bool makeEvents();
245  void unpackMuonOrbit(BXVector<l1t::Muon>* muons, char* buf, size_t len);
246 
247  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_;
248  uint16_t detectedFRDversion_ = 0;
249  size_t headerSize_ = 0;
250  std::vector<std::unique_ptr<FRDEventMsgView>> events_;
251 
252  std::unique_ptr<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>>> dummyLVec_;
253 
254  unsigned char* dataBlockAddr_ = nullptr;
255 
256  //debugging
257  std::vector<unsigned char*> startAddrs_;
258  std::vector<unsigned char*> dataBlockAddrs_;
259  std::vector<unsigned char*> dataBlockMaxAddrs_;
260  size_t dataBlockMax_ = 0;
261  size_t fileHeaderSize_ = 0;
262  short numFiles_ = 0;
263  bool eventCached_ = false;
264  bool dataBlockInitialized_ = false;
265  bool blockCompleted_ = true;
266 };
267 
268 #endif // EventFilter_Utilities_DAQSourceModelsScouting_h
static constexpr uint32_t orbitmatch
static constexpr uint32_t chrg
static constexpr uint32_t phis
bool isRealData() const override
void readEvent(edm::EventPrincipal &eventPrincipal) override
static constexpr uint32_t index
void makeDirectoryEntries(std::vector< std::string > const &baseDirs, std::string const &runDir) override
constexpr size_t FRDHeaderMaxVersion
void makeDirectoryEntries(std::vector< std::string > const &baseDirs, std::string const &runDir) override
static constexpr uint32_t bxmatch
static constexpr uint32_t etaexts
uint64_t dataBlockSize() const override
void unpackOrbit(BXVector< l1t::Muon > *muons, char *buf, size_t len)
static constexpr float pt_scale
static constexpr uint32_t etav
std::vector< unsigned char * > dataBlockAddrs_
static constexpr float phi_scale
bool dataBlockCompleted() const override
static constexpr uint32_t mBcount
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > daqProvenanceHelpers_
std::unique_ptr< ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > > dummyLVec_
bool versionCheck() const override
bool dataBlockInitialized() const override
void readEvent(edm::EventPrincipal &eventPrincipal) override
bool fitToBuffer() const override
assert(be >=bs)
void setDataBlockInitialized(bool) override
static constexpr uint32_t iso
DataModeScoutingRun2Multi(DAQSource *daqSource)
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > daqProvenanceHelpers_
void setDataBlockInitialized(bool val) override
static constexpr uint32_t eta
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > & makeDaqProvenanceHelpers() override
std::vector< std::unique_ptr< FRDEventMsgView > > events_
static constexpr uint32_t qual
static constexpr uint32_t orbitmatch
static constexpr uint32_t iso
void makeDataBlockView(unsigned char *addr, size_t maxSize, std::vector< uint64_t > const &fileSizes, size_t fileHeaderSize) override
static constexpr uint32_t chrgv
void unpackMuonOrbit(BXVector< l1t::Muon > *muons, char *buf, size_t len)
bool isRealData() const override
static constexpr uint32_t rsv
static constexpr uint32_t mAcount
uint32_t run() const override
static constexpr uint32_t index
static constexpr uint32_t phi
static constexpr uint32_t pt
std::vector< unsigned char * > dataBlockMaxAddrs_
std::pair< bool, std::vector< std::string > > defineAdditionalFiles(std::string const &primaryName, bool fileListMode) const override
static constexpr uint32_t chrgv
uint64_t dataBlockSize() const override
void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override
static constexpr uint32_t etaextv
static constexpr uint32_t phiext
void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override
DataModeScoutingRun2Muon(DAQSource *daqSource)
void detectVersion(unsigned char *fileBuf, uint32_t fileHeaderOffset) override
#define M_PI
std::vector< unsigned char * > startAddrs_
void detectVersion(unsigned char *fileBuf, uint32_t fileHeaderOffset) override
static constexpr uint32_t eta
bool requireHeader() const override
static constexpr uint32_t pt
static constexpr uint32_t sv
unsigned long long uint64_t
Definition: Time.h:13
uint32_t headerSize() const override
static constexpr uint32_t chrg
static constexpr uint32_t etaext
static constexpr uint32_t etaext
static constexpr uint32_t phiv
std::string getChecksumError() const override
bool versionCheck() const override
static constexpr uint32_t phiext
int dataVersion() const override
static constexpr uint32_t mAcount
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > & makeDaqProvenanceHelpers() override
static constexpr uint32_t mBcount
bool requireHeader() const override
static constexpr uint32_t etas
static constexpr uint32_t phi
bool dataBlockCompleted() const override
std::pair< bool, std::vector< std::string > > defineAdditionalFiles(std::string const &primaryName, bool) const override
constexpr std::array< uint32, FRDHeaderMaxVersion+1 > FRDHeaderVersionSize
bool dataBlockInitialized() const override
static constexpr uint32_t bxmatch
static constexpr float eta_scale
void makeDataBlockView(unsigned char *addr, size_t maxSize, std::vector< uint64_t > const &fileSizes, size_t fileHeaderSize) override
uint32_t run() const override
std::unique_ptr< FRDEventMsgView > event_
uint32_t headerSize() const override
std::string getChecksumError() const override
static constexpr float phi_range
std::unique_ptr< ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > > dummyLVec_
static constexpr uint32_t qual