CMS 3D CMS Logo

MatacqProducer.h
Go to the documentation of this file.
1 #ifndef PRODUCER_H
2 #define PRODUCER_H
3 
4 //#define USE_STORAGE_MANAGER
5 
6 #ifdef USE_STORAGE_MANAGER
9 #else //USE_STORAGE_MANAGER not defined
10 #ifndef _LARGEFILE64_SOURCE
11 #define _LARGEFILE64_SOURCE
12 #endif //_LARGEFILE64_SOURCE not defined
13 #define _FILE_OFFSET_BITS 64
14 #include <cstdio>
15 #endif //USE_STORAGE_MANAGER defined
16 
25 
26 #include <string>
27 #include <cinttypes>
28 #include <fstream>
29 #include <memory>
30 
31 #include <sys/time.h>
32 
33 struct NullOut {
34  NullOut& operator<<(std::ostream& (*pf)(std::ostream&)) { return *this; }
35  template <typename T>
36  inline NullOut& operator<<(const T& a) {
37  return *this;
38  }
39 };
40 
42 public:
43  enum calibTrigType_t { laserType = 4, ledType = 5, tpType = 6, pedType = 7 };
44 
45 private:
46 #ifdef USE_STORAGE_MANAGER
47  typedef IOOffset filepos_t;
48  typedef std::unique_ptr<Storage> FILE_t;
49 #else
50  typedef off_t filepos_t;
51  typedef FILE* FILE_t;
52 #endif
53  struct MatacqEventId {
54  MatacqEventId() : run(0), orbit(0) {}
55  MatacqEventId(uint32_t r, uint32_t o) : run(r), orbit(o) {}
56 
59  uint32_t run;
60 
63  uint32_t orbit;
64 
65  bool operator<(const MatacqEventId& a) {
66  return (this->run < a.run) || ((this->run == a.run) && (this->orbit < a.orbit));
67  }
68 
69  bool operator>(const MatacqEventId& a) {
70  return (this->run > a.run) || ((this->run == a.run) && (this->orbit > a.orbit));
71  }
72 
73  bool operator==(const MatacqEventId& a) { return !((*this) < a || (*this) > a); }
74  };
75 
82  class PosEstimator {
83  //Note: a better estimate could be obtained by using segment of linear
84  //functions. In such implementation, the estimator must be updated
85  //each time a point with wrong estimate has been found.
86  public:
88  void init(MatacqProducer* mp);
89  bool invalid() const { return invalid_; }
90  int64_t pos(int orb) const;
91  int eventLength() const { return eventLength_; }
92  int firstOrbit() const { return firstOrbit_; }
93  void verbosity(int verb) { verbosity_ = verb; }
94 
95  private:
99  bool invalid_;
101  };
102 
103 public:
107  explicit MatacqProducer(const edm::ParameterSet& params);
108 
111  ~MatacqProducer() override;
112 
117  void produce(edm::Event& event, const edm::EventSetup& eventSetup) override;
118 
119 private:
125 
133  bool getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool* fileChange = nullptr);
134 
135  bool getMatacqEvent(uint32_t runNumber, int32_t orbitId, bool fileChange);
136  /*,bool doWrap = false, std::streamoff maxPos = -1);*/
137 
138  uint32_t getRunNumber(edm::Event& ev) const;
139  uint32_t getOrbitId(edm::Event& ev) const;
140 
141  bool getOrbitRange(uint32_t& firstOrb, uint32_t& lastOrb);
142 
143  int getCalibTriggerType(edm::Event& ev) const;
144 
147  void loadOrbitOffset();
148 
155  bool mseek(filepos_t offset, int whence = SEEK_SET, const char* mess = nullptr);
156 
157  bool mtell(filepos_t& pos);
158 
167  bool mread(char* buf, size_t n, const char* mess = nullptr, bool peek = false);
168 
169  bool mcheck(const std::string& name);
170 
171  bool mopen(const std::string& name);
172 
173  void mclose();
174 
175  bool misOpened();
176 
177  bool meof();
178 
179  bool mrewind();
180 
181  bool msize(filepos_t& s);
182 
183  void newRun(int prevRun, int newRun);
184 
185  static std::string runSubDir(uint32_t runNumber);
186 
187 private:
188  std::vector<std::string> fileNames_;
189 
193 
197 
200  bool timing_;
201 
204  bool disabled_;
205 
209 
213 
217 
222 
227 
231  bool mergeRaw_;
232 
236 
238 
242 
243  static const int bufferSize = 30000; //must greater or equal to maximum
244  // matacq event size.
245  std::vector<unsigned char> data_;
247  const static int orbitTolerance_;
249  int32_t lastOrb_;
251 
253 
254  timeval startTime_;
255 
261 
264  std::map<uint32_t, uint32_t> orbitOffset_;
265 
269 
273 
274  static const int matacqFedId_ = 655;
275 
276  struct stats_t {
277  double nEvents;
280  } stats_;
281 
282  const static stats_t stats_init;
286 
289  std::ofstream logFile_;
290 
294 
298 
304  timeval timer_;
305 
308  std::ofstream timeLog_;
309 
313 
316  uint32_t runNumber_;
317 };
318 
319 #endif
MatacqProducer::inFile_
FILE_t inFile_
Definition: MatacqProducer.h:241
MatacqProducer::inputRawCollectionToken_
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
Definition: MatacqProducer.h:226
MatacqProducer::PosEstimator
Definition: MatacqProducer.h:82
MatacqProducer::MatacqProducer
MatacqProducer(const edm::ParameterSet &params)
Definition: MatacqProducer.cc:62
MatacqProducer::getOrbitId
uint32_t getOrbitId(edm::Event &ev) const
Definition: MatacqProducer.cc:648
MatacqProducer::verbosity_
int verbosity_
Definition: MatacqProducer.h:208
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
EDProducer.h
MatacqProducer::runNumber_
uint32_t runNumber_
Definition: MatacqProducer.h:316
MatacqProducer::stats_
struct MatacqProducer::stats_t stats_
MatacqProducer::inFileName_
std::string inFileName_
Definition: MatacqProducer.h:272
MatacqProducer::getMatacqEvent
bool getMatacqEvent(uint32_t runNumber, int32_t orbitId, bool fileChange)
Definition: MatacqProducer.cc:326
MatacqProducer::orbitOffset_
std::map< uint32_t, uint32_t > orbitOffset_
Definition: MatacqProducer.h:264
MatacqProducer::stats_init
const static stats_t stats_init
Definition: MatacqProducer.h:282
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
MatacqProducer::misOpened
bool misOpened()
Definition: MatacqProducer.cc:1094
edm::EDGetTokenT< FEDRawDataCollection >
MatacqProducer::filepos_t
off_t filepos_t
Definition: MatacqProducer.h:50
pos
Definition: PixelAliasList.h:18
MatacqProducer::PosEstimator::firstOrbit_
int firstOrbit_
Definition: MatacqProducer.h:98
MatacqProducer::timeLogFile_
std::string timeLogFile_
Definition: MatacqProducer.h:301
MatacqProducer::mread
bool mread(char *buf, size_t n, const char *mess=nullptr, bool peek=false)
Definition: MatacqProducer.cc:1011
MatacqProducer::rawInstanceName_
std::string rawInstanceName_
Definition: MatacqProducer.h:196
MatacqProducer::timing_
bool timing_
Definition: MatacqProducer.h:200
MatacqProducer::mcheck
bool mcheck(const std::string &name)
Definition: MatacqProducer.cc:1062
NullOut::operator<<
NullOut & operator<<(std::ostream &(*pf)(std::ostream &))
Definition: MatacqProducer.h:34
NullOut
Definition: MatacqProducer.h:33
MatacqProducer::laserType
Definition: MatacqProducer.h:43
MatacqProducer::getMatacqFile
bool getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool *fileChange=nullptr)
Definition: MatacqProducer.cc:525
MatacqProducer::matacq_
MatacqRawEvent matacq_
Definition: MatacqProducer.h:237
MatacqProducer::PosEstimator::invalid
bool invalid() const
Definition: MatacqProducer.h:89
Storage.h
MatacqProducer::mtell
bool mtell(filepos_t &pos)
Definition: MatacqProducer.cc:1004
MatacqProducer::formatter_
MatacqDataFormatter formatter_
Definition: MatacqProducer.h:246
MatacqProducer::PosEstimator::eventLength_
int eventLength_
Definition: MatacqProducer.h:96
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
MatacqProducer::produce
void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
Definition: MatacqProducer.cc:143
MatacqProducer::PosEstimator::init
void init(MatacqProducer *mp)
Definition: MatacqProducer.cc:724
MatacqProducer::orbitTolerance_
const static int orbitTolerance_
Definition: MatacqProducer.h:247
MatacqProducer::MatacqEventId
Definition: MatacqProducer.h:53
MatacqProducer::logFile_
std::ofstream logFile_
Definition: MatacqProducer.h:289
alignCSCRings.s
s
Definition: alignCSCRings.py:92
MatacqProducer::openedFileRunNumber_
uint32_t openedFileRunNumber_
Definition: MatacqProducer.h:248
MatacqProducer::PosEstimator::verbosity_
int verbosity_
Definition: MatacqProducer.h:100
MatacqProducer::pedType
Definition: MatacqProducer.h:43
MatacqProducer::MatacqEventId::orbit
uint32_t orbit
Definition: MatacqProducer.h:63
MatacqProducer::MatacqEventId::run
uint32_t run
Definition: MatacqProducer.h:59
MatacqProducer::PosEstimator::orbitStepMean_
int orbitStepMean_
Definition: MatacqProducer.h:97
MatacqProducer
Definition: MatacqProducer.h:41
MatacqProducer::getOrbitRange
bool getOrbitRange(uint32_t &firstOrb, uint32_t &lastOrb)
Definition: MatacqProducer.cc:1125
MatacqProducer::posEstim_
PosEstimator posEstim_
Definition: MatacqProducer.h:252
MatacqProducer::logFileName_
std::string logFileName_
Definition: MatacqProducer.h:285
MatacqProducer::ignoreTriggerType_
bool ignoreTriggerType_
Definition: MatacqProducer.h:235
MatacqProducer::MatacqEventId::MatacqEventId
MatacqEventId()
Definition: MatacqProducer.h:54
MatacqProducer::FILE_t
FILE * FILE_t
Definition: MatacqProducer.h:51
MatacqProducer::meof
bool meof()
Definition: MatacqProducer.cc:1096
EDGetToken.h
MatacqProducer::logTiming_
bool logTiming_
Definition: MatacqProducer.h:312
MatacqRawEvent
Definition: MatacqRawEvent.h:30
MatacqProducer::timer_
timeval timer_
Definition: MatacqProducer.h:304
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MatacqProducer::MatacqEventId::MatacqEventId
MatacqEventId(uint32_t r, uint32_t o)
Definition: MatacqProducer.h:55
MatacqProducer::tpType
Definition: MatacqProducer.h:43
MatacqProducer::PosEstimator::PosEstimator
PosEstimator()
Definition: MatacqProducer.h:87
funct::true
true
Definition: Factorize.h:173
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
MatacqProducer::stats_t::nEvents
double nEvents
Definition: MatacqProducer.h:277
MatacqProducer::produceRaw_
bool produceRaw_
Definition: MatacqProducer.h:216
MatacqProducer::lastOrb_
int32_t lastOrb_
Definition: MatacqProducer.h:249
MatacqProducer::fileNames_
std::vector< std::string > fileNames_
Definition: MatacqProducer.h:188
MatacqProducer::fastRetrievalThresh_
int fastRetrievalThresh_
Definition: MatacqProducer.h:250
IOOffset
int64_t IOOffset
Definition: IOTypes.h:19
MatacqProducer::produceDigis_
bool produceDigis_
Definition: MatacqProducer.h:212
MatacqProducer::disabled_
bool disabled_
Definition: MatacqProducer.h:204
MatacqProducer::orbitOffsetFile_
std::string orbitOffsetFile_
Definition: MatacqProducer.h:260
MatacqProducer::runSubDir
static std::string runSubDir(uint32_t runNumber)
Definition: MatacqProducer.cc:1104
StorageFactory.h
MatacqProducer::onErrorDisablingEvtCnt_
int onErrorDisablingEvtCnt_
Definition: MatacqProducer.h:297
FEDRawDataCollection.h
MatacqProducer::PosEstimator::eventLength
int eventLength() const
Definition: MatacqProducer.h:91
MatacqProducer::eventSkipCounter_
int eventSkipCounter_
Definition: MatacqProducer.h:293
MatacqProducer::getRunNumber
uint32_t getRunNumber(edm::Event &ev) const
Definition: MatacqProducer.cc:646
NullOut::operator<<
NullOut & operator<<(const T &a)
Definition: MatacqProducer.h:36
MatacqProducer::PosEstimator::verbosity
void verbosity(int verb)
Definition: MatacqProducer.h:93
MatacqProducer::loadOrbitOffset
void loadOrbitOffset()
Definition: MatacqProducer.cc:826
edm::EventSetup
Definition: EventSetup.h:58
MatacqProducer::data_
std::vector< unsigned char > data_
Definition: MatacqProducer.h:245
MatacqProducer::matacqFedId_
static const int matacqFedId_
Definition: MatacqProducer.h:274
MatacqProducer::mrewind
bool mrewind()
Definition: MatacqProducer.cc:1055
MatacqRawEvent.h
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
MatacqProducer::stats_t
Definition: MatacqProducer.h:276
MatacqProducer::doOrbitOffset_
bool doOrbitOffset_
Definition: MatacqProducer.h:268
MatacqProducer::~MatacqProducer
~MatacqProducer() override
Definition: MatacqProducer.cc:813
InputTag.h
MatacqProducer::MatacqEventId::operator==
bool operator==(const MatacqEventId &a)
Definition: MatacqProducer.h:73
MatacqProducer::newRun
void newRun(int prevRun, int newRun)
Definition: MatacqProducer.cc:1111
MatacqProducer::ledType
Definition: MatacqProducer.h:43
alignCSCRings.r
r
Definition: alignCSCRings.py:93
MatacqProducer::mergeRaw_
bool mergeRaw_
Definition: MatacqProducer.h:231
MatacqProducer::stats_t::nNonLaserEventsWithMatacq
double nNonLaserEventsWithMatacq
Definition: MatacqProducer.h:279
MatacqProducer::addMatacqData
void addMatacqData(edm::Event &event)
Definition: MatacqProducer.cc:174
MatacqProducer::PosEstimator::invalid_
bool invalid_
Definition: MatacqProducer.h:99
MatacqProducer::PosEstimator::firstOrbit
int firstOrbit() const
Definition: MatacqProducer.h:92
packedPFCandidateRefMixer_cfi.pf
pf
Definition: packedPFCandidateRefMixer_cfi.py:4
T
long double T
Definition: Basic3DVectorLD.h:48
MatacqProducer::stats_t::nLaserEventsWithMatacq
double nLaserEventsWithMatacq
Definition: MatacqProducer.h:278
MatacqProducer::PosEstimator::pos
int64_t pos(int orb) const
Definition: MatacqProducer.cc:804
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
MatacqProducer::mseek
bool mseek(filepos_t offset, int whence=SEEK_SET, const char *mess=nullptr)
Definition: MatacqProducer.cc:989
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
MatacqProducer::timeLog_
std::ofstream timeLog_
Definition: MatacqProducer.h:308
edm::EDProducer
Definition: EDProducer.h:35
MatacqDataFormatter
Definition: MatacqDataFormatter.h:16
MatacqProducer::inputRawCollection_
edm::InputTag inputRawCollection_
Definition: MatacqProducer.h:221
MatacqProducer::startTime_
timeval startTime_
Definition: MatacqProducer.h:254
MatacqProducer::mopen
bool mopen(const std::string &name)
Definition: MatacqProducer.cc:1075
MatacqProducer::MatacqEventId::operator<
bool operator<(const MatacqEventId &a)
Definition: MatacqProducer.h:65
MatacqProducer::MatacqEventId::operator>
bool operator>(const MatacqEventId &a)
Definition: MatacqProducer.h:69
MatacqProducer::mclose
void mclose()
Definition: MatacqProducer.cc:1088
event
Definition: event.py:1
MatacqProducer::calibTrigType_t
calibTrigType_t
Definition: MatacqProducer.h:43
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
edm::Event
Definition: Event.h:73
MatacqProducer::msize
bool msize(filepos_t &s)
Definition: MatacqProducer.cc:1042
edm::InputTag
Definition: InputTag.h:15
MatacqProducer::bufferSize
static const int bufferSize
Definition: MatacqProducer.h:243
MatacqProducer::getCalibTriggerType
int getCalibTriggerType(edm::Event &ev) const
Definition: MatacqProducer.cc:689
MatacqProducer::digiInstanceName_
std::string digiInstanceName_
Definition: MatacqProducer.h:192
MatacqDataFormatter.h