CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

APVCyclePhaseProducerFromL1ABC Class Reference

#include <DPGAnalysis/SiStripTools/plugins/APVCyclePhaseProducerFromL1ABC.cc>

Inheritance diagram for APVCyclePhaseProducerFromL1ABC:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 APVCyclePhaseProducerFromL1ABC (const edm::ParameterSet &)
 ~APVCyclePhaseProducerFromL1ABC ()

Private Member Functions

virtual void beginJob ()
virtual void beginRun (edm::Run &, const edm::EventSetup &)
virtual void endJob ()
virtual void endRun (edm::Run &, const edm::EventSetup &)
virtual void produce (edm::Event &, const edm::EventSetup &)

Private Attributes

unsigned int _curroffevent
long long _curroffset
const std::vector< std::string > _defpartnames
const std::vector< int > _defphases
const unsigned int _firstgoodrun
TH1F ** _hbx
TH1F ** _hdbx
TH1F ** _hdorbit
const edm::InputTag _l1abccollection
std::map< unsigned int, long long > _offsets
const int _orbitoffsetSOR
const bool _wantHistos
RunHistogramManager m_rhm

Detailed Description

Description: EDproducer for APVCyclePhaseCollection which uses the configuration file to assign a phase to the run

Implementation: <Notes on="" implementation>="">

Definition at line 54 of file APVCyclePhaseProducerFromL1ABC.cc.


Constructor & Destructor Documentation

APVCyclePhaseProducerFromL1ABC::APVCyclePhaseProducerFromL1ABC ( const edm::ParameterSet iConfig) [explicit]

Definition at line 98 of file APVCyclePhaseProducerFromL1ABC.cc.

References _hbx, _hdbx, _hdorbit, _wantHistos, m_rhm, and RunHistogramManager::makeTH1F().

                                                                                            :
  _l1abccollection(iConfig.getParameter<edm::InputTag>("l1ABCCollection")),
  _defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
  _defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
  _orbitoffsetSOR(iConfig.getParameter<int>("StartOfRunOrbitOffset")),
  _wantHistos(iConfig.getUntrackedParameter<bool>("wantHistos",false)),
  m_rhm(),
  _hbx(0),_hdbx(0),_hdorbit(0),_firstgoodrun(110878),
  _offsets(), _curroffset(0), _curroffevent(0)
{

  produces<APVCyclePhaseCollection,edm::InEvent>();

   //now do what ever other initialization is needed

  if(_wantHistos) {
    _hbx = m_rhm.makeTH1F("l1abcbx","BX number from L1ABC",4096,-0.5,4095.5);
    _hdbx = m_rhm.makeTH1F("dbx","BX number difference",4096*2-1,-4095.5,4095.5);
    _hdorbit = m_rhm.makeTH1F("dorbit","Orbit Number difference",9999,-4999.5,4999.5);
  }


}
APVCyclePhaseProducerFromL1ABC::~APVCyclePhaseProducerFromL1ABC ( )

Definition at line 123 of file APVCyclePhaseProducerFromL1ABC.cc.

{
 
   // do anything here that needs to be done at desctruction time
   // (e.g. close files, deallocate resources etc.)

}

Member Function Documentation

void APVCyclePhaseProducerFromL1ABC::beginJob ( void  ) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 287 of file APVCyclePhaseProducerFromL1ABC.cc.

{
}
void APVCyclePhaseProducerFromL1ABC::beginRun ( edm::Run iRun,
const edm::EventSetup iSetup 
) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 138 of file APVCyclePhaseProducerFromL1ABC.cc.

References _firstgoodrun, _hbx, _hdbx, _hdorbit, _offsets, _wantHistos, RunHistogramManager::beginRun(), m_rhm, and edm::RunBase::run().

{

  // reset offset vector

  _offsets.clear();
  edm::LogInfo("AbsoluteBXOffsetReset") << "Absolute BX offset map reset";


  if(_wantHistos) {

    m_rhm.beginRun(iRun);

    if(_hbx && *_hbx) {
      (*_hbx)->GetXaxis()->SetTitle("BX");     (*_hbx)->GetYaxis()->SetTitle("Events"); 
    }

    if(_hdbx && *_hdbx) {
      (*_hdbx)->GetXaxis()->SetTitle("#DeltaBX");     (*_hdbx)->GetYaxis()->SetTitle("Events"); 
    }

    if(_hdorbit && *_hdorbit) {
      (*_hdorbit)->GetXaxis()->SetTitle("#Deltaorbit");     (*_hdorbit)->GetYaxis()->SetTitle("Events"); 
    }

  }

  if(iRun.run() < _firstgoodrun) {
    edm::LogInfo("UnreliableMissingL1AcceptBunchCrossingCollection") << 
      "In this run L1AcceptBunchCrossingCollection is missing or unreliable: default phases will be used"; 
  }

}
void APVCyclePhaseProducerFromL1ABC::endJob ( void  ) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 293 of file APVCyclePhaseProducerFromL1ABC.cc.

                                       {
}
void APVCyclePhaseProducerFromL1ABC::endRun ( edm::Run ,
const edm::EventSetup  
) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 174 of file APVCyclePhaseProducerFromL1ABC.cc.

References _offsets, and evf::evtn::offset().

{
  // summary of absolute bx offset vector

  edm::LogInfo("L1AcceptBunchCrossingAbsoluteBXOffsetSummary") << "Absolute BX offset summary:";
  for(std::map<unsigned int, long long>::const_iterator offset=_offsets.begin();offset!=_offsets.end();++offset) {
    edm::LogVerbatim("L1AcceptBunchCrossingAbsoluteBXOffsetSummary") << offset->first << " " << offset->second;
  }

}
void APVCyclePhaseProducerFromL1ABC::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDProducer.

