CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
MatacqProducer::PosEstimator Class Reference

Public Member Functions

int eventLength () const
 
int firstOrbit () const
 
void init (MatacqProducer *mp)
 
bool invalid () const
 
int64_t pos (int orb) const
 
 PosEstimator ()
 
void verbosity (int verb)
 

Private Attributes

int eventLength_
 
int firstOrbit_
 
bool invalid_
 
int orbitStepMean_
 
int verbosity_
 

Detailed Description

Estimates matacq event position in a file from its orbit id. This estimator requires that every event in the file has the same length. A linear extrapolation of pos=f(orbit) function from first and last event is performed. It gives only a rough estimate, relevant only to initiliaze the event search.

Definition at line 82 of file MatacqProducer.h.

Constructor & Destructor Documentation

MatacqProducer::PosEstimator::PosEstimator ( )
inline

Member Function Documentation

int MatacqProducer::PosEstimator::eventLength ( ) const
inline

Definition at line 91 of file MatacqProducer.h.

Referenced by MatacqProducer::getMatacqEvent().

int MatacqProducer::PosEstimator::firstOrbit ( ) const
inline

Definition at line 92 of file MatacqProducer.h.

void MatacqProducer::PosEstimator::init ( MatacqProducer mp)

Definition at line 726 of file MatacqProducer.cc.

References gather_cfg::cout, data, MatacqRawEvent::getDccLen(), MatacqRawEvent::getOrbitId(), sistrip::invalid_, dqmdumpme::last, MatacqProducer::mread(), MatacqProducer::mrewind(), MatacqProducer::mseek(), MatacqProducer::msize(), nEvents, now(), alignCSCRings::s, and MatacqProducer::verbosity_.

Referenced by MatacqProducer::getMatacqFile().

726  {
727  mp->mrewind();
728 
729  const size_t headerSize = 8 * 8;
730  unsigned char data[headerSize];
731  if (!mp->mread((char*)data, headerSize)) {
732  if (verbosity_)
733  cout << "[Matacq " << now() << "] reached end of file!\n";
735  return;
736  } else {
737  firstOrbit_ = MatacqRawEvent::getOrbitId(data, headerSize);
738  eventLength_ = MatacqRawEvent::getDccLen(data, headerSize);
739  if (verbosity_ > 1)
740  cout << "[Matacq " << now() << "] First event orbit: " << firstOrbit_ << " event length: " << eventLength_
741  << "*8 byte\n";
742  }
743 
744  mp->mrewind();
745 
746  if (eventLength_ == 0) {
747  if (verbosity_)
748  cout << "[Matacq " << now() << "] event length is null!" << endl;
749  return;
750  }
751 
752  filepos_t s;
753  mp->msize(s);
754 
755  //number of complete events:
756  const unsigned nEvents = s / eventLength_ / 8;
757 
758  if (nEvents == 0) {
759  if (verbosity_)
760  cout << "[Matacq " << now() << "] File is empty!" << endl;
761  orbitStepMean_ = 0;
762  return;
763  }
764 
765  if (verbosity_ > 1)
766  cout << "[Matacq " << now() << "] File size: " << s << " Number of events: " << nEvents << endl;
767 
768  //position of last complete events:
769  off_t last = (nEvents - 1) * (off_t)eventLength_ * 8;
770  mp->mseek(last,
771  SEEK_SET,
772  "Moving to beginning of last complete "
773  "matacq event");
774  if (!mp->mread((char*)data, headerSize, "Reading matacq header", true)) {
775  LogWarning("Matacq") << "Fast matacq event retrieval failure. "
776  "Falling back to safe retrieval mode.";
777  orbitStepMean_ = 0;
778  }
779 
780  int32_t lastOrb = MatacqRawEvent::getOrbitId(data, headerSize);
781  int32_t lastLen = MatacqRawEvent::getDccLen(data, headerSize);
782 
783  if (verbosity_ > 1)
784  cout << "[Matacq " << now() << "] Last event orbit: " << lastOrb << " last event length: " << lastLen << endl;
785 
786  //some consistency check
787  if (lastLen != eventLength_) {
788  LogWarning("Matacq")
789  //throw cms::Exception("Matacq")
790  << "Fast matacq event retrieval failure: it looks like "
791  "the matacq file contains events of different sizes.";
792  // " Falling back to safe retrieval mode.";
793  invalid_ = false; //true;
794  orbitStepMean_ = 112; //0;
795  return;
796  }
797 
798  orbitStepMean_ = (lastOrb - firstOrbit_) / nEvents;
799 
800  if (verbosity_ > 1)
801  cout << "[Matacq " << now() << "] Orbit step mean: " << orbitStepMean_ << "\n";
802 
803  invalid_ = false;
804 }
uint32_t getOrbitId() const
unsigned getDccLen() const
bool mread(char *buf, size_t n, const char *mess=0, bool peek=false)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
static std::string now()
bool mseek(filepos_t offset, int whence=SEEK_SET, const char *mess=0)
UInt_t nEvents
Definition: hcalCalib.cc:41
bool msize(filepos_t &s)
bool MatacqProducer::PosEstimator::invalid ( ) const
inline

Definition at line 89 of file MatacqProducer.h.

References sistrip::invalid_.

Referenced by MatacqProducer::getMatacqEvent().

int64_t MatacqProducer::PosEstimator::pos ( int  orb) const

Definition at line 806 of file MatacqProducer.cc.

References gather_cfg::cout, now(), alignCSCRings::r, and MatacqProducer::verbosity_.

Referenced by Vispa.Gui.PortWidget.PortWidget::connectionPoint(), Vispa.Gui.VispaWidget.VispaWidget::dragWidget(), MatacqProducer::getMatacqEvent(), and Vispa.Gui.VispaWidget.VispaWidget::paintEvent().

806  {
807  if (orb < firstOrbit_)
808  return -1;
809  uint64_t r = orbitStepMean_ != 0 ? (((uint64_t)(orb - firstOrbit_)) / orbitStepMean_) * eventLength_ * 8 : 0;
810  if (verbosity_ > 2)
811  cout << "[Matacq " << now() << "] Estimated Position for orbit " << orb << ": " << r << endl;
812  return r;
813 }
unsigned long long uint64_t
Definition: Time.h:13
static std::string now()
void MatacqProducer::PosEstimator::verbosity ( int  verb)
inline

Definition at line 93 of file MatacqProducer.h.

Referenced by MatacqProducer::MatacqProducer().

Member Data Documentation

int MatacqProducer::PosEstimator::eventLength_
private

Definition at line 96 of file MatacqProducer.h.

int MatacqProducer::PosEstimator::firstOrbit_
private

Definition at line 98 of file MatacqProducer.h.

bool MatacqProducer::PosEstimator::invalid_
private

Definition at line 99 of file MatacqProducer.h.

int MatacqProducer::PosEstimator::orbitStepMean_
private

Definition at line 97 of file MatacqProducer.h.

int MatacqProducer::PosEstimator::verbosity_
private

Definition at line 100 of file MatacqProducer.h.