/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Private Member Functions | Private Attributes
SmartFilterAlg Class Reference

#include <SmartFilterAlg.h>

List of all members.

Public Member Functions

 SmartFilterAlg (const std::string &name, ISvcLocator *pSvcLocator)
virtual ~SmartFilterAlg ()
virtual StatusCode initialize ()
virtual StatusCode execute ()
virtual StatusCode finalize ()

Private Member Functions

StatusCode processParentHeaders (DataObject *dobj)
ObjectRegfindRegistration (DataObject *dobj)
bool isChild (const DataObject *dobj)

Private Attributes

bool m_clearAll
 Property ClearAll - Clear all data from output.
std::string m_keepLocation
 Property KeepLocation - Location in TES where filter begins.
double m_prescale
 Property Prescale - Prescale fraction for filtering.
bool m_keepAllParents
 Property KeepAllParents - Keep all parent headers of filtered data.
std::vector< std::string > m_keepParents
 Property KeepParents - locations in TES of parents to keep.
double m_parentPrescale
 Property ParentPrescale - Prescale fraction for parent headers.
bool m_keepAllChildren
 Property KeepAllChildren - keep all child headers.
std::vector< std::string > m_keepChildren
 Property KeepChildren - locations in TES of children to keep.
double m_childrenPrescale
 Property ChildrenPrescale - Prescale fraction for child headers.
unsigned int m_maxKeptHistory
 Property MaxKeptHistory - Maximum number of filtered events to search for children.
IDataProviderSvc * m_archiveSvc
std::list< DataObject * > m_keptHeaders
Rndm::Numbers * m_uniform

Detailed Description

Definition at line 24 of file SmartFilterAlg.h.


Constructor & Destructor Documentation

SmartFilterAlg::SmartFilterAlg ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 14 of file SmartFilterAlg.cc.

  : GaudiAlgorithm(name,pSvcLocator),
    m_keepParents(),
    m_keepChildren(),
    m_archiveSvc(0),
    m_keptHeaders(),
    m_uniform(0)
{
  declareProperty("ClearAll", 
                  m_clearAll=false,
                  "Clear all data from output");

  declareProperty("KeepLocation", 
                  m_keepLocation="",
                  "Location in TES where filter begins");

  declareProperty("Prescale", 
                  m_prescale=-1,
                  "Prescale fraction for filtering");

  declareProperty("KeepAllParents", 
                  m_keepAllParents=false,
                  "Keep all parent headers of filtered data");

  declareProperty("KeepParents", 
                  m_keepParents,
                  "List of specific parent headers to keep");

  declareProperty("ParentPrescale", 
                  m_parentPrescale=-1,
                  "Additional prescale applied to parent headers");

  declareProperty("KeepAllChildren", 
                  m_keepAllChildren=false,
                  "Keep all children headers of filtered data");

  declareProperty("KeepChildren", 
                  m_keepChildren,
                  "List of specific child headers to keep");

  declareProperty("ChildrenPrescale", 
                  m_childrenPrescale=-1,
                  "Additional prescale applied to child headers");
  
  declareProperty("MaxKeptHistory", 
                  m_maxKeptHistory=5,
                  "Maximum number of filtered events to search for children");
}
SmartFilterAlg::~SmartFilterAlg ( ) [virtual]

Definition at line 63 of file SmartFilterAlg.cc.

{
}

Member Function Documentation

StatusCode SmartFilterAlg::initialize ( ) [virtual]

Definition at line 67 of file SmartFilterAlg.cc.

{

  StatusCode sc = service("EventDataArchiveSvc",m_archiveSvc);
  if(sc.isFailure()){
    warning() << "Failed to access the Archive event store" << endreq;
  }

  if(m_prescale>0 || m_parentPrescale>0 || m_childrenPrescale>0){
    // Initialize random number service if needed
    IRndmGenSvc *rgs = 0;
    StatusCode sc;
    sc = service("RndmGenSvc",rgs,true); 
    if( sc.isFailure() ){
      error() << "Failed to get random service" << endreq;
      return StatusCode::FAILURE;        
    }
    m_uniform = new Rndm::Numbers();
    sc = m_uniform->initialize(rgs, Rndm::Flat(0,1));
    if( sc.isFailure() ) {
      error() << "Failed to initialize uniform random numbers" << endreq;
      return StatusCode::FAILURE;
    }
  }

  return StatusCode::SUCCESS;
}
StatusCode SmartFilterAlg::execute ( ) [virtual]

Definition at line 95 of file SmartFilterAlg.cc.

