CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes

edm::eventsetup::DependentRecordIntervalFinder Class Reference

#include <DependentRecordIntervalFinder.h>

Inheritance diagram for edm::eventsetup::DependentRecordIntervalFinder:
edm::EventSetupRecordIntervalFinder

List of all members.

Public Member Functions

void addProviderWeAreDependentOn (boost::shared_ptr< EventSetupRecordProvider >)
 DependentRecordIntervalFinder (const EventSetupRecordKey &)
bool haveProviders () const
void setAlternateFinder (boost::shared_ptr< EventSetupRecordIntervalFinder >)
virtual ~DependentRecordIntervalFinder ()

Protected Member Functions

virtual void setIntervalFor (const EventSetupRecordKey &, const IOVSyncValue &, ValidityInterval &)

Private Types

typedef std::vector
< boost::shared_ptr
< EventSetupRecordProvider > > 
Providers

Private Member Functions

 DependentRecordIntervalFinder (const DependentRecordIntervalFinder &)
const
DependentRecordIntervalFinder
operator= (const DependentRecordIntervalFinder &)

Private Attributes

boost::shared_ptr
< EventSetupRecordIntervalFinder
alternate_
std::vector< ValidityIntervalpreviousIOVs_
Providers providers_

Detailed Description

Definition at line 36 of file DependentRecordIntervalFinder.h.


Member Typedef Documentation

typedef std::vector< boost::shared_ptr<EventSetupRecordProvider> > edm::eventsetup::DependentRecordIntervalFinder::Providers [private]

Definition at line 65 of file DependentRecordIntervalFinder.h.


Constructor & Destructor Documentation

DependentRecordIntervalFinder::DependentRecordIntervalFinder ( const EventSetupRecordKey iKey)
DependentRecordIntervalFinder::~DependentRecordIntervalFinder ( ) [virtual]

Definition at line 43 of file DependentRecordIntervalFinder.cc.

{
}
edm::eventsetup::DependentRecordIntervalFinder::DependentRecordIntervalFinder ( const DependentRecordIntervalFinder ) [private]

Member Function Documentation

void DependentRecordIntervalFinder::addProviderWeAreDependentOn ( boost::shared_ptr< EventSetupRecordProvider iProvider)

Definition at line 63 of file DependentRecordIntervalFinder.cc.

References providers_.

Referenced by edm::eventsetup::EventSetupRecordProvider::setDependentProviders().

{
   providers_.push_back(iProvider);
}
bool edm::eventsetup::DependentRecordIntervalFinder::haveProviders ( ) const [inline]

Definition at line 44 of file DependentRecordIntervalFinder.h.

References providers_.

                                 {
        return !providers_.empty();
      }
const DependentRecordIntervalFinder& edm::eventsetup::DependentRecordIntervalFinder::operator= ( const DependentRecordIntervalFinder ) [private]
void DependentRecordIntervalFinder::setAlternateFinder ( boost::shared_ptr< EventSetupRecordIntervalFinder iOther)

Definition at line 69 of file DependentRecordIntervalFinder.cc.

References alternate_.

{
  alternate_ = iOther;
}
void DependentRecordIntervalFinder::setIntervalFor ( const EventSetupRecordKey iKey,
const IOVSyncValue iTime,
ValidityInterval oInterval 
) [protected, virtual]

Implements edm::EventSetupRecordIntervalFinder.

Definition at line 75 of file DependentRecordIntervalFinder.cc.

References alternate_, edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::comparable(), edm::IOVSyncValue::endOfTime(), edm::IOVSyncValue::eventID(), edm::ValidityInterval::first(), edm::ValidityInterval::invalidInterval(), edm::IOVSyncValue::invalidIOVSyncValue(), edm::ValidityInterval::last(), edm::EventID::luminosityBlock(), previousIOVs_, providers_, edm::EventID::run(), edm::ValidityInterval::setFirst(), edm::ValidityInterval::setLast(), edm::IOVSyncValue::time(), tmp, edm::Timestamp::unixTime(), and edm::Timestamp::value().