Definition at line 187 of file APVCyclePhaseProducerFromL1ABC.cc.

References _curroffevent, _curroffset, _defpartnames, _defphases, _firstgoodrun, _hbx, _hdbx, _hdorbit, _l1abccollection, _offsets, _orbitoffsetSOR, _wantHistos, edm::EventBase::bunchCrossing(), edm::EventID::event(), Exception, edm::Event::getByLabel(), edm::EventBase::id(), edm::EventBase::orbitNumber(), edm::Event::put(), and edm::Event::run().

                                                                                     {

  using namespace edm;
  
  std::auto_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection() );
  

  const std::vector<int>& phases = _defphases;
  const std::vector<std::string>& partnames = _defpartnames;

  // Look for the L1AcceptBunchCrossingCollection

  int phasechange = 0;

  if(iEvent.run() >= _firstgoodrun ) {
    
    Handle<L1AcceptBunchCrossingCollection > pIn;
    iEvent.getByLabel(_l1abccollection,pIn);
    
    // offset computation
    
    long long orbitoffset = _orbitoffsetSOR;
    int bxoffset = 0;
    
    for(L1AcceptBunchCrossingCollection::const_iterator l1abc=pIn->begin();l1abc!=pIn->end();++l1abc) {
      if(l1abc->l1AcceptOffset()==0) {
        if(l1abc->eventType()!=0) {
          orbitoffset = (long long)iEvent.orbitNumber() - (long long)l1abc->orbitNumber() ;
          bxoffset = iEvent.bunchCrossing() - l1abc->bunchCrossing();
          
          if(_wantHistos) {
            if(_hbx && *_hbx) (*_hbx)->Fill(l1abc->bunchCrossing());
            if(_hdbx && *_hdbx) (*_hdbx)->Fill(bxoffset);
            if(_hdorbit && *_hdorbit) (*_hdorbit)->Fill(orbitoffset);
          }
        }
        else {
          edm::LogWarning("L1AcceptBunchCrossingNoType") << "L1AcceptBunchCrossing with no type found: ";
          for(L1AcceptBunchCrossingCollection::const_iterator debu=pIn->begin();debu!=pIn->end();++debu) {
            edm::LogPrint("L1AcceptBunchCrossingNoType") << *debu;
          }
        }
      }
    }

    long long absbxoffset = orbitoffset*3564 + bxoffset;

    if(orbitoffset != _orbitoffsetSOR) phasechange = (orbitoffset*3564)%70;

     if(_offsets.size()==0) {
       _curroffset = absbxoffset;
       _curroffevent = iEvent.id().event();
       _offsets[iEvent.id().event()] = absbxoffset;
     }
     else {
       if(_curroffset != absbxoffset || iEvent.id().event() < _curroffevent ) {

         if( _curroffset != absbxoffset) {
           edm::LogInfo("L1AcceptBunchCrossingAbsoluteBXOffsetChanged") << "Absolute BX offset changed from " 
                                                                        << _curroffset << " to "
                                                                        << absbxoffset << " at orbit "
                                                                        << iEvent.orbitNumber() << " and BX "
                                                                        << iEvent.bunchCrossing();
           for(L1AcceptBunchCrossingCollection::const_iterator l1abc=pIn->begin();l1abc!=pIn->end();++l1abc) {
             edm::LogVerbatim("L1AcceptBunchCrossingAbsoluteBXOffsetChanged") << *l1abc;
           }
         }

         _curroffset = absbxoffset;
         _curroffevent = iEvent.id().event();
         _offsets[iEvent.id().event()] = absbxoffset;
       }
     }

    
  }
  


  if(phases.size() < partnames.size() ) {
    // throw exception
    throw cms::Exception("InvalidAPVCyclePhases") << " Inconsistent phases/partitions vector sizes: " 
                                             << phases.size() << " " 
                                             << partnames.size();
  }

  for(unsigned int ipart=0;ipart<partnames.size();++ipart) {
    if(phases[ipart]>=0) {
      apvphases->get()[partnames[ipart]] = (phases[ipart]+phasechange)%70;

    }
  }


  iEvent.put(apvphases);

}

Member Data Documentation

Definition at line 82 of file APVCyclePhaseProducerFromL1ABC.cc.

Referenced by produce().

Definition at line 81 of file APVCyclePhaseProducerFromL1ABC.cc.

Referenced by produce().

const std::vector<std::string> APVCyclePhaseProducerFromL1ABC::_defpartnames [private]

Definition at line 69 of file APVCyclePhaseProducerFromL1ABC.cc.

Referenced by produce().

const std::vector<int> APVCyclePhaseProducerFromL1ABC::_defphases [private]

Definition at line 70 of file APVCyclePhaseProducerFromL1ABC.cc.

Referenced by produce().

const unsigned int APVCyclePhaseProducerFromL1ABC::_firstgoodrun [private]

Definition at line 79 of file APVCyclePhaseProducerFromL1ABC.cc.

Referenced by beginRun(), and produce().

Definition at line 68 of file APVCyclePhaseProducerFromL1ABC.cc.

Referenced by produce().

std::map<unsigned int, long long> APVCyclePhaseProducerFromL1ABC::_offsets [private]

Definition at line 80 of file APVCyclePhaseProducerFromL1ABC.cc.

Referenced by beginRun(), endRun(), and produce().

Definition at line 71 of file APVCyclePhaseProducerFromL1ABC.cc.

Referenced by produce().

Definition at line 74 of file APVCyclePhaseProducerFromL1ABC.cc.

Referenced by APVCyclePhaseProducerFromL1ABC(), and beginRun().