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:
87  PosEstimator() : eventLength_(0), orbitStepMean_(0), firstOrbit_(0), invalid_(true), verbosity_(0) {}
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:
124  void addMatacqData(edm::Event& event);
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 
241  FILE_t inFile_;
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
std::string inFileName_
uint32_t runNumber_
std::ofstream logFile_
static const int orbitTolerance_
std::ofstream timeLog_
bool operator<(const MatacqEventId &a)
int init
Definition: HydjetWrapper.h:64
std::vector< std::string > fileNames_
bool ev
std::string digiInstanceName_
std::map< uint32_t, uint32_t > orbitOffset_
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
edm::InputTag inputRawCollection_
std::string orbitOffsetFile_
std::string timeLogFile_
bool operator>(const MatacqEventId &a)
def getRunNumber(filename)
MatacqDataFormatter formatter_
NullOut & operator<<(std::ostream &(*pf)(std::ostream &))
bool operator==(const MatacqEventId &a)
static const uint16_t invalid_
Definition: Constants.h:16
uint32_t openedFileRunNumber_
MatacqEventId(uint32_t r, uint32_t o)
int64_t IOOffset
Definition: IOTypes.h:19
PosEstimator posEstim_
double a
Definition: hdecay.h:119
MatacqRawEvent matacq_
std::string rawInstanceName_
std::string logFileName_
std::vector< unsigned char > data_
static const stats_t stats_init
long double T
NullOut & operator<<(const T &a)
Definition: event.py:1