{
   //NOTE: oInterval is the last value that was used so if nothing changed do not modify oInterval
   
   //I am assuming that an invalidTime is always less then the first valid time
   assert(IOVSyncValue::invalidIOVSyncValue() < IOVSyncValue::beginOfTime());
   if(providers_.size() == 0 && alternate_.get() == 0 ) {
      oInterval = ValidityInterval::invalidInterval();
      return;
   }
   bool haveAValidDependentRecord = false;
   bool allRecordsValid = true;
   ValidityInterval newInterval(IOVSyncValue::beginOfTime(), IOVSyncValue::endOfTime());
   
   if (alternate_.get() != 0) {
     ValidityInterval test = alternate_->findIntervalFor(iKey, iTime);
     if ( test != ValidityInterval::invalidInterval() ) {
       haveAValidDependentRecord =true;
       newInterval = test;
     }
   }
   bool intervalsWereComparible = true;
   for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
       itProvider != itProviderEnd;
       ++itProvider) {
      if((*itProvider)->setValidityIntervalFor(iTime)) {
         haveAValidDependentRecord=true;
         ValidityInterval providerInterval = (*itProvider)->validityInterval();
         if( (!newInterval.first().comparable(providerInterval.first())) ||
             (!newInterval.last().comparable(providerInterval.last()))) {
           intervalsWereComparible=false;
           break;
         }
         if(newInterval.first() < providerInterval.first()) {
            newInterval.setFirst(providerInterval.first());
         }
         if(newInterval.last() > providerInterval.last()) {
            newInterval.setLast(providerInterval.last());
         }
      } else {
        allRecordsValid = false;
      }
   }
   if(intervalsWereComparible) {
     if(!haveAValidDependentRecord) {
       //If no Finder has no valid time, then this record is also invalid for this time
       newInterval = ValidityInterval::invalidInterval();
     }
     if(!allRecordsValid) {
       //since some of the dependent providers do not have a valid IOV for this syncvalue
       // we do not know what the true end IOV is.  Therefore we must make it open ended
       // so that we can check each time to see if those providers become valid.
       newInterval.setLast(IOVSyncValue::invalidIOVSyncValue());
     }
     oInterval = newInterval;
     return;
   }
   //handle the case where some providers use time and others use run/lumi/event
   // in this case all we can do is find an IOV which changed since last time
   // and use its start time to do the synching and use an 'invalid' end time
   // so the system always checks back to see if something has changed
   if (previousIOVs_.empty()) {
      std::vector<ValidityInterval> tmp(providers_.size(),ValidityInterval());
      previousIOVs_.swap(tmp);
   }

   //I'm using an heuristic to pick a reasonable starting point for the IOV. The idea is to
   // assume that lumi sections are 23 seconds long and therefore if we take a difference between
   // iTime and the beginning of a changed IOV we can pick the changed IOV with the start time 
   // closest to iTime. This doesn't have to be perfect, we just want to reduce the dependency
   // on provider order to make the jobs more deterministic
   
   bool hadChangedIOV = false;
   //both start at the smallest value
   EventID closestID;
   Timestamp closestTimeStamp(0);
   std::vector<ValidityInterval>::iterator itIOVs = previousIOVs_.begin();
   for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
       itProvider != itProviderEnd;
       ++itProvider, ++itIOVs) {
      if((*itProvider)->setValidityIntervalFor(iTime)) {
         ValidityInterval providerInterval = (*itProvider)->validityInterval();
         if(*itIOVs != providerInterval) {
            hadChangedIOV = true;
            if(providerInterval.first().time().value() == 0) {
               //this is a run/lumi based one
               if( closestID < providerInterval.first().eventID()) {
                  closestID = providerInterval.first().eventID();
               }
            } else {
               if(closestTimeStamp < providerInterval.first().time()) {
                  closestTimeStamp = providerInterval.first().time();
               }
            }
            *itIOVs = providerInterval;
         }
      }
   }
   if(hadChangedIOV) {
      if(closestID.run() !=0) {
         if(closestTimeStamp.value() == 0) {
            //no time
            oInterval = ValidityInterval(IOVSyncValue(closestID), IOVSyncValue::invalidIOVSyncValue());
         } else {
            if(closestID.run() == iTime.eventID().run()) {
               //can compare time to lumi
               const unsigned long long kLumiTimeLength = 23;
               
               if( (iTime.eventID().luminosityBlock() - closestID.luminosityBlock())*kLumiTimeLength < 
                  iTime.time().unixTime() - closestTimeStamp.unixTime() ) {
                  //closestID was closer
                  oInterval = ValidityInterval(IOVSyncValue(closestID), IOVSyncValue::invalidIOVSyncValue());
               } else {
                  oInterval = ValidityInterval(IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
               }
            } else {
               //since we don't know how to change run # into time we can't compare
               // so if we have a time just use it
               oInterval = ValidityInterval(IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
            }
         }
      } else {
         oInterval = ValidityInterval( IOVSyncValue(closestTimeStamp), IOVSyncValue::invalidIOVSyncValue());
      }
   }
}

Member Data Documentation

Definition at line 68 of file DependentRecordIntervalFinder.h.

Referenced by setAlternateFinder(), and setIntervalFor().

Definition at line 69 of file DependentRecordIntervalFinder.h.

Referenced by setIntervalFor().