CMS 3D CMS Logo

MatacqProducer.cc
Go to the documentation of this file.
1 //#define USE_STORAGE_MANAGER
2 
3 #ifdef USE_STORAGE_MANAGER
6 #else //USE_STORAGE_MANAGER not defined
7 #ifndef _LARGEFILE64_SOURCE
8 #define _LARGEFILE64_SOURCE
9 #endif //_LARGEFILE64_SOURCE not defined
10 #define _FILE_OFFSET_BITS 64
11 #include <cstdio>
12 #endif //USE_STORAGE_MANAGER defined
13 
21 
22 #include <string>
23 #include <cinttypes>
24 #include <fstream>
25 #include <memory>
26 
27 #include <sys/time.h>
28 
29 struct NullOut {
30  NullOut& operator<<(std::ostream& (*pf)(std::ostream&)) { return *this; }
31  template <typename T>
32  inline NullOut& operator<<(const T& a) {
33  return *this;
34  }
35 };
36 
38 public:
39  enum calibTrigType_t { laserType = 4, ledType = 5, tpType = 6, pedType = 7 };
40 
41 private:
42 #ifdef USE_STORAGE_MANAGER
43  typedef IOOffset filepos_t;
44  typedef std::unique_ptr<Storage> FILE_t;
45 #else
46  typedef off_t filepos_t;
47  typedef FILE* FILE_t;
48 #endif
49  struct MatacqEventId {
50  MatacqEventId() : run(0), orbit(0) {}
51  MatacqEventId(uint32_t r, uint32_t o) : run(r), orbit(o) {}
52 
55  uint32_t run;
56 
59  uint32_t orbit;
60 
61  bool operator<(const MatacqEventId& a) {
62  return (this->run < a.run) || ((this->run == a.run) && (this->orbit < a.orbit));
63  }
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) { return !((*this) < a || (*this) > a); }
70  };
71 
78  class PosEstimator {
79  //Note: a better estimate could be obtained by using segment of linear
80  //functions. In such implementation, the estimator must be updated
81  //each time a point with wrong estimate has been found.
82  public:
84  void init(MatacqProducer* mp);
85  bool invalid() const { return invalid_; }
86  int64_t pos(int orb) const;
87  int eventLength() const { return eventLength_; }
88  int firstOrbit() const { return firstOrbit_; }
89  void verbosity(int verb) { verbosity_ = verb; }
90 
91  private:
95  bool invalid_;
97  };
98 
99 public:
103  explicit MatacqProducer(const edm::ParameterSet& params);
104 
107  ~MatacqProducer() override;
108 
113  void produce(edm::Event& event, const edm::EventSetup& eventSetup) override;
114 
115 private:
121 
129  bool getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool* fileChange = nullptr);
130 
131  bool getMatacqEvent(uint32_t runNumber, int32_t orbitId, bool fileChange);
132  /*,bool doWrap = false, std::streamoff maxPos = -1);*/
133 
134  uint32_t getRunNumber(edm::Event& ev) const;
135  uint32_t getOrbitId(edm::Event& ev) const;
136 
137  bool getOrbitRange(uint32_t& firstOrb, uint32_t& lastOrb);
138 
139  int getCalibTriggerType(edm::Event& ev) const;
140 
143  void loadOrbitOffset();
144 
151  bool mseek(filepos_t offset, int whence = SEEK_SET, const char* mess = nullptr);
152 
153  bool mtell(filepos_t& pos);
154 
163  bool mread(char* buf, size_t n, const char* mess = nullptr, bool peek = false);
164 
165  bool mcheck(const std::string& name);
166 
167  bool mopen(const std::string& name);
168 
169  void mclose();
170 
171  bool misOpened();
172 
173  bool meof();
174 
175  bool mrewind();
176 
177  bool msize(filepos_t& s);
178 
179  void newRun(int prevRun, int newRun);
180 
181  static std::string runSubDir(uint32_t runNumber);
182 
183 private:
184  std::vector<std::string> fileNames_;
185 
189 
193 
196  bool timing_;
197 
200  bool disabled_;
201 
205 
209 
213 
218 
223 
227  bool mergeRaw_;
228 
232 
234 
238 
239  static const int bufferSize = 30000; //must greater or equal to maximum
240  // matacq event size.
241  std::vector<unsigned char> data_;
243  const static int orbitTolerance_;
245  int32_t lastOrb_;
247 
249 
250  timeval startTime_;
251 
257 
260  std::map<uint32_t, uint32_t> orbitOffset_;
261 
265 
269 
270  static const int matacqFedId_ = 655;
271 
272  struct stats_t {
273  double nEvents;
276  } stats_;
277 
278  const static stats_t stats_init;
282 
285  std::ofstream logFile_;
286 
290 
294 
300  timeval timer_;
301 
304  std::ofstream timeLog_;
305 
309 
312  uint32_t runNumber_;
313 };
314 
315 #include <csignal>
316 #include <cstdio>
317 #include <iomanip>
318 #include <iostream>
319 
320 #include <glob.h>
321 #include <sys/stat.h>
322 #include <sys/types.h>
323 #include <unistd.h>
324 
325 #include <fmt/printf.h>
326 #include <boost/algorithm/string.hpp>
327 
338 
339 using namespace std;
340 using namespace boost;
341 using namespace edm;
342 
343 // #undef LogInfo
344 // #define LogInfo(a) cout << "INFO " << a << ": "
345 // #undef LogWarning
346 // #define LogWarning(a) cout << "WARN " << a << ": "
347 // #undef LogDebug
348 // #define LogDebug(a) cout << "DBG " << a << ": "
349 
350 //verbose mode for matacq event retrieval debugging:
351 //static const bool searchDbg = false;
352 
353 //laser freq is 1 every 112 orbit => >80 orbit
354 const int MatacqProducer::orbitTolerance_ = 80;
355 
357 
358 static std::string now() {
359  struct timeval t;
360  gettimeofday(&t, nullptr);
361 
362  char buf[256];
363  strftime(buf, sizeof(buf), "%F %R %S s", localtime(&t.tv_sec));
364  buf[sizeof(buf) - 1] = 0;
365 
366  stringstream buf2;
367  buf2 << buf << " " << ((t.tv_usec + 500) / 1000) << " ms";
368 
369  return buf2.str();
370 }
371 
373  : fileNames_(params.getParameter<std::vector<std::string> >("fileNames")),
374  digiInstanceName_(params.getParameter<string>("digiInstanceName")),
375  rawInstanceName_(params.getParameter<string>("rawInstanceName")),
376  timing_(params.getUntrackedParameter<bool>("timing", false)),
377  disabled_(params.getParameter<bool>("disabled")),
378  verbosity_(params.getUntrackedParameter<int>("verbosity", 0)),
379  produceDigis_(params.getParameter<bool>("produceDigis")),
380  produceRaw_(params.getParameter<bool>("produceRaw")),
381  inputRawCollection_(params.getParameter<edm::InputTag>("inputRawCollection")),
382  mergeRaw_(params.getParameter<bool>("mergeRaw")),
383  ignoreTriggerType_(params.getParameter<bool>("ignoreTriggerType")),
384  matacq_(nullptr, 0),
385  inFile_(nullptr),
386  data_(bufferSize),
387  openedFileRunNumber_(0),
388  lastOrb_(0),
389  fastRetrievalThresh_(0),
390  orbitOffsetFile_(params.getUntrackedParameter<std::string>("orbitOffsetFile", "")),
391  inFileName_(""),
392  stats_(stats_init),
393  logFileName_(params.getUntrackedParameter<std::string>("logFileName", "matacqProducer.log")),
394  eventSkipCounter_(0),
395  onErrorDisablingEvtCnt_(params.getParameter<int>("onErrorDisablingEvtCnt")),
396  timeLogFile_(params.getUntrackedParameter<std::string>("timeLogFile", "")),
397  runNumber_(0) {
398  if (verbosity_ >= 4)
399  cout << "[Matacq " << now() << "] in MatacqProducer ctor" << endl;
400 
401  gettimeofday(&timer_, nullptr);
402 
403  if (!timeLogFile_.empty()) {
404  timeLog_.open(timeLogFile_.c_str());
405  if (timeLog_.fail()) {
406  cout << "[LaserSorter " << now() << "] "
407  << "Failed to open file " << timeLogFile_ << " to log timing.\n";
408  logTiming_ = false;
409  } else {
410  logTiming_ = true;
411  }
412  }
413 
415 
416  logFile_.open(logFileName_.c_str(), ios::app | ios::out);
417 
418  if (logFile_.bad()) {
419  throw cms::Exception("FileOpen") << "Failed to open file " << logFileName_ << " for logging.\n";
420  }
421 
422  inputRawCollectionToken_ = consumes<FEDRawDataCollection>(params.getParameter<InputTag>("inputRawCollection"));
423 
424  if (produceDigis_) {
425  if (verbosity_ > 0)
426  cout << "[Matacq " << now()
427  << "] registering new "
428  "EcalMatacqDigiCollection product with instance name '"
429  << digiInstanceName_ << "'\n";
430  produces<EcalMatacqDigiCollection>(digiInstanceName_);
431  }
432 
433  if (produceRaw_) {
434  if (verbosity_ > 0)
435  cout << "[Matacq " << now()
436  << "] registering new FEDRawDataCollection "
437  "product with instance name '"
438  << rawInstanceName_ << "'\n";
439  produces<FEDRawDataCollection>(rawInstanceName_);
440  }
441 
442  startTime_.tv_sec = startTime_.tv_usec = 0;
443  if (!orbitOffsetFile_.empty()) {
444  doOrbitOffset_ = true;
445  loadOrbitOffset();
446  } else {
447  doOrbitOffset_ = false;
448  }
449  if (verbosity_ >= 4)
450  cout << "[Matacq " << now() << "] exiting MatacqProducer ctor" << endl;
451 }
452 
454  if (verbosity_ >= 4)
455  cout << "[Matacq " << now() << "] in MatacqProducer::produce" << endl;
456  if (logTiming_) {
457  timeval t;
458  gettimeofday(&t, nullptr);
459 
460  timeLog_ << t.tv_sec << "." << setfill('0') << setw(3) << (t.tv_usec + 500) / 1000 << setfill(' ') << "\t"
461  << (t.tv_usec - timer_.tv_usec) * 1. + (t.tv_sec - timer_.tv_sec) * 1.e6 << "\t";
462  timer_ = t;
463  }
464 
465  if (startTime_.tv_sec == 0)
466  gettimeofday(&startTime_, nullptr);
467  ++stats_.nEvents;
468  if (disabled_)
469  return;
470  const uint32_t runNumber = getRunNumber(event);
471  if (runNumber != runNumber_) {
473  }
475 
476  if (logTiming_) {
477  timeval t;
478  gettimeofday(&t, nullptr);
479  timeLog_ << (t.tv_usec - timer_.tv_usec) * 1. + (t.tv_sec - timer_.tv_sec) * 1.e6 << "\n";
480  timer_ = t;
481  }
482 }
483 
486  event.getByToken(inputRawCollectionToken_, sourceColl);
487 
488  std::unique_ptr<FEDRawDataCollection> rawColl;
489  if (produceRaw_) {
490  if (mergeRaw_) {
491  rawColl = std::make_unique<FEDRawDataCollection>(*sourceColl);
492  } else {
493  rawColl = std::make_unique<FEDRawDataCollection>();
494  }
495  }
496 
497  auto digiColl = std::make_unique<EcalMatacqDigiCollection>();
498 
499  if (eventSkipCounter_ == 0) {
500  if (sourceColl->FEDData(matacqFedId_).size() > 4 && !produceRaw_) {
501  //input raw data collection already contains matacqData
503  } else {
504  bool isLaserEvent = (getCalibTriggerType(event) == laserType);
505 
506  // cout << "---> " << (ignoreTriggerType_?"yes":"no") << " " << getCalibTriggerType(event) << endl;
507 
508  if (isLaserEvent || ignoreTriggerType_) {
509  const uint32_t runNumber = getRunNumber(event);
510  const uint32_t orbitId = getOrbitId(event);
511 
512  LogInfo("Matacq") << "Run " << runNumber << "\t Orbit " << orbitId << "\n";
513 
514  bool fileChange;
515  if (doOrbitOffset_) {
516  map<uint32_t, uint32_t>::iterator it = orbitOffset_.find(runNumber);
517  if (it == orbitOffset_.end()) {
518  LogWarning("Matacq") << "Orbit offset not found for run " << runNumber
519  << ". No orbit correction will be applied.";
520  }
521  }
522 
523  if (getMatacqFile(runNumber, orbitId, &fileChange)) {
524  //matacq file retrieval succeeded
525  LogInfo("Matacq") << "Matacq data file found for "
526  << "run " << runNumber << " orbit " << orbitId;
527  if (getMatacqEvent(runNumber, orbitId, fileChange)) {
528  if (produceDigis_) {
530  }
531  if (produceRaw_) {
532  uint32_t dataLen64 = matacq_.getParsedLen();
533  if (dataLen64 > bufferSize * 8 || matacq_.getDccLen() != dataLen64) {
534  LogWarning("Matacq") << " Error in Matacq event fragment length! "
535  << "DCC len: " << matacq_.getDccLen()
536  << "*8 Bytes, Parsed len: " << matacq_.getParsedLen() << "*8 Bytes. "
537  << "Matacq data will not be included for this event.\n";
538  } else {
539  rawColl->FEDData(matacqFedId_).resize(dataLen64 * 8);
540  copy(data_.begin(), data_.begin() + dataLen64 * 8, rawColl->FEDData(matacqFedId_).data());
541  }
542  }
543  LogInfo("Matacq") << "Associating matacq data with orbit id " << matacq_.getOrbitId()
544  << " to dcc event with orbit id " << orbitId << std::endl;
545  if (isLaserEvent) {
547  } else {
549  }
550  } else {
551  if (isLaserEvent) {
552  LogWarning("Matacq") << "No matacq data found for laser event "
553  << "of run " << runNumber << " orbit " << orbitId;
554  }
555  }
556  } else {
557  LogWarning("Matacq") << "No matacq file found for event " << event.id();
558  }
559  }
560  }
561  if (eventSkipCounter_ > 0) { //error occured for this events
562  // and some events will be skipped following
563  // to this error.
564  LogInfo("Matacq") << " [" << now() << "] " << eventSkipCounter_
565  << " next events will be skipped, following to an "
566  << "error on the last processed event, "
567  << "which is expected to be persistant.";
568  }
569  } else {
571  }
572 
573  if (produceRaw_) {
574  if (verbosity_ > 1)
575  cout << "[Matacq " << now() << "] "
576  << "Adding FEDRawDataCollection collection "
577  << " to event.\n";
578  event.put(std::move(rawColl), rawInstanceName_);
579  }
580 
581  if (produceDigis_) {
582  if (verbosity_ > 1)
583  cout << "[Matacq " << now() << "] "
584  << "Adding EcalMatacqDigiCollection collection "
585  << " to event.\n";
586  event.put(std::move(digiColl), digiInstanceName_);
587  }
588 }
589 
590 // #if 0
591 // bool
592 // MatacqProducer::getMatacqEvent(std::ifstream& f,
593 // uint32_t runNumber,
594 // uint32_t orbitId,
595 // bool doWrap,
596 // std::streamoff maxPos){
597 // bool found = false;
598 // streampos startPos = f.tellg();
599 
600 // while(!f.eof()
601 // && !found
602 // && (maxPos<0 || f.tellg()<=maxPos)){
603 // const streamsize headerSize = 8*8;
604 // f.read((char*)&data_[0], headerSize);
605 // if(f.eof()) break;
606 // int32_t orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
607 // uint32_t len = MatacqRawEvent::getDccLen(&data_[0], headerSize);
608 // uint32_t run = MatacqRawEvent::getRunNum(&data_[0], headerSize);
609 // // cout << "Matacq: orbit = " << orb
610 // // << " len = " << len
611 // // << " run = " << run << endl;
612 // if((abs(orb-(int32_t)orbitId) < orbitTolerance_)
613 // && (runNumber==0 || runNumber==run)){
614 // found = true;
615 // //reads the rest of the event:
616 // if(data_.size() < len*8){
617 // throw cms::Exception("Matacq") << "Buffer overflow";
618 // }
619 // f.read((char*)&data_[0]+headerSize, len*8-headerSize);
620 // matacq_ = MatacqRawEvent((unsigned char*)&data_[0], len*8);
621 // } else{
622 // //moves to next event:
623 // f.seekg(len*8 - headerSize, ios::cur);
624 // }
625 // }
626 
627 // f.clear(); //clears eof error to allow seekg
628 // if(doWrap && !found){
629 // f.seekg(0, ios::beg);
630 // found = getMatacqEvent(f, runNumber, orbitId, false, startPos);
631 // }
632 // return found;
633 // }
634 //#endif
635 
636 bool MatacqProducer::getMatacqEvent(uint32_t runNumber, int32_t orbitId, bool fileChange) {
637  filepos_t startPos;
638  if (!mtell(startPos))
639  return false;
640 
641  int32_t startOrb = -1;
642  const size_t headerSize = 8 * 8;
643  if (mread((char*)&data_[0], headerSize, "Reading matacq header", true)) {
644  startOrb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
645  if (startOrb < 0)
646  startOrb = 0;
647  } else {
648  if (verbosity_ > 2) {
649  cout << "[Matacq " << now()
650  << "] Failed to read matacq header. Moved to start of "
651  " the file.\n";
652  }
653  mrewind();
654  if (mread((char*)&data_[0], headerSize, "Reading matacq header", true)) {
655  startPos = 0;
656  startOrb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
657  } else {
658  if (verbosity_ > 2)
659  cout << "[Matacq " << now() << "] Looks like matacq file is empty"
660  << "\n";
661  return false;
662  }
663  }
664 
665  if (verbosity_ > 2)
666  cout << "[Matacq " << now() << "] Last read orbit: " << lastOrb_ << " looking for orbit " << orbitId
667  << ". Current file position: " << startPos << " Orbit at current position: " << startOrb << "\n";
668 
669  // f.clear();
670  bool didCoarseMove = false;
671 
672  //FIXME: case where posEtim_.invalid() is false
673  if (!posEstim_.invalid() && (abs(lastOrb_ - orbitId) > fastRetrievalThresh_)) {
674  filepos_t pos = posEstim_.pos(orbitId);
675 
676  // struct stat st;
677  filepos_t fsize = -1;
678  // if(0==stat(inFileName_.c_str(), &st)){
679  if (msize(fsize)) {
680  // const int64_t fsize = st.st_size;
681  if (0 != posEstim_.eventLength() && pos > fsize) {
682  //estimated position is beyong end of file
683  //-> move to beginning of last event:
684  int64_t evtSize = posEstim_.eventLength() * sizeof(uint64_t);
685  pos = ((int64_t)fsize / evtSize - 1) * evtSize;
686  if (verbosity_ > 2) {
687  cout << "[Matacq " << now()
688  << "] Estimated position was beyond end of file. "
689  "Changed to "
690  << pos << "\n";
691  }
692  }
693  } else {
694  LogWarning("Matacq") << "Failed to access file " << inFileName_ << ".";
695  }
696  if (pos >= 0) {
697  if (verbosity_ > 2)
698  cout << "[Matacq " << now() << "] jumping to estimated position " << pos << "\n";
699  mseek(pos, SEEK_SET, "Jumping to estimated event position");
700  if (mread((char*)&data_[0], headerSize, "Reading matacq header", true)) {
701  didCoarseMove = true;
702  } else {
703  //estimated position might have been beyond the end of the file,
704  //try, with original position:
705  didCoarseMove = false;
706  if (!mread((char*)&data_[0], headerSize, "Reading event header", true)) {
707  return false;
708  }
709  }
710  } else {
711  if (verbosity_)
712  cout << "[Matacq " << now()
713  << "] Event orbit outside of orbit range "
714  "of matacq data file events\n";
715  return false;
716  }
717  }
718 
719  int32_t orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
720 
721  if (didCoarseMove) {
722  //autoadjustement of threshold for coarse move:
723  if (abs(orb - orbitId) > fastRetrievalThresh_) {
724  if (verbosity_ > 2)
725  cout << "[Matacq " << now() << "] Fast retrieval threshold increased from " << fastRetrievalThresh_;
726  fastRetrievalThresh_ = 2 * abs(orb - orbitId);
727  if (verbosity_ > 2)
728  cout << " to " << fastRetrievalThresh_ << "\n";
729  }
730 
731  //if coarse move did not improve situation, rolls back:
732  if (startOrb > 0 && (abs(orb - orbitId) > abs(startOrb - orbitId))) {
733  if (verbosity_ > 2)
734  cout << "[Matacq " << now() << "] Estimation (-> orbit " << orb
735  << ") "
736  "was worst than original position (-> orbit "
737  << startOrb << "). Restoring position (" << startPos << ").\n";
738  mseek(startPos, SEEK_SET);
739  mread((char*)&data_[0], headerSize, "Reading event header", true);
740  orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
741  }
742  }
743 
744  bool searchBackward = (orb > orbitId) ? true : false;
745  //BEWARE: len must be signed, because we are using latter in the code (-len)
746  //expression
747  int len = (int)MatacqRawEvent::getDccLen(&data_[0], headerSize);
748 
749  if (len == 0) {
750  cout << "[Matacq " << now() << "] read DCC length is null! Cancels matacq event search "
751  << " and move matacq file pointer to beginning of the file. "
752  << "(" << __FILE__ << ":" << __LINE__ << ")."
753  << "\n";
754  //rewind(f);
755  mrewind();
756  return false;
757  }
758 
759  enum state_t { searching, found, failed } state = searching;
760 
761  while (state == searching) {
762  orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
763  len = (int)MatacqRawEvent::getDccLen(&data_[0], headerSize);
764  uint32_t run = MatacqRawEvent::getRunNum(&data_[0], headerSize);
765  if (verbosity_ > 3) {
766  filepos_t pos = -1;
767  mtell(pos);
768  cout << "[Matacq " << now() << "] Header read at file position " << pos << ": orbit = " << orb
769  << " len = " << len << "x8 Byte"
770  << " run = " << run << "\n";
771  }
772  if ((abs(orb - orbitId) < orbitTolerance_) && (runNumber == 0 || runNumber == run)) {
773  state = found;
774  lastOrb_ = orb;
775  //reads the rest of the event:
776  if ((int)data_.size() < len * 8) {
777  throw cms::Exception("Matacq") << "Buffer overflow";
778  }
779  if (verbosity_ > 2)
780  cout << "[Matacq " << now()
781  << "] Event found. Reading "
782  " matacq event."
783  << "\n";
784  if (!mread((char*)&data_[0], len * 8, "Reading matacq event")) {
785  if (verbosity_ > 2)
786  cout << "[Matacq " << now() << "] Failed to read matacq event."
787  << "\n";
788  state = failed;
789  }
790  matacq_ = MatacqRawEvent((unsigned char*)&data_[0], len * 8);
791  } else {
792  if ((searchBackward && (orb < orbitId)) || (!searchBackward && (orb > orbitId))) { //search ended
793  lastOrb_ = orb;
794  state = failed;
795  if (verbosity_ > 2)
796  cout << "[Matacq " << now() << "] No matacq data found for run " << run << ", orbit ID " << orbitId << "."
797  << "\n";
798  } else {
799  off_t offset = (searchBackward ? -len : len) * 8;
800  lastOrb_ = orb;
801  if (verbosity_ > 3) {
802  cout << "[Matacq " << now() << "] In matacq file, moving " << abs(offset) << " byte "
803  << (offset > 0 ? "forward" : "backward") << ".\n";
804  }
805 
806  if (mseek(offset, SEEK_CUR, (searchBackward ? "Moving to previous event" : "Moving to next event")) &&
807  mread((char*)&data_[0], headerSize, "Reading event header", true)) {
808  } else {
809  if (!searchBackward)
810  mseek(-len * 8, SEEK_CUR, "Moving to start of last complete event");
811  state = failed;
812  }
813  }
814  }
815  }
816 
817  if (state == found) {
818  filepos_t pos = -1;
819  filepos_t fsize = -1;
820  mtell(pos);
821  msize(fsize);
822  if (pos == fsize - 1) { //last byte.
823  if (verbosity_ > 2) {
824  cout << "[Matacq " << now()
825  << "] Event found was at the end of the file. Moving "
826  "stream position to beginning of this event."
827  << "\n";
828  }
829  mseek(-(int)len * 8 - 1, SEEK_CUR, "Moving to beginning of last matacq event");
830  }
831  }
832  return (state == found);
833 }
834 
835 bool MatacqProducer::getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool* fileChange) {
837  uint32_t firstOrb, lastOrb;
838  bool goodRange = getOrbitRange(firstOrb, lastOrb);
839  // if(orbitId < firstOrb || orbitId > lastOrb) continue;
840  if (goodRange && firstOrb <= orbitId && orbitId <= lastOrb) {
841  if (fileChange != nullptr)
842  *fileChange = false;
843  return misOpened();
844  }
845  }
846 
847  if (fileNames_.empty())
848  return false;
849 
850  const string runNumberFormat = "%08d{,_*}";
851  string sRunNumber = fmt::sprintf(runNumberFormat, runNumber);
852  //cout << "Run number string: " << sRunNumber << "\n";
853  bool found = false;
854  string fname;
855  uint32_t maxOrb = 0;
856  //we make two iterations to handle the case where the event is procesed
857  //before the matacq data are available. In such case we would have
858  //orbitId > maxOrb (maxOrb: orbit of last written matacq event)
859  // for(int itry = 0; itry < 2 && (orbitId > maxOrb); ++itry){
860  for (int itry = 0; itry < 1 && (orbitId > maxOrb); ++itry) {
861  if (itry > 0) {
862  int n_sec = 1;
863  std::cout << "[Matacq " << now() << "] Event orbit id (" << orbitId
864  << ") goes "
865  "beyound the range of available one. Waiting for "
866  << n_sec
867  << " seconds in case "
868  "it was not written yet to disk.";
869  sleep(n_sec);
870  }
871 
872  for (unsigned i = 0; i < fileNames_.size() && !found; ++i) {
873  fname = fileNames_[i];
874  boost::algorithm::replace_all(fname, "%run_subdir%", runSubDir(runNumber));
875  boost::algorithm::replace_all(fname, "%run_number%", sRunNumber);
876 
877  glob_t g;
878  int rc = glob(fname.c_str(), GLOB_BRACE, nullptr, &g);
879  if (rc) {
880  if (verbosity_ > 1) {
881  switch (rc) {
882  case GLOB_NOSPACE:
883  std::cout << "[Matacq " << now()
884  << "] Running out of memory while calling glob function to look for matacq file paths\n";
885  break;
886  case GLOB_ABORTED:
887  std::cout << "[Matacq " << now()
888  << "] Read error while calling glob function to look for matacq file paths\n";
889  break;
890  case GLOB_NOMATCH:
891  //ok. No message to report.
892  break;
893  }
894  continue;
895  }
896  } //rc
897  for (unsigned iglob = 0; iglob < g.gl_pathc; ++iglob) {
898  char* thePath = g.gl_pathv[iglob];
899  //FIXME: add sanity check on the path
900  static std::atomic<int> nOpenErrors{0};
901  const int maxOpenErrors = 50;
902  if (!mopen(thePath) && nOpenErrors < maxOpenErrors) {
903  std::cout << "[Matacq " << now() << "] Failed to open file " << thePath;
904  ++nOpenErrors;
905  if (nOpenErrors == maxOpenErrors) {
906  std::cout << nOpenErrors << "This is the " << maxOpenErrors
907  << "th occurence of this error. Report of this error is now disabled.\n";
908  } else {
909  std::cout << "\n";
910  }
911  }
912  uint32_t firstOrb;
913  uint32_t lastOrb;
914  bool goodRange = getOrbitRange(firstOrb, lastOrb);
915  std::cout << "Get orbit range " << (goodRange ? "succeeded" : "failed") << ". Range: " << firstOrb << "..."
916  << lastOrb << "\n";
917  if (goodRange && lastOrb > maxOrb)
918  maxOrb = lastOrb;
919  if (goodRange && firstOrb <= orbitId && orbitId <= lastOrb) {
920  found = true;
921  //continue;
922  fname = thePath;
923  if (verbosity_ > 1)
924  std::cout << "[Matacq " << now() << "] Switching to file " << fname << "\n";
925  break;
926  }
927  } //next iglob
928  globfree(&g);
929  } //next filenames
930  } //next itry
931 
932  if (found) {
933  LogInfo("Matacq") << "Uses matacq data file: '" << fname << "'\n";
934  } else {
935  if (verbosity_ >= 0)
936  cout << "[Matacq " << now()
937  << "] no matacq file found "
938  "for run "
939  << runNumber << ", orbit " << orbitId << "\n";
942  if (fileChange != nullptr)
943  *fileChange = false;
944  return false;
945  }
946 
947  if (found) {
949  lastOrb_ = 0;
950  posEstim_.init(this);
951  if (fileChange != nullptr)
952  *fileChange = true;
953  return true;
954  } else {
955  return false;
956  }
957 }
958 
959 uint32_t MatacqProducer::getRunNumber(edm::Event& ev) const { return ev.run(); }
960 
962  //on CVS HEAD (June 4, 08), class Event has a method orbitNumber()
963  //we could use here. The code would be shorten to:
964  //return ev.orbitNumber();
965  //we have to deal with what we have in current CMSSW releases:
967  ev.getByToken(inputRawCollectionToken_, rawdata);
968  if (!(rawdata.isValid())) {
969  throw cms::Exception("NotFound") << "No FED raw data collection found. ECAL raw data are "
970  "required to retrieve the orbit ID";
971  }
972 
973  int orbit = 0;
974  for (int id = 601; id <= 654; ++id) {
975  if (!FEDNumbering::inRange(id))
976  continue;
977  const FEDRawData& data = rawdata->FEDData(id);
978  const int orbitIdOffset64 = 3;
979  if (data.size() >= 8 * (orbitIdOffset64 + 1)) { //orbit id is in 4th 64-bit word
980  const unsigned char* pOrbit = data.data() + orbitIdOffset64 * 8;
981  int thisOrbit = pOrbit[0] | (pOrbit[1] << 8) | (pOrbit[2] << 16) | (pOrbit[3] << 24);
982  if (orbit != 0 && thisOrbit != 0 && abs(orbit - thisOrbit) > orbitTolerance_) {
983  //throw cms::Exception("EventCorruption")
984  // << "Orbit ID inconsitency in DCC headers";
985  LogWarning("EventCorruption") << "Orbit ID inconsitency in DCC headers";
986  orbit = 0;
987  break;
988  }
989  if (thisOrbit != 0)
990  orbit = thisOrbit;
991  }
992  }
993 
994  if (orbit == 0) {
995  // throw cms::Exception("NotFound")
996  // << "Failed to retrieve orbit ID of event "<< ev.id();
997  LogWarning("NotFound") << "Failed to retrieve orbit ID of event " << ev.id();
998  }
999  return orbit;
1000 }
1001 
1004  ev.getByToken(inputRawCollectionToken_, rawdata);
1005  if (!(rawdata.isValid())) {
1006  throw cms::Exception("NotFound") << "No FED raw data collection found. ECAL raw data are "
1007  "required to retrieve the trigger type";
1008  }
1009 
1011  for (int id = 601; id <= 654; ++id) {
1012  if (!FEDNumbering::inRange(id))
1013  continue;
1014  const FEDRawData& data = rawdata->FEDData(id);
1015  const int detailedTrigger32 = 5;
1016  if (data.size() >= 4 * (detailedTrigger32 + 1)) {
1017  const unsigned char* pTType = data.data() + detailedTrigger32 * 4;
1018  int tType = pTType[1] & 0x7;
1019  stat.add(tType);
1020  }
1021  }
1022  double p;
1023  int tType = stat.result(&p);
1024  if (p < 0) {
1025  //throw cms::Exception("NotFound") << "No ECAL DCC data found\n";
1026  LogWarning("NotFound") << "No ECAL DCC data found\n";
1027  tType = -1;
1028  }
1029  if (p < .8) {
1030  //throw cms::Exception("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
1031  LogWarning("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
1032  tType = -1;
1033  }
1034  return tType;
1035 }
1036 
1038  mp->mrewind();
1039 
1040  const size_t headerSize = 8 * 8;
1041  unsigned char data[headerSize];
1042  if (!mp->mread((char*)data, headerSize)) {
1043  if (verbosity_)
1044  cout << "[Matacq " << now() << "] reached end of file!\n";
1046  return;
1047  } else {
1050  if (verbosity_ > 1)
1051  cout << "[Matacq " << now() << "] First event orbit: " << firstOrbit_ << " event length: " << eventLength_
1052  << "*8 byte\n";
1053  }
1054 
1055  mp->mrewind();
1056 
1057  if (eventLength_ == 0) {
1058  if (verbosity_)
1059  cout << "[Matacq " << now() << "] event length is null!" << endl;
1060  return;
1061  }
1062 
1063  filepos_t s = -1;
1064  mp->msize(s);
1065 
1066  if (s == -1) {
1067  if (verbosity_)
1068  cout << "[Matacq " << now() << "] File is missing!" << endl;
1069  orbitStepMean_ = 0;
1070  return;
1071  } else if (s == 0) {
1072  if (verbosity_)
1073  cout << "[Matacq " << now() << "] File is empty!" << endl;
1074  orbitStepMean_ = 0;
1075  return;
1076  }
1077 
1078  //number of complete events:
1079  const unsigned nEvents = s / eventLength_ / 8;
1080 
1081  if (verbosity_ > 1)
1082  cout << "[Matacq " << now() << "] File size: " << s << " Number of events: " << nEvents << endl;
1083 
1084  //position of last complete events:
1085  off_t last = (nEvents - 1) * (off_t)eventLength_ * 8;
1086  mp->mseek(last,
1087  SEEK_SET,
1088  "Moving to beginning of last complete "
1089  "matacq event");
1090  if (!mp->mread((char*)data, headerSize, "Reading matacq header", true)) {
1091  LogWarning("Matacq") << "Fast matacq event retrieval failure. "
1092  "Falling back to safe retrieval mode.";
1093  orbitStepMean_ = 0;
1094  }
1095 
1096  int32_t lastOrb = MatacqRawEvent::getOrbitId(data, headerSize);
1097  int32_t lastLen = MatacqRawEvent::getDccLen(data, headerSize);
1098 
1099  if (verbosity_ > 1)
1100  cout << "[Matacq " << now() << "] Last event orbit: " << lastOrb << " last event length: " << lastLen << endl;
1101 
1102  //some consistency check
1103  if (lastLen != eventLength_) {
1104  LogWarning("Matacq")
1105  //throw cms::Exception("Matacq")
1106  << "Fast matacq event retrieval failure: it looks like "
1107  "the matacq file contains events of different sizes.";
1108  // " Falling back to safe retrieval mode.";
1109  invalid_ = false; //true;
1110  orbitStepMean_ = 112; //0;
1111  return;
1112  }
1113 
1114  orbitStepMean_ = (lastOrb - firstOrbit_) / nEvents;
1115 
1116  if (verbosity_ > 1)
1117  cout << "[Matacq " << now() << "] Orbit step mean: " << orbitStepMean_ << "\n";
1118 
1119  invalid_ = false;
1120 }
1121 
1122 int64_t MatacqProducer::PosEstimator::pos(int orb) const {
1123  if (orb < firstOrbit_)
1124  return -1;
1125  uint64_t r = orbitStepMean_ != 0 ? (((uint64_t)(orb - firstOrbit_)) / orbitStepMean_) * eventLength_ * 8 : 0;
1126  if (verbosity_ > 2)
1127  cout << "[Matacq " << now() << "] Estimated Position for orbit " << orb << ": " << r << endl;
1128  return r;
1129 }
1130 
1132  mclose();
1133  timeval t;
1134  gettimeofday(&t, nullptr);
1135  if (logTiming_ && startTime_.tv_sec != 0) {
1136  //not using logger, to allow timing with different logging options
1137  cout << "[Matacq " << now()
1138  << "] Time elapsed between first event and "
1139  "destruction of MatacqProducer: "
1140  << ((t.tv_sec - startTime_.tv_sec) * 1. + (t.tv_usec - startTime_.tv_usec) * 1.e-6) << "s\n";
1141  }
1142 }
1143 
1145  std::ifstream f(orbitOffsetFile_.c_str());
1146  if (f.bad()) {
1147  throw cms::Exception("Matacq") << "Failed to open orbit ID correction file '" << orbitOffsetFile_ << "'\n";
1148  }
1149 
1150  cout << "[Matacq " << now() << "] "
1151  << "Offset to substract to Matacq events Orbit ID: \n"
1152  << "#Run Number\t Offset\n";
1153 
1154  string s;
1155  stringstream buf;
1156  while (f.eof()) {
1157  getline(f, s);
1158  if (s[0] == '#') { //comment
1159  //skip line:
1160  f.ignore(numeric_limits<streamsize>::max(), '\n');
1161  continue;
1162  }
1163  buf.str("");
1164  buf << s;
1165  int run;
1166  int orbit;
1167  buf >> run;
1168  buf >> orbit;
1169  if (buf.bad()) {
1170  throw cms::Exception("Matacq") << "Syntax error in Orbit offset file '" << orbitOffsetFile_ << "'";
1171  }
1172  cout << run << "\t" << orbit << "\n";
1173  orbitOffset_.insert(pair<int, int>(run, orbit));
1174  }
1175 }
1176 
1177 #ifdef USE_STORAGE_MANAGER
1178 bool MatacqProducer::mseek(filepos_t offset, int whence, const char* mess) {
1179  if (0 == inFile_.get())
1180  return false;
1181  try {
1182  Storage::Relative wh;
1183  if (whence == SEEK_SET)
1184  wh = Storage::SET;
1185  else if (whence == SEEK_CUR)
1186  wh = Storage::CURRENT;
1187  else if (whence == SEEK_END)
1188  wh = Storage::END;
1189  else
1190  throw cms::Exception("Bug") << "Bug found in " << __FILE__ << ": " << __LINE__ << "\n";
1191 
1192  inFile_->position(offset, wh);
1193  } catch (cms::Exception& e) {
1194  if (verbosity_) {
1195  cout << "[Matacq " << now() << "] ";
1196  if (mess)
1197  cout << mess << ". ";
1198  cout << "Random access error on input matacq file. ";
1199  if (whence == SEEK_SET)
1200  cout << "Failed to seek absolute position " << offset;
1201  else if (whence == SEEK_CUR)
1202  cout << "Failed to move " << offset << " bytes forward";
1203  else if (whence == SEEK_END)
1204  cout << "Failed to seek position at " << offset << " bytes before end of file";
1205  cout << ". Reopening file. " << e.what() << "\n";
1206  mopen(inFileName_);
1207  return false;
1208  }
1209  }
1210  return true;
1211 }
1212 
1214  if (0 == inFile_.get())
1215  return false;
1216  pos = inFile_->position();
1217  return true;
1218 }
1219 
1220 bool MatacqProducer::mread(char* buf, size_t n, const char* mess, bool peek) {
1221  if (0 == inFile_.get())
1222  return false;
1223 
1224  filepos_t pos = -1;
1225  if (!mtell(pos))
1226  return false;
1227 
1228  bool rc = false;
1229  try {
1230  rc = (n == inFile_->xread(buf, n));
1231  } catch (cms::Exception& e) {
1232  if (verbosity_) {
1233  cout << "[Matacq " << now() << "] ";
1234  if (mess)
1235  cout << mess << ". ";
1236  cout << "Read failure from input matacq file: " << e.what() << "\n";
1237  }
1238  //recovering from error:
1239  mopen(inFileName_);
1240  mseek(pos);
1241  return false;
1242  }
1243  if (peek) { //asked to restore original file position
1244  mseek(pos);
1245  }
1246  return rc;
1247 }
1248 
1250  if (inFile_.get() == 0)
1251  return false;
1252  s = inFile_.get()->size();
1253  return true;
1254 }
1255 
1256 bool MatacqProducer::mrewind() {
1257  Storage* file = inFile_.get();
1258  if (file == 0)
1259  return false;
1260  try {
1261  file->rewind();
1262  } catch (cms::Exception e) {
1263  if (verbosity_)
1264  cout << "Exception cautgh while rewinding file " << inFileName_ << ": " << e.what() << ". "
1265  << "File will be reopened.";
1266  return mopen(inFileName_);
1267  }
1268  return true;
1269 }
1270 
1271 bool MatacqProducer::mcheck(const std::string& name) { return StorageFactory::get()->check(name); }
1272 
1273 bool MatacqProducer::mopen(const std::string& name) {
1274  //close already opened file if any:
1275  mclose();
1276 
1277  try {
1278  inFile_ = unique_ptr<Storage>(StorageFactory::get()->open(name, IOFlags::OpenRead));
1279  inFileName_ = name;
1280  } catch (cms::Exception& e) {
1281  LogWarning("Matacq") << e.what();
1282  inFile_.reset();
1283  inFileName_ = "";
1284  return false;
1285  }
1286  return true;
1287 }
1288 
1289 void MatacqProducer::mclose() {
1290  if (inFile_.get() != 0) {
1291  inFile_->close();
1292  inFile_.reset();
1293  }
1294 }
1295 
1296 bool MatacqProducer::misOpened() { return inFile_.get() != 0; }
1297 
1298 bool MatacqProducer::meof() {
1299  if (inFile_.get() == 0)
1300  return true;
1301  return inFile_->eof();
1302 }
1303 
1304 #else //USE_STORAGE_MANAGER not defined
1305 bool MatacqProducer::mseek(off_t offset, int whence, const char* mess) {
1306  if (nullptr == inFile_)
1307  return false;
1308  const int rc = fseeko(inFile_, offset, whence);
1309  if (rc != 0 && verbosity_) {
1310  cout << "[Matacq " << now() << "] ";
1311  if (mess)
1312  cout << mess << ". ";
1313  cout << "Random access error on input matacq file. "
1314  "Rewind file.\n";
1315  mrewind();
1316  }
1317  return rc == 0;
1318 }
1319 
1321  if (nullptr == inFile_)
1322  return false;
1323  pos = ftello(inFile_);
1324  return pos != -1;
1325 }
1326 
1327 bool MatacqProducer::mread(char* buf, size_t n, const char* mess, bool peek) {
1328  if (nullptr == inFile_)
1329  return false;
1330  off_t pos = ftello(inFile_);
1331  bool rc = (pos != -1) && (1 == fread(buf, n, 1, inFile_));
1332  if (!rc) {
1333  if (verbosity_) {
1334  cout << "[Matacq " << now() << "] ";
1335  if (mess)
1336  cout << mess << ". ";
1337  cout << "Read failure from input matacq file.\n";
1338  }
1339  clearerr(inFile_);
1340  }
1341  if (peek || !rc) { //need to restore file position
1342  if (0 != fseeko(inFile_, pos, SEEK_SET)) {
1343  if (verbosity_) {
1344  cout << "[Matacq " << now() << "] ";
1345  if (mess)
1346  cout << mess << ". ";
1347  cout << "Failed to restore file position of "
1348  "before read error. Rewind file.\n";
1349  }
1350  //rewind(inFile_.get());
1351  mrewind();
1352  lastOrb_ = 0;
1353  }
1354  }
1355  return rc;
1356 }
1357 
1359  if (nullptr == inFile_)
1360  return false;
1361  struct stat buf;
1362  if (0 != fstat(fileno(inFile_), &buf)) {
1363  s = 0;
1364  return false;
1365  } else {
1366  s = buf.st_size;
1367  return true;
1368  }
1369 }
1370 
1372  if (nullptr == inFile_)
1373  return false;
1374  clearerr(inFile_);
1375  return fseeko(inFile_, 0, SEEK_SET) != 0;
1376 }
1377 
1379  struct stat dummy;
1380  return 0 == stat(name.c_str(), &dummy);
1381  // if(stat(name.c_str(), &dummy)==0){
1382  // return true;
1383  // } else{
1384  // cout << "[Matacq " << now() << "] Failed to stat file '"
1385  // << name.c_str() << "'. "
1386  // << "Error " << errno << ": " << strerror(errno) << "\n";
1387  // return false;
1388  // }
1389 }
1390 
1392  if (inFile_ != nullptr)
1393  mclose();
1394  inFile_ = fopen(name.c_str(), "r");
1395  if (inFile_ != nullptr) {
1396  inFileName_ = name;
1397  return true;
1398  } else {
1399  inFileName_ = "";
1400  return false;
1401  }
1402 }
1403 
1405  if (inFile_ != nullptr)
1406  fclose(inFile_);
1407  inFile_ = nullptr;
1408 }
1409 
1410 bool MatacqProducer::misOpened() { return inFile_ != nullptr; }
1411 
1413  if (nullptr == inFile_)
1414  return true;
1415  return feof(inFile_) == 0;
1416 }
1417 
1418 #endif //USE_STORAGE_MANAGER defined
1419 
1421  int millions = runNumber / (1000 * 1000);
1422  int thousands = (runNumber - millions * 1000 * 1000) / 1000;
1423  int units = runNumber - millions * 1000 * 1000 - thousands * 1000;
1424  return fmt::sprintf("%03d/%03d/%03d", millions, thousands, units);
1425 }
1426 
1427 void MatacqProducer::newRun(int prevRun, int newRun) {
1428  runNumber_ = newRun;
1429  eventSkipCounter_ = 0;
1430  logFile_ << "[" << now() << "] Event count for run " << runNumber_ << ": "
1431  << "total: " << stats_.nEvents << ", "
1432  << "Laser event with Matacq data: " << stats_.nLaserEventsWithMatacq << ", "
1433  << "Non laser event (according to DCC header) with Matacq data: " << stats_.nNonLaserEventsWithMatacq << "\n"
1434  << flush;
1435 
1436  stats_.nEvents = 0;
1439 }
1440 
1441 bool MatacqProducer::getOrbitRange(uint32_t& firstOrb, uint32_t& lastOrb) {
1442  filepos_t pos = -1;
1443  filepos_t fsize = -1;
1444  mtell(pos);
1445  msize(fsize);
1446  const unsigned headerSize = 8 * 8;
1447  unsigned char header[headerSize];
1448  //FIXME: Don't we need here to rewind?
1449  mseek(0);
1450  if (!mread((char*)header, headerSize, nullptr, false))
1451  return false;
1452  firstOrb = MatacqRawEvent::getOrbitId(header, headerSize);
1453  int len = (int)MatacqRawEvent::getDccLen(header, headerSize);
1454  //number of complete events. If last event is partially written,
1455  //it won't be included in the count.
1456  unsigned nEvts = fsize / (len * 8);
1457  //Position of last complete event:
1458  filepos_t lastEvtPos = (filepos_t)(nEvts - 1) * len * 8;
1459  // std::cout << "Move to position : " << lastEvtPos
1460  // << "(" << (nEvts - 1) << "*" << len << "*" << 64 << ")"
1461  //<< "\n";
1462  mseek(lastEvtPos);
1463  filepos_t tmp;
1464  mtell(tmp);
1465  //std::cout << "New position, sizeof(tmp): " << tmp << "," << sizeof(tmp) << "\n";
1466  mread((char*)header, headerSize, nullptr, false);
1467  lastOrb = MatacqRawEvent::getOrbitId(header, headerSize);
1468 
1469  //restore file position:
1470  mseek(pos);
1471 
1472  return true;
1473 }
1474 
static const char runNumber_[]
std::string inFileName_
int64_t IOOffset
Definition: IOTypes.h:20
int getCalibTriggerType(edm::Event &ev) const
~MatacqProducer() override
std::ofstream logFile_
static const int matacqFedId_
static const int orbitTolerance_
std::ofstream timeLog_
Definition: CLHEP.h:16
bool mseek(filepos_t offset, int whence=SEEK_SET, const char *mess=nullptr)
bool getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool *fileChange=nullptr)
uint32_t getRunNumber(edm::Event &ev) const
bool operator<(const MatacqEventId &a)
bool getOrbitRange(uint32_t &firstOrb, uint32_t &lastOrb)
static unsigned getOrbitId(unsigned char *data, size_t size)
unsigned getDccLen() const
std::vector< std::string > fileNames_
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:48
std::vector< TString > glob(const std::string &pattern)
Definition: fileutil.cc:100
std::string digiInstanceName_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
int64_t pos(int orb) const
bool mcheck(const std::string &name)
struct MatacqProducer::stats_t stats_
bool mread(char *buf, size_t n, const char *mess=nullptr, bool peek=false)
std::map< uint32_t, uint32_t > orbitOffset_
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
void addMatacqData(edm::Event &event)
static std::string runSubDir(uint32_t runNumber)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::InputTag inputRawCollection_
std::string orbitOffsetFile_
void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Log< level::Info, false > LogInfo
const int nEvts
std::string timeLogFile_
bool operator>(const MatacqEventId &a)
unsigned long long uint64_t
Definition: Time.h:13
MatacqDataFormatter formatter_
NullOut & operator<<(std::ostream &(*pf)(std::ostream &))
bool operator==(const MatacqEventId &a)
uint32_t getOrbitId(edm::Event &ev) const
uint32_t openedFileRunNumber_
MatacqEventId(uint32_t r, uint32_t o)
PosEstimator posEstim_
void init(MatacqProducer *mp)
bool isValid() const
Definition: HandleBase.h:70
bool mtell(filepos_t &pos)
string fname
main script
static const int bufferSize
static bool inRange(int)
MatacqProducer(const edm::ParameterSet &params)
TString units(TString variable, Char_t axis)
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
static std::string now()
double a
Definition: hdecay.h:121
MatacqRawEvent matacq_
std::string rawInstanceName_
void interpretRawData(const FEDRawData &data, EcalMatacqDigiCollection &matacqDigiCollection)
unsigned getRunNum() const
uint32_t getOrbitId() const
#define get
Log< level::Warning, false > LogWarning
std::string logFileName_
bool msize(filepos_t &s)
std::vector< unsigned char > data_
void newRun(int prevRun, int newRun)
static const stats_t stats_init
tmp
align.sh
Definition: createJobs.py:716
long double T
NullOut & operator<<(const T &a)
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
bool mopen(const std::string &name)
bool getMatacqEvent(uint32_t runNumber, int32_t orbitId, bool fileChange)