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  int iline = 0;
1155  string s;
1156  stringstream buf;
1157  while (f.eof()) {
1158  getline(f, s);
1159  ++iline;
1160  if (s[0] == '#') { //comment
1161  //skip line:
1162  f.ignore(numeric_limits<streamsize>::max(), '\n');
1163  continue;
1164  }
1165  buf.str("");
1166  buf << s;
1167  int run;
1168  int orbit;
1169  buf >> run;
1170  buf >> orbit;
1171  if (buf.bad()) {
1172  throw cms::Exception("Matacq") << "Syntax error in Orbit offset file '" << orbitOffsetFile_ << "'";
1173  }
1174  cout << run << "\t" << orbit << "\n";
1175  orbitOffset_.insert(pair<int, int>(run, orbit));
1176  }
1177 }
1178 
1179 #ifdef USE_STORAGE_MANAGER
1180 bool MatacqProducer::mseek(filepos_t offset, int whence, const char* mess) {
1181  if (0 == inFile_.get())
1182  return false;
1183  try {
1184  Storage::Relative wh;
1185  if (whence == SEEK_SET)
1186  wh = Storage::SET;
1187  else if (whence == SEEK_CUR)
1188  wh = Storage::CURRENT;
1189  else if (whence == SEEK_END)
1190  wh = Storage::END;
1191  else
1192  throw cms::Exception("Bug") << "Bug found in " << __FILE__ << ": " << __LINE__ << "\n";
1193 
1194  inFile_->position(offset, wh);
1195  } catch (cms::Exception& e) {
1196  if (verbosity_) {
1197  cout << "[Matacq " << now() << "] ";
1198  if (mess)
1199  cout << mess << ". ";
1200  cout << "Random access error on input matacq file. ";
1201  if (whence == SEEK_SET)
1202  cout << "Failed to seek absolute position " << offset;
1203  else if (whence == SEEK_CUR)
1204  cout << "Failed to move " << offset << " bytes forward";
1205  else if (whence == SEEK_END)
1206  cout << "Failed to seek position at " << offset << " bytes before end of file";
1207  cout << ". Reopening file. " << e.what() << "\n";
1208  mopen(inFileName_);
1209  return false;
1210  }
1211  }
1212  return true;
1213 }
1214 
1216  if (0 == inFile_.get())
1217  return false;
1218  pos = inFile_->position();
1219  return true;
1220 }
1221 
1222 bool MatacqProducer::mread(char* buf, size_t n, const char* mess, bool peek) {
1223  if (0 == inFile_.get())
1224  return false;
1225 
1226  filepos_t pos = -1;
1227  if (!mtell(pos))
1228  return false;
1229 
1230  bool rc = false;
1231  try {
1232  rc = (n == inFile_->xread(buf, n));
1233  } catch (cms::Exception& e) {
1234  if (verbosity_) {
1235  cout << "[Matacq " << now() << "] ";
1236  if (mess)
1237  cout << mess << ". ";
1238  cout << "Read failure from input matacq file: " << e.what() << "\n";
1239  }
1240  //recovering from error:
1241  mopen(inFileName_);
1242  mseek(pos);
1243  return false;
1244  }
1245  if (peek) { //asked to restore original file position
1246  mseek(pos);
1247  }
1248  return rc;
1249 }
1250 
1252  if (inFile_.get() == 0)
1253  return false;
1254  s = inFile_.get()->size();
1255  return true;
1256 }
1257 
1258 bool MatacqProducer::mrewind() {
1259  Storage* file = inFile_.get();
1260  if (file == 0)
1261  return false;
1262  try {
1263  file->rewind();
1264  } catch (cms::Exception e) {
1265  if (verbosity_)
1266  cout << "Exception cautgh while rewinding file " << inFileName_ << ": " << e.what() << ". "
1267  << "File will be reopened.";
1268  return mopen(inFileName_);
1269  }
1270  return true;
1271 }
1272 
1273 bool MatacqProducer::mcheck(const std::string& name) { return StorageFactory::get()->check(name); }
1274 
1275 bool MatacqProducer::mopen(const std::string& name) {
1276  //close already opened file if any:
1277  mclose();
1278 
1279  try {
1280  inFile_ = unique_ptr<Storage>(StorageFactory::get()->open(name, IOFlags::OpenRead));
1281  inFileName_ = name;
1282  } catch (cms::Exception& e) {
1283  LogWarning("Matacq") << e.what();
1284  inFile_.reset();
1285  inFileName_ = "";
1286  return false;
1287  }
1288  return true;
1289 }
1290 
1291 void MatacqProducer::mclose() {
1292  if (inFile_.get() != 0) {
1293  inFile_->close();
1294  inFile_.reset();
1295  }
1296 }
1297 
1298 bool MatacqProducer::misOpened() { return inFile_.get() != 0; }
1299 
1300 bool MatacqProducer::meof() {
1301  if (inFile_.get() == 0)
1302  return true;
1303  return inFile_->eof();
1304 }
1305 
1306 #else //USE_STORAGE_MANAGER not defined
1307 bool MatacqProducer::mseek(off_t offset, int whence, const char* mess) {
1308  if (nullptr == inFile_)
1309  return false;
1310  const int rc = fseeko(inFile_, offset, whence);
1311  if (rc != 0 && verbosity_) {
1312  cout << "[Matacq " << now() << "] ";
1313  if (mess)
1314  cout << mess << ". ";
1315  cout << "Random access error on input matacq file. "
1316  "Rewind file.\n";
1317  mrewind();
1318  }
1319  return rc == 0;
1320 }
1321 
1323  if (nullptr == inFile_)
1324  return false;
1325  pos = ftello(inFile_);
1326  return pos != -1;
1327 }
1328 
1329 bool MatacqProducer::mread(char* buf, size_t n, const char* mess, bool peek) {
1330  if (nullptr == inFile_)
1331  return false;
1332  off_t pos = ftello(inFile_);
1333  bool rc = (pos != -1) && (1 == fread(buf, n, 1, inFile_));
1334  if (!rc) {
1335  if (verbosity_) {
1336  cout << "[Matacq " << now() << "] ";
1337  if (mess)
1338  cout << mess << ". ";
1339  cout << "Read failure from input matacq file.\n";
1340  }
1341  clearerr(inFile_);
1342  }
1343  if (peek || !rc) { //need to restore file position
1344  if (0 != fseeko(inFile_, pos, SEEK_SET)) {
1345  if (verbosity_) {
1346  cout << "[Matacq " << now() << "] ";
1347  if (mess)
1348  cout << mess << ". ";
1349  cout << "Failed to restore file position of "
1350  "before read error. Rewind file.\n";
1351  }
1352  //rewind(inFile_.get());
1353  mrewind();
1354  lastOrb_ = 0;
1355  }
1356  }
1357  return rc;
1358 }
1359 
1361  if (nullptr == inFile_)
1362  return false;
1363  struct stat buf;
1364  if (0 != fstat(fileno(inFile_), &buf)) {
1365  s = 0;
1366  return false;
1367  } else {
1368  s = buf.st_size;
1369  return true;
1370  }
1371 }
1372 
1374  if (nullptr == inFile_)
1375  return false;
1376  clearerr(inFile_);
1377  return fseeko(inFile_, 0, SEEK_SET) != 0;
1378 }
1379 
1381  struct stat dummy;
1382  return 0 == stat(name.c_str(), &dummy);
1383  // if(stat(name.c_str(), &dummy)==0){
1384  // return true;
1385  // } else{
1386  // cout << "[Matacq " << now() << "] Failed to stat file '"
1387  // << name.c_str() << "'. "
1388  // << "Error " << errno << ": " << strerror(errno) << "\n";
1389  // return false;
1390  // }
1391 }
1392 
1394  if (inFile_ != nullptr)
1395  mclose();
1396  inFile_ = fopen(name.c_str(), "r");
1397  if (inFile_ != nullptr) {
1398  inFileName_ = name;
1399  return true;
1400  } else {
1401  inFileName_ = "";
1402  return false;
1403  }
1404 }
1405 
1407  if (inFile_ != nullptr)
1408  fclose(inFile_);
1409  inFile_ = nullptr;
1410 }
1411 
1412 bool MatacqProducer::misOpened() { return inFile_ != nullptr; }
1413 
1415  if (nullptr == inFile_)
1416  return true;
1417  return feof(inFile_) == 0;
1418 }
1419 
1420 #endif //USE_STORAGE_MANAGER defined
1421 
1423  int millions = runNumber / (1000 * 1000);
1424  int thousands = (runNumber - millions * 1000 * 1000) / 1000;
1425  int units = runNumber - millions * 1000 * 1000 - thousands * 1000;
1426  return fmt::sprintf("%03d/%03d/%03d", millions, thousands, units);
1427 }
1428 
1429 void MatacqProducer::newRun(int prevRun, int newRun) {
1430  runNumber_ = newRun;
1431  eventSkipCounter_ = 0;
1432  logFile_ << "[" << now() << "] Event count for run " << runNumber_ << ": "
1433  << "total: " << stats_.nEvents << ", "
1434  << "Laser event with Matacq data: " << stats_.nLaserEventsWithMatacq << ", "
1435  << "Non laser event (according to DCC header) with Matacq data: " << stats_.nNonLaserEventsWithMatacq << "\n"
1436  << flush;
1437 
1438  stats_.nEvents = 0;
1441 }
1442 
1443 bool MatacqProducer::getOrbitRange(uint32_t& firstOrb, uint32_t& lastOrb) {
1444  filepos_t pos = -1;
1445  filepos_t fsize = -1;
1446  mtell(pos);
1447  msize(fsize);
1448  const unsigned headerSize = 8 * 8;
1449  unsigned char header[headerSize];
1450  //FIXME: Don't we need here to rewind?
1451  mseek(0);
1452  if (!mread((char*)header, headerSize, nullptr, false))
1453  return false;
1454  firstOrb = MatacqRawEvent::getOrbitId(header, headerSize);
1455  int len = (int)MatacqRawEvent::getDccLen(header, headerSize);
1456  //number of complete events. If last event is partially written,
1457  //it won't be included in the count.
1458  unsigned nEvts = fsize / (len * 8);
1459  //Position of last complete event:
1460  filepos_t lastEvtPos = (filepos_t)(nEvts - 1) * len * 8;
1461  // std::cout << "Move to position : " << lastEvtPos
1462  // << "(" << (nEvts - 1) << "*" << len << "*" << 64 << ")"
1463  //<< "\n";
1464  mseek(lastEvtPos);
1465  filepos_t tmp;
1466  mtell(tmp);
1467  //std::cout << "New position, sizeof(tmp): " << tmp << "," << sizeof(tmp) << "\n";
1468  mread((char*)header, headerSize, nullptr, false);
1469  lastOrb = MatacqRawEvent::getOrbitId(header, headerSize);
1470 
1471  //restore file position:
1472  mseek(pos);
1473 
1474  return true;
1475 }
1476 
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:45
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:79
static std::string now()
double a
Definition: hdecay.h:119
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)