CMS 3D CMS Logo

LaserSorter.h
Go to the documentation of this file.
1 /*
2  */
3 
4 #ifndef EVENT_SELECT_H
5 #define EVENT_SELECT_H
6 
7 #include <vector>
8 #include <iostream>
9 #include <fstream>
10 #include <cinttypes>
11 #include "boost/ptr_container/ptr_list.hpp"
12 
16 
20 
21 #include <sys/time.h>
22 #include <ctime>
23 #include <map>
24 
44 class LaserSorter : public edm::EDAnalyzer {
45  //inner classes
46 private:
47  struct IndexRecord {
48  uint32_t orbit;
49  uint32_t filePos;
50  bool operator<(const IndexRecord& i) const { return orbit < i.orbit; }
51  };
52 
54  public:
55  //default ctor
56  OutStreamRecord(int fedId__,
57  edm::LuminosityBlockNumber_t startingLumiBlock__,
58  std::ofstream* out__,
59  std::string& tmpFileName__,
60  std::string& finalFileName__)
61  : fedId_(fedId__),
62  startingLumiBlock_(startingLumiBlock__),
63  out_(out__),
64  tmpFileName_(tmpFileName__),
65  finalFileName_(finalFileName__),
66  indexError_(false) {
67  indices_.reserve(indexReserve_);
68  }
69 
70  int fedId() const { return fedId_; }
71  edm::LuminosityBlockNumber_t startingLumiBlock() const { return startingLumiBlock_; }
72  std::ofstream* out() const { return out_.get(); }
73  std::string finalFileName() const { return finalFileName_; }
74  std::string tmpFileName() const { return tmpFileName_; }
75  std::vector<IndexRecord>* indices() { return &indices_; }
76 
81  std::set<uint32_t>& excludedOrbit() { return excludedOrbit_; }
82 
83  private:
84  int fedId_;
86  std::unique_ptr<std::ofstream> out_;
89  const static std::string emptyString_;
90 
95  std::vector<IndexRecord> indices_;
96 
100  std::set<uint32_t> excludedOrbit_;
101 
106 
109  static const size_t indexReserve_;
110  };
111 
112  //typedefs:
113 private:
114  typedef boost::ptr_list<OutStreamRecord> OutStreamList;
115 
116  //ctors/dtors
117 public:
119  ~LaserSorter() override;
120 
121  //methods
122 public:
123  void analyze(const edm::Event&, const edm::EventSetup&) override;
124  void endJob() override;
125  void beginJob() override;
126  void beginRun(edm::Run const&, edm::EventSetup const&) override;
127 
128 private:
129  int dcc2Lme(int dccNum, int dccSide);
130 
136 
147  int getDetailedTriggerType(const edm::Handle<FEDRawDataCollection>& rawdata, double* proba = nullptr);
148 
153 
156  void closeAllStreams();
157 
165 
176  const edm::Event& event,
177  int detailedTriggerType,
178  const FEDRawDataCollection& data);
179 
185  bool writeFedBlock(std::ofstream& out, const FEDRawData& data);
186 
192  OutStreamList::iterator closeOutStream(OutStreamList::iterator streamRecord);
193 
202  OutStreamList::iterator createOutStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock);
203 
207  void writeFileHeader(std::ofstream& out);
208 
214  bool writeEventHeader(std::ofstream& out, const edm::Event& evt, int fedId, unsigned nFeds);
215 
223  void streamFileName(int fedId, edm::LuminosityBlockNumber_t lumiBlock, std::string& tmpName, std::string& finalName);
224 
234  bool isDccEventEmpty(const FEDRawData& data, size_t* dccLen = nullptr, int* nTowerBlocks = nullptr) const;
235 
240  void getOutputFedList(const edm::Event& event, const FEDRawDataCollection& data, std::vector<unsigned>& fedIds) const;
241 
250  bool readIndexTable(std::ifstream& in, std::string& inName, OutStreamRecord& outRcd, std::string* err);
251 
257  bool writeIndexTable(std::ofstream& out, std::vector<IndexRecord>& indices);
258 
259  bool renameAsBackup(const std::string& fileName, std::string& newFileName);
260 
266  int readFormatVersion(std::ifstream& in, const std::string& fileName);
267 
270  static std::string toString(uint64_t t);
271 
278  void restoreStreamsOfLumiBlock(int lumiBlock);
279 
284  std::vector<int> getFullyReadoutDccs(const FEDRawDataCollection& data) const;
285 
286  //fields
287 private:
290  static const int ecalDccFedIdMin_;
291 
294  static const int ecalDccFedIdMax_;
295 
299 
302  std::ofstream logFile_;
303 
307 
311 
315  OutStreamList outStreamList_;
316 
319  unsigned char formatVersion_;
320 
324 
327  std::vector<std::string> fedSubDirs_;
328 
332 
336 
340 
343  timeval timer_;
344 
347  std::ofstream timeLog_;
348 
351  bool timing_;
352 
356 
360 
364 
367  std::ofstream outputList_;
368 
369 #if 0
370 
372  bool storeFirstOrbitId_;
373 
376  std::ofstream firstOrbitOut_;
377 
380  std::string firstOrbitOutputFile_;
381 
384  uint32_t minOrbitId_;
385 
386 #endif
387 
391 
395 
399 
403 
416 
419 
422  static const int matacqFedId_ = 655;
423 
426  static const int indexOffset32_;
427 
431  static const unsigned maxEvents_ = 1 << 20;
432 
435  struct stats_t {
437  double nRead;
439  double nWritten;
447  double nRestoredDcc;
448  } stats_;
449  static const stats_t stats_init;
450 
454 
460 
461  int orbit_;
462 
470  struct timeval orbitZeroTime_;
471 };
472 
473 #endif //EVENT_SELECT_H not defined
void beginJob() override
Definition: LaserSorter.cc:891
edm::InputTag fedRawDataCollectionTag_
Definition: LaserSorter.h:417
OutStreamRecord * getStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:474
int lumiBlockSpan_
Definition: LaserSorter.h:415
bool disableOutput_
Definition: LaserSorter.h:335
std::vector< int > getFullyReadoutDccs(const FEDRawDataCollection &data) const
Definition: LaserSorter.cc:964
int maxFullReadoutDccError_
Definition: LaserSorter.h:394
double nRestoredDcc
number of events whose DCC ID was restored based on FED block sizes
Definition: LaserSorter.h:447
OutStreamRecord(int fedId__, edm::LuminosityBlockNumber_t startingLumiBlock__, std::ofstream *out__, std::string &tmpFileName__, std::string &finalFileName__)
Definition: LaserSorter.h:56
static std::string toString(uint64_t t)
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:290
std::set< uint32_t > excludedOrbit_
Definition: LaserSorter.h:100
static const int indexOffset32_
Definition: LaserSorter.h:426
bool writeIndexTable(std::ofstream &out, std::vector< IndexRecord > &indices)
Definition: LaserSorter.cc:976
edm::LuminosityBlockNumber_t startingLumiBlock_
Definition: LaserSorter.h:85
bool readIndexTable(std::ifstream &in, std::string &inName, OutStreamRecord &outRcd, std::string *err)
bool writeEvent(OutStreamRecord &out, const edm::Event &event, int detailedTriggerType, const FEDRawDataCollection &data)
Definition: LaserSorter.cc:499
edm::RunNumber_t runNumber_
Definition: LaserSorter.h:339
void writeFileHeader(std::ofstream &out)
Definition: LaserSorter.cc:732
std::ofstream * out() const
Definition: LaserSorter.h:72
void streamFileName(int fedId, edm::LuminosityBlockNumber_t lumiBlock, std::string &tmpName, std::string &finalName)
Definition: LaserSorter.cc:791
edm::LuminosityBlockNumber_t lumiBlock_
Definition: LaserSorter.h:306
std::set< uint32_t > & excludedOrbit()
Definition: LaserSorter.h:81
void getOutputFedList(const edm::Event &event, const FEDRawDataCollection &data, std::vector< unsigned > &fedIds) const
Definition: LaserSorter.cc:939
int dccNum[12][12]
static const int matacqFedId_
Definition: LaserSorter.h:422
OutStreamList::iterator closeOutStream(OutStreamList::iterator streamRecord)
Definition: LaserSorter.cc:838
unsigned int LuminosityBlockNumber_t
std::string finalFileName() const
Definition: LaserSorter.h:73
void closeAllStreams()
Definition: LaserSorter.cc:448
std::vector< std::string > fedSubDirs_
Definition: LaserSorter.h:327
std::vector< IndexRecord > indices_
Definition: LaserSorter.h:95
struct timeval orbitZeroTime_
Definition: LaserSorter.h:470
edm::LuminosityBlockNumber_t startingLumiBlock() const
Definition: LaserSorter.h:71
std::unique_ptr< std::ofstream > out_
Definition: LaserSorter.h:86
double nRead
number of events read out
Definition: LaserSorter.h:437
unsigned char formatVersion_
Definition: LaserSorter.h:319
~LaserSorter() override
Definition: LaserSorter.cc:156
std::vector< IndexRecord > * indices()
Definition: LaserSorter.h:75
int dcc2Lme(int dccNum, int dccSide)
Definition: LaserSorter.cc:350
std::string outputDir_
Definition: LaserSorter.h:323
timeval timer_
Definition: LaserSorter.h:343
bool writeFedBlock(std::ofstream &out, const FEDRawData &data)
Definition: LaserSorter.cc:552
std::string outputListFile_
Definition: LaserSorter.h:355
int getOrbitFromDcc(const edm::Handle< FEDRawDataCollection > &rawdata) const
Definition: LaserSorter.cc:381
std::string timeLogFile_
Definition: LaserSorter.h:331
static const std::string emptyString_
Definition: LaserSorter.h:89
void beginRun(edm::Run const &, edm::EventSetup const &) override
bool overWriteLumiBlockId_
Definition: LaserSorter.h:453
int iNoEcalDataMess_
Definition: LaserSorter.h:398
static const unsigned maxEvents_
Definition: LaserSorter.h:431
void closeOldStreams(edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:454
static const size_t indexReserve_
Definition: LaserSorter.h:109
static const stats_t stats_init
Definition: LaserSorter.h:449
int getDetailedTriggerType(const edm::Handle< FEDRawDataCollection > &rawdata, double *proba=nullptr)
Definition: LaserSorter.cc:404
boost::ptr_list< OutStreamRecord > OutStreamList
Definition: LaserSorter.h:114
LaserSorter(const edm::ParameterSet &)
Definition: LaserSorter.cc:74
int detailedTrigType_
Definition: LaserSorter.h:298
unsigned long long uint64_t
Definition: Time.h:15
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:294
std::ofstream outputList_
Definition: LaserSorter.h:367
int readFormatVersion(std::ifstream &in, const std::string &fileName)
std::ofstream logFile_
Definition: LaserSorter.h:302
int orbitCountInALumiBlock_
Definition: LaserSorter.h:459
void endJob() override
Definition: LaserSorter.cc:885
struct LaserSorter::stats_t stats_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool writeEventHeader(std::ofstream &out, const edm::Event &evt, int fedId, unsigned nFeds)
Definition: LaserSorter.cc:748
OutStreamList::iterator createOutStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:609
edm::LuminosityBlockNumber_t lumiBlockPrev_
Definition: LaserSorter.h:310
int maxNoEcalDataMess_
Definition: LaserSorter.h:402
unsigned int RunNumber_t
int iNoFullReadoutDccError_
Definition: LaserSorter.h:390
void restoreStreamsOfLumiBlock(int lumiBlock)
std::string tmpFileName() const
Definition: LaserSorter.h:74
bool doOutputList_
Definition: LaserSorter.h:359
double nWritten
number of events written out
Definition: LaserSorter.h:439
edm::EDGetTokenT< FEDRawDataCollection > fedRawDataCollectionToken_
Definition: LaserSorter.h:418
OutStreamList outStreamList_
Definition: LaserSorter.h:315
bool operator<(const IndexRecord &i) const
Definition: LaserSorter.h:50
std::ofstream timeLog_
Definition: LaserSorter.h:347
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: LaserSorter.cc:163
Definition: event.py:1
Definition: Run.h:45
bool renameAsBackup(const std::string &fileName, std::string &newFileName)
Definition: LaserSorter.cc:588
bool isDccEventEmpty(const FEDRawData &data, size_t *dccLen=nullptr, int *nTowerBlocks=nullptr) const
Definition: LaserSorter.cc:893