{
  StatusCode sc;

  DayaBay::RegistrationSequence* regSeq
    = get<DayaBay::RegistrationSequence>("/Event/RegistrationSequence");
  
  IRegistrationSequence::Registrations& registrations 
    = const_cast<IRegistrationSequence::Registrations&>(regSeq->registrations()); 
  IRegistrationSequence::Registrations::iterator it, 
    done = registrations.end();

  // Clear all data, if requested
  if(m_clearAll){
    for (it = registrations.begin(); it != done; ++it) {
      it->setStore(false);
    }
  }

  if(m_keepLocation.size()==0){
    // No more filtering to do...
    return StatusCode::SUCCESS;
  }

  // Loop over registrations, and look for the header we are filtering
  for (it = registrations.begin(); it != done; ++it) {
    DataObject* dobj = it->object();
    debug() << "Checking object: " << dobj->registry()->identifier() << endreq;
    if(dobj->registry()->identifier() != m_keepLocation){
      // Not the path we are interested in...
      continue;
    }
    double rand = 0;
    if(m_uniform){
      rand = (*m_uniform)();
    }
    if(m_prescale>0 && m_prescale<rand){
      // Don't keep this one, prescaled
      continue;
    }
    // We are keeping this entry
    it->setStore(true);
    debug() << "Keeping: " << dobj->registry()->identifier() << endreq;
    
    // Look for parent headers to keep
    if(m_keepAllParents || m_keepParents.size()>0){
      double effectiveParentPrescale = m_parentPrescale;
      if(m_prescale>0 && m_parentPrescale>0){
        effectiveParentPrescale = m_prescale*m_parentPrescale;
      }
      if( m_parentPrescale<0 || rand < effectiveParentPrescale ){
        sc = this->processParentHeaders(dobj);
      }
    }
    
    // Keep a reference so we can check children
    if( m_keepAllChildren || m_keepChildren.size()>0 ){      
      double effectiveChildrenPrescale = m_childrenPrescale;
      if(m_prescale>0 && m_childrenPrescale>0){
        effectiveChildrenPrescale = m_prescale*m_childrenPrescale;
      }
      if( m_childrenPrescale<0 || rand < effectiveChildrenPrescale ){
        dobj->addRef();
        m_keptHeaders.push_back(dobj);
        if(m_keptHeaders.size() > m_maxKeptHistory){
          // Remove stale header
          m_keptHeaders.front()->release();
          m_keptHeaders.pop_front();
        }
      }
    }
  } // end loop over registrations

  if( m_keepAllChildren || m_keepChildren.size()>0 ) {
    // Loop over registrations again, and look for child headers
    for (it = registrations.begin(); it != done; ++it) {
      DataObject* childObj = it->object();
      debug() << "Checking child: " << childObj->registry()->identifier()
             << endreq;
      if( !m_keepAllChildren
          && std::find(m_keepChildren.begin(),
                       m_keepChildren.end(),
                       childObj->registry()->identifier() ) 
          == m_keepChildren.end() ){
        // Not an interesting child
        continue;
      }
      // Is this a child?
      if( !this->isChild( childObj ) ) continue;
      // This is a child to keep
      it->setStore(true);
      debug() << "Keeping child: " << childObj->registry()->identifier() 
             << endreq;
    } // end loop over child candidates
  }

  return StatusCode::SUCCESS;
}
StatusCode SmartFilterAlg::finalize ( ) [virtual]

Definition at line 194 of file SmartFilterAlg.cc.

{
  if(m_archiveSvc){
    m_archiveSvc->release();
  }
  if(m_uniform){
    delete m_uniform;
    m_uniform=0;
  }
  return this->GaudiAlgorithm::finalize();
}
StatusCode SmartFilterAlg::processParentHeaders ( DataObject *  dobj) [private]

Definition at line 207 of file SmartFilterAlg.cc.

{
  // Helper function to traverse and filter parent headers
  DayaBay::IHeader* header = dynamic_cast<DayaBay::IHeader*>(dobj);
  if(!header){
    error() << "Invalid data object" << endreq;
    return StatusCode::FAILURE;
  }
  // Loop over input headers
  for(unsigned int ihIdx=0;ihIdx<header->inputHeaders().size();ihIdx++){
    const DayaBay::IHeader* inputHeader = header->inputHeaders()[ihIdx];
    const DataObject* tmpObj
      = dynamic_cast<const DataObject*>( inputHeader );
    DataObject* parentObj = const_cast<DataObject*>(tmpObj);
    if( !m_keepAllParents
        && std::find(m_keepParents.begin(), 
                     m_keepParents.end(),
                     parentObj->registry()->identifier())
        ==m_keepParents.end()){
      // Don't keep this parent
      continue;
    }
    ObjectReg* parentReg = this->findRegistration(parentObj);
    if(parentReg){
      parentReg->setStore(true);
      debug() << "Keeping parent: " << parentObj->registry()->identifier() 
             << endreq;
      // Don't forget to check the grandparents
      StatusCode sc = this->processParentHeaders(parentObj);
      if(sc.isFailure()) return sc;
    }
  }

  return StatusCode::SUCCESS;
}
ObjectReg * SmartFilterAlg::findRegistration ( DataObject *  dobj) [private]

