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 
17 
26 
27 #include <string>
28 #include <cinttypes>
29 #include <fstream>
30 #include <memory>
31 
32 #include <sys/time.h>
33 
34 struct NullOut{
35  NullOut&
36  operator<<(std::ostream& (*pf)(std::ostream&)){
37  return *this;
38  }
39  template<typename T>
40  inline NullOut& operator<<(const T& a){
41  return *this;
42  }
43 };
44 
46 {
47 public:
49  laserType = 4,
50  ledType = 5,
51  tpType = 6,
52  pedType = 7
53  };
54 private:
55 #ifdef USE_STORAGE_MANAGER
56  typedef IOOffset filepos_t;
57  typedef std::unique_ptr<Storage> FILE_t;
58 #else
59  typedef off_t filepos_t;
60  typedef FILE* FILE_t;
61 #endif
62  struct MatacqEventId{
63  MatacqEventId(): run(0), orbit(0){}
64  MatacqEventId(uint32_t r, uint32_t o): run(r), orbit(o){}
65 
68  uint32_t run;
69 
72  uint32_t orbit;
73 
74  bool
76  return (this->run < a.run)
77  || ((this->run == a.run) && (this->orbit < a.orbit));
78  }
79 
80  bool
82  return (this->run > a.run)
83  || ((this->run == a.run) && (this->orbit > a.orbit));
84  }
85 
86  bool
88  return !((*this) < a || (*this) > a);
89  }
90  };
91 
92 
99  class PosEstimator{
100  //Note: a better estimate could be obtained by using segment of linear
101  //functions. In such implementation, the estimator must be updated
102  //each time a point with wrong estimate has been found.
103  public:
104  PosEstimator():eventLength_(0), orbitStepMean_(0), firstOrbit_(0),
105  invalid_(true), verbosity_(0) { }
106  void init(MatacqProducer* mp);
107  bool invalid() const { return invalid_; }
108  int64_t pos(int orb) const;
109  int eventLength() const { return eventLength_; }
110  int firstOrbit() const { return firstOrbit_; }
111  void verbosity(int verb) { verbosity_ = verb; }
112  private:
116  bool invalid_;
118  };
119 
120 public:
124  explicit
125  MatacqProducer(const edm::ParameterSet& params);
126 
129  ~MatacqProducer() override;
130 
135  void
136  produce(edm::Event& event, const edm::EventSetup& eventSetup) override;
137 
138 private:
143  void
144  addMatacqData(edm::Event& event);
145 
153  bool
154  getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool* fileChange =nullptr);
155 
156  bool
157  getMatacqEvent(uint32_t runNumber, int32_t orbitId,
158  bool fileChange);
159  /*,bool doWrap = false, std::streamoff maxPos = -1);*/
160 
161  uint32_t getRunNumber(edm::Event& ev) const;
162  uint32_t getOrbitId(edm::Event& ev) const;
163 
164 
165  bool getOrbitRange(uint32_t& firstOrb, uint32_t& lastOrb);
166 
167  int getCalibTriggerType(edm::Event& ev) const;
168 
171  void loadOrbitOffset();
172 
179  bool mseek(filepos_t offset, int whence = SEEK_SET, const char* mess = nullptr);
180 
181  bool mtell(filepos_t& pos);
182 
191  bool mread(char* buf, size_t n, const char* mess = nullptr, bool peek = false);
192 
193  bool mcheck(const std::string& name);
194 
195  bool mopen(const std::string& name);
196 
197  void mclose();
198 
199  bool misOpened();
200 
201  bool meof();
202 
203  bool mrewind();
204 
205  bool msize(filepos_t& s);
206 
207  void newRun(int prevRun, int newRun);
208 
209  static std::string runSubDir(uint32_t runNumber);
210 
211 private:
212  std::vector<std::string> fileNames_;
213 
217 
221 
224  bool timing_;
225 
228  bool disabled_;
229 
233 
237 
241 
246 
247 
252 
256  bool mergeRaw_;
257 
261 
263 
266  FILE_t inFile_;
267 
268  static const int bufferSize = 30000; //must greater or equal to maximum
269  // matacq event size.
270  std::vector<unsigned char> data_;
272  const static int orbitTolerance_;
274  int32_t lastOrb_;
276 
278 
279  timeval startTime_;
280 
286 
289  std::map<uint32_t,uint32_t> orbitOffset_;
290 
294 
298 
299  static const int matacqFedId_ = 655;
300 
301  struct stats_t {
302  double nEvents;
305  } stats_;
306 
307  const static stats_t stats_init;
311 
314  std::ofstream logFile_;
315 
316 
320 
324 
330  timeval timer_;
331 
334  std::ofstream timeLog_;
335 
339 
342  uint32_t runNumber_;
343 };
344 
345 #endif
std::string inFileName_
std::map< uint32_t, uint32_t > orbitOffset_
uint32_t runNumber_
std::ofstream logFile_
static const int orbitTolerance_
std::ofstream timeLog_
int init
Definition: HydjetWrapper.h:67
std::vector< std::string > fileNames_
bool ev
std::string digiInstanceName_
bool operator<(const FedChannelConnection &, const FedChannelConnection &)
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:121
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