CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <stdio.h>
15 #endif //USE_STORAGE_MANAGER defined
16 
17 
26 
27 #include <string>
28 #include <inttypes.h>
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::auto_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:
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();
130 
135  virtual void
136  produce(edm::Event& event, const edm::EventSetup& eventSetup);
137 
138 private:
143  void
145 
153  bool
154  getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool* fileChange =0);
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  int getCalibTriggerType(edm::Event& ev) const;
164 
167  void loadOrbitOffset();
168 
175  bool mseek(filepos_t offset, int whence = SEEK_SET, const char* mess = 0);
176 
177  bool mtell(filepos_t& pos);
178 
187  bool mread(char* buf, size_t n, const char* mess = 0, bool peek = false);
188 
189  bool mcheck(const std::string& name);
190 
191  bool mopen(const std::string& name);
192 
193  void mclose();
194 
195  bool misOpened();
196 
197  bool meof();
198 
199  bool mrewind();
200 
201  bool msize(filepos_t& s);
202 
203  void newRun(int prevRun, int newRun);
204 
205  static std::string runSubDir(uint32_t runNumber);
206 
207 private:
208  std::vector<std::string> fileNames_;
209 
213 
217 
220  bool timing_;
221 
224  bool disabled_;
225 
229 
233 
237 
242 
243 
248 
252  bool mergeRaw_;
253 
257 
259 
263 
264  static const int bufferSize = 30000; //must greater or equal to maximum
265  // matacq event size.
266  std::vector<unsigned char> data_;
268  const static int orbitTolerance_;
270  int32_t lastOrb_;
272 
274 
275  timeval startTime_;
276 
282 
285  std::map<uint32_t,uint32_t> orbitOffset_;
286 
290 
294 
295  static const int matacqFedId_ = 655;
296 
297  struct stats_t {
298  double nEvents;
301  } stats_;
302 
303  const static stats_t stats_init;
307 
310  std::ofstream logFile_;
311 
312 
316 
320 
326  timeval timer_;
327 
330  std::ofstream timeLog_;
331 
335 
338  uint32_t runNumber_;
339 };
340 
341 #endif
std::string inFileName_
std::map< uint32_t, uint32_t > orbitOffset_
uint32_t runNumber_
std::ofstream logFile_
static const int matacqFedId_
static const int orbitTolerance_
std::ofstream timeLog_
bool operator<(const MatacqEventId &a)
std::vector< std::string > fileNames_
bool ev
std::string digiInstanceName_
uint32_t getRunNumber(edm::Event &ev) const
uint32_t getOrbitId(edm::Event &ev) const
bool mcheck(const std::string &name)
struct MatacqProducer::stats_t stats_
int64_t pos(int orb) const
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
void addMatacqData(edm::Event &event)
static std::string runSubDir(uint32_t runNumber)
bool mread(char *buf, size_t n, const char *mess=0, bool peek=false)
virtual void produce(edm::Event &event, const edm::EventSetup &eventSetup)
edm::InputTag inputRawCollection_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::string orbitOffsetFile_
int getCalibTriggerType(edm::Event &ev) const
std::string timeLogFile_
bool operator>(const MatacqEventId &a)
MatacqDataFormatter formatter_
NullOut & operator<<(std::ostream &(*pf)(std::ostream &))
bool operator==(const MatacqEventId &a)
uint32_t openedFileRunNumber_
MatacqEventId(uint32_t r, uint32_t o)
int64_t IOOffset
Definition: IOTypes.h:19
PosEstimator posEstim_
void init(MatacqProducer *mp)
bool mtell(filepos_t &pos)
static const int bufferSize
MatacqProducer(const edm::ParameterSet &params)
bool mseek(filepos_t offset, int whence=SEEK_SET, const char *mess=0)
double a
Definition: hdecay.h:121
MatacqRawEvent matacq_
std::string rawInstanceName_
std::string logFileName_
bool msize(filepos_t &s)
std::vector< unsigned char > data_
void newRun(int prevRun, int newRun)
bool getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool *fileChange=0)
static const stats_t stats_init
long double T
NullOut & operator<<(const T &a)
bool mopen(const std::string &name)
bool getMatacqEvent(uint32_t runNumber, int32_t orbitId, bool fileChange)