Definition at line 243 of file SmartFilterAlg.cc.

{
  // Try to find the registration for this data object

  // FIXME: Can't navigate directly to ObjectReg for a given header object. 
  //        
  // Instead, use the following HACK
  // Check all archived regseq. to look for each input header
  if(m_archiveSvc){
    DybArchiveList* arcRegList = 0;
    arcRegList = get<DybArchiveList*>(m_archiveSvc,
                                      "/Event/RegistrationSequence");
    if(!arcRegList){
      error() << "Failed to get archive of registrations sequences" << endreq;
      return 0;
    }
    for(unsigned int regSeqIdx=0; regSeqIdx<arcRegList->size(); regSeqIdx++){
      DayaBay::RegistrationSequence* regSeq 
        = dynamic_cast<DayaBay::RegistrationSequence*>(
                                             arcRegList->dataObject(regSeqIdx));
      if(!regSeq){
        error() << "Invalid registration sequence in AES!" << endreq;
        continue;
      }
      ObjectReg* objReg = regSeq->registration(dobj);
      if(objReg){
        // Found it!
        return objReg;
      }
    }
  }else{
    // Just use current RegSeq
    IRegistrationSequence* regSeq 
      = get<IRegistrationSequence>("/Event/RegistrationSequence");
    if(!regSeq){
      error() << "Invalid registration sequence in TES!" << endreq;
      return 0;
    }
    ObjectReg* objReg = regSeq->registration(dobj);
    if(objReg){
      // Found it!
      return objReg;
    }
  }
  if(dobj && dobj->registry()){
    warning() << "Failed to find registration for object " 
              << dobj->registry()->identifier() << endreq;
  }else{
    warning() << "Broken registry for current data object" << endreq;
  }
  return 0;
}
bool SmartFilterAlg::isChild ( const DataObject *  dobj) [private]

Definition at line 297 of file SmartFilterAlg.cc.

                                                  {
  // Check if this object is a child of a kept object
  const DayaBay::IHeader* header = dynamic_cast<const DayaBay::IHeader*>(dobj);
  if(!header){
    error() << "Invalid data object" << endreq;
    return false;
  }
  // Loop over input headers
  for(unsigned int ihIdx=0;ihIdx<header->inputHeaders().size();ihIdx++){
    const DayaBay::IHeader* inputHeader = header->inputHeaders()[ihIdx];
    const DataObject* parentObj
      = dynamic_cast<const DataObject*>( inputHeader ); 
    if(std::find(m_keptHeaders.begin(), 
                 m_keptHeaders.end(), 
                 parentObj) != m_keptHeaders.end()){
      return true;
    }
    // check ancestors as well
    if( this->isChild( parentObj ) ) return true;
  }
  return false;
}

Member Data Documentation

Property ClearAll - Clear all data from output.

Definition at line 43 of file SmartFilterAlg.h.

std::string SmartFilterAlg::m_keepLocation [private]

Property KeepLocation - Location in TES where filter begins.

Definition at line 47 of file SmartFilterAlg.h.

double SmartFilterAlg::m_prescale [private]

Property Prescale - Prescale fraction for filtering.

Definition at line 51 of file SmartFilterAlg.h.

Property KeepAllParents - Keep all parent headers of filtered data.

Definition at line 55 of file SmartFilterAlg.h.

std::vector< std::string > SmartFilterAlg::m_keepParents [private]

Property KeepParents - locations in TES of parents to keep.

Definition at line 59 of file SmartFilterAlg.h.

Property ParentPrescale - Prescale fraction for parent headers.

Definition at line 63 of file SmartFilterAlg.h.

Property KeepAllChildren - keep all child headers.

Definition at line 67 of file SmartFilterAlg.h.

std::vector< std::string > SmartFilterAlg::m_keepChildren [private]

Property KeepChildren - locations in TES of children to keep.

Definition at line 71 of file SmartFilterAlg.h.

Property ChildrenPrescale - Prescale fraction for child headers.

Definition at line 75 of file SmartFilterAlg.h.

unsigned int SmartFilterAlg::m_maxKeptHistory [private]

Property MaxKeptHistory - Maximum number of filtered events to search for children.

Definition at line 80 of file SmartFilterAlg.h.

IDataProviderSvc* SmartFilterAlg::m_archiveSvc [private]

Definition at line 83 of file SmartFilterAlg.h.

std::list<DataObject*> SmartFilterAlg::m_keptHeaders [private]

Definition at line 85 of file SmartFilterAlg.h.

Rndm::Numbers* SmartFilterAlg::m_uniform [private]

Definition at line 86 of file SmartFilterAlg.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:08:36 for SmartFilter by doxygen 1.7.4