CMS 3D CMS Logo

Public Member Functions | Private Attributes

MatacqProducer::PosEstimator Class Reference

List of all members.

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 105 of file MatacqProducer.h.


Constructor & Destructor Documentation

MatacqProducer::PosEstimator::PosEstimator ( ) [inline]

Definition at line 110 of file MatacqProducer.h.


Member Function Documentation

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

Definition at line 115 of file MatacqProducer.h.

References eventLength_.

Referenced by MatacqProducer::getMatacqEvent().

{ return eventLength_; }
int MatacqProducer::PosEstimator::firstOrbit ( ) const [inline]

Definition at line 116 of file MatacqProducer.h.

References firstOrbit_.

{ return firstOrbit_; }
void MatacqProducer::PosEstimator::init ( MatacqProducer mp)

Definition at line 598 of file MatacqProducer.cc.

References gather_cfg::cout, runTheMatrix::data, eventLength_, firstOrbit_, MatacqRawEvent::getDccLen(), MatacqProducer::getOrbitId(), invalid_, prof2calltree::last, MatacqProducer::mread(), MatacqProducer::mrewind(), MatacqProducer::mseek(), MatacqProducer::msize(), nEvents, orbitStepMean_, asciidump::s, and verbosity_.

Referenced by MatacqProducer::getMatacqFile().

                                                       {
  mp->mrewind();

  const size_t headerSize = 8*8;
  unsigned char data[headerSize];
  if(!mp->mread((char*)data, headerSize)){
    if(verbosity_) cout << "[Matacq] reached end of file!\n"; 
    firstOrbit_ = eventLength_ = orbitStepMean_ = 0;
    return;
  } else{
    firstOrbit_ = MatacqRawEvent::getOrbitId(data, headerSize);
    eventLength_ = MatacqRawEvent::getDccLen(data, headerSize);
    if(verbosity_>1) cout << "[Matacq] First event orbit: " << firstOrbit_
                          << " event length: " << eventLength_
                          << "*8 byte\n";
  }

  mp->mrewind();
  
  if(eventLength_==0){    
    if(verbosity_) cout << "[Matacq] event length is null!" << endl; 
    return;
  }

  filepos_t s;
  mp->msize(s);

  //number of complete events:
  const unsigned nEvents = s/eventLength_/8;

  if(nEvents==0){
    if(verbosity_) cout << "[Matacq] File is empty!" << endl;
    orbitStepMean_ = 0;
    return;
  }

  if(verbosity_>1) cout << "[Matacq] File size: " << s
                        << " Number of events: " << nEvents << endl;
  
  //position of last complete events:
  off_t last = (nEvents-1)*(off_t)eventLength_*8;
  mp->mseek(last, SEEK_SET, "Moving to beginning of last complete "
            "matacq event");
  if(!mp->mread((char*) data, headerSize, "Reading matacq header", true)){
    LogWarning("IncorrectLaserEvent") << "Fast matacq event retrieval failure. "
      "Falling back to safe retrieval mode.";
    orbitStepMean_ = 0;
  }
  
  int32_t lastOrb = MatacqRawEvent::getOrbitId(data, headerSize);
  int32_t lastLen = MatacqRawEvent::getDccLen(data, headerSize);

  if(verbosity_>1) cout << "[Matacq] Last event orbit: " << lastOrb
                        << " last event length: " << lastLen << endl;
  
  //some consistency check
  if(lastLen!=eventLength_){
    LogWarning("IncorrectLaserEvent")
      << "Fast matacq event retrieval failure: it looks like "
      "the matacq file contains events of different sizes. Falling back to "
      "safe retrieval mode.";
    invalid_ = true;
    orbitStepMean_ = 0;
    return;
  }

  orbitStepMean_ = (lastOrb - firstOrbit_)/nEvents;
  
  if(verbosity_>1) cout << "[Matacq] Orbit step mean: " << orbitStepMean_
                        << "\n";

  invalid_ = false;
}
bool MatacqProducer::PosEstimator::invalid ( ) const [inline]

Definition at line 113 of file MatacqProducer.h.

References invalid_.

Referenced by MatacqProducer::getMatacqEvent().

{ return invalid_; }
int64_t MatacqProducer::PosEstimator::pos ( int  orb) const

Definition at line 672 of file MatacqProducer.cc.

References gather_cfg::cout, csvReporter::r, and MatacqProducer::verbosity_.

Referenced by MatacqProducer::getMatacqEvent().

                                                    {
  if(orb<firstOrbit_) return -1;
  uint64_t r = orbitStepMean_!=0?
    (((uint64_t)(orb-firstOrbit_))/orbitStepMean_)*eventLength_*8
    :0;
  if(verbosity_>2) cout << "[Matacq] Estimated Position for orbit  " << orb
                        << ": " << r << endl;
  return r;
}
void MatacqProducer::PosEstimator::verbosity ( int  verb) [inline]

Definition at line 117 of file MatacqProducer.h.

References verbosity_.

Referenced by MatacqProducer::MatacqProducer().

{ verbosity_ = verb; }

Member Data Documentation

Definition at line 119 of file MatacqProducer.h.

Referenced by eventLength(), and init().

Definition at line 121 of file MatacqProducer.h.

Referenced by firstOrbit(), and init().

Definition at line 122 of file MatacqProducer.h.

Referenced by init(), and invalid().

Definition at line 120 of file MatacqProducer.h.

Referenced by init().

Definition at line 123 of file MatacqProducer.h.

Referenced by init(), and verbosity().