#include <SmartFilterAlg.h>
Inheritance diagram for SmartFilterAlg:
Public Member Functions | |
SmartFilterAlg (const std::string &name, ISvcLocator *pSvcLocator) | |
virtual | ~SmartFilterAlg () |
virtual StatusCode | initialize () |
virtual StatusCode | execute () |
virtual StatusCode | finalize () |
virtual StatusCode | sysExecute () |
void | put (IDataProviderSvc *svc, DataObject *object, const std::string &address, const bool useRootInTES=true) const |
void | put (DataObject *object, const std::string &address, const bool useRootInTES=true) const |
Gaudi::Utils::GetData< TYPE >::return_type | get (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const |
Gaudi::Utils::GetData< TYPE >::return_type | get (const std::string &location, const bool useRootInTES=true) const |
TYPE * | getDet (IDataProviderSvc *svc, const std::string &location) const |
TYPE * | getDet (const std::string &location) const |
bool | exist (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const |
bool | exist (const std::string &location, const bool useRootInTES=true) const |
bool | existDet (IDataProviderSvc *svc, const std::string &location) const |
bool | existDet (const std::string &location) const |
TYPE * | getOrCreate (IDataProviderSvc *svc, const std::string &location, const bool useRootInTES=true) const |
TYPE * | getOrCreate (const std::string &location, const bool useRootInTES=true) const |
bool | registerContext () const |
INTupleSvc * | evtColSvc () const |
IAlgContextSvc * | contextSvc () const |
TOOL * | tool (const std::string &type, const std::string &name, const IInterface *parent=0, bool create=true) const |
TOOL * | tool (const std::string &type, const IInterface *parent=0, bool create=true) const |
SERVICE * | svc (const std::string &name, const bool create=true) const |
IUpdateManagerSvc * | updMgrSvc () const |
IDataProviderSvc * | fastContainersSvc () const |
StatusCode | Error (const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const |
StatusCode | Warning (const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const |
StatusCode | Print (const std::string &msg, const StatusCode st=StatusCode::SUCCESS, const MSG::Level lev=MSG::INFO) const |
StatusCode | Assert (const bool ok, const std::string &message="", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const |
StatusCode | Assert (const bool ok, const char *message, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const |
StatusCode | Exception (const std::string &msg, const GaudiException &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const |
StatusCode | Exception (const std::string &msg, const std::exception &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const |
StatusCode | Exception (const std::string &msg="no message", const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const |
MsgStream & | msgStream (const MSG::Level level) const |
MsgStream & | always () const |
MsgStream & | fatal () const |
MsgStream & | err () const |
MsgStream & | error () const |
MsgStream & | warning () const |
MsgStream & | info () const |
MsgStream & | debug () const |
MsgStream & | verbose () const |
MsgStream & | msg () const |
const Statistics & | counters () const |
StatEntity & | counter (const std::string &tag) const |
MSG::Level | msgLevel () const |
bool | msgLevel (const MSG::Level level) const |
void | resetMsgStream () const |
bool | typePrint () const |
bool | propsPrint () const |
bool | statPrint () const |
bool | errorsPrint () const |
long | printStat (const MSG::Level level=MSG::ALWAYS) const |
long | printErrors (const MSG::Level level=MSG::ALWAYS) const |
long | printProps (const MSG::Level level=MSG::ALWAYS) const |
void | registerCondition (const std::string &condition, StatusCode(CallerClass::*mf)()=NULL) |
void | registerCondition (const std::string &condition, CondType *&condPtrDest, StatusCode(CallerClass::*mf)()=NULL) |
void | registerCondition (char *condition, StatusCode(CallerClass::*mf)()=NULL) |
void | registerCondition (TargetClass *condition, StatusCode(CallerClass::*mf)()=NULL) |
StatusCode | runUpdate () |
TransientFastContainer< T > * | getFastContainer (const std::string &location, typename TransientFastContainer< T >::size_type initial=0) |
StatusCode | release (const IInterface *interface) const |
unsigned long | release () |
const std::string & | context () const |
const std::string & | rootInTES () const |
double | globalTimeOffset () const |
virtual StatusCode | sysStart () |
virtual StatusCode | sysInitialize () |
virtual StatusCode | sysReinitialize () |
virtual StatusCode | sysRestart () |
virtual StatusCode | sysStop () |
virtual StatusCode | sysFinalize () |
virtual StatusCode | sysBeginRun () |
virtual StatusCode | sysEndRun () |
virtual const std::string & | name () const |
virtual const std::string & | version () const |
virtual StatusCode | configure () |
virtual StatusCode | terminate () |
virtual StatusCode | start () |
virtual StatusCode | stop () |
virtual StatusCode | reinitialize () |
virtual StatusCode | restart () |
virtual bool | isExecuted () const |
virtual void | setExecuted (bool state) |
virtual void | resetExecuted () |
virtual StatusCode | beginRun () |
virtual StatusCode | endRun () |
virtual Gaudi::StateMachine::State | FSMState () const |
virtual Gaudi::StateMachine::State | targetFSMState () const |
virtual bool | isEnabled () const |
virtual bool | filterPassed () const |
virtual void | setFilterPassed (bool state) |
StatusCode | service (const std::string &name, T *&psvc, bool createIf=true) const |
StatusCode | service (const std::string &svcType, const std::string &svcName, T *&psvc) const |
void | setOutputLevel (int level) |
IAuditorSvc * | auditorSvc () const |
IChronoStatSvc * | chronoSvc () const |
IChronoStatSvc * | chronoStatService () const |
IDataProviderSvc * | detSvc () const |
IDataProviderSvc * | detDataService () const |
IConversionSvc * | detCnvSvc () const |
IConversionSvc * | detDataCnvService () const |
IDataProviderSvc * | eventSvc () const |
IDataProviderSvc * | evtSvc () const |
IDataProviderSvc * | eventDataService () const |
IConversionSvc * | eventCnvSvc () const |
IConversionSvc * | eventDataCnvService () const |
IHistogramSvc * | histoSvc () const |
IHistogramSvc * | histogramDataService () const |
IMessageSvc * | msgSvc () const |
IMessageSvc * | messageService () const |
INTupleSvc * | ntupleSvc () const |
INTupleSvc * | ntupleService () const |
IRndmGenSvc * | randSvc () const |
IToolSvc * | toolSvc () const |
IExceptionSvc * | exceptionSvc () const |
ISvcLocator * | serviceLocator () const |
ISvcLocator * | svcLoc () const |
StatusCode | createSubAlgorithm (const std::string &type, const std::string &name, Algorithm *&pSubAlg) |
std::vector< Algorithm * > * | subAlgorithms () const |
virtual StatusCode | setProperty (const Property &p) |
virtual StatusCode | setProperty (const std::string &s) |
virtual StatusCode | setProperty (const std::string &n, const std::string &v) |
StatusCode | setProperty (const std::string &name, const TYPE &value) |
virtual StatusCode | getProperty (Property *p) const |
virtual const Property & | getProperty (const std::string &name) const |
virtual StatusCode | getProperty (const std::string &n, std::string &v) const |
virtual const std::vector< Property * > & | getProperties () const |
StatusCode | setProperties () |
Property * | declareProperty (const std::string &name, T &property, const std::string &doc="none") const |
Property * | declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const |
IMonitorSvc * | monitorSvc () const |
void | declareInfo (const std::string &name, const T &var, const std::string &desc) const |
void | declareInfo (const std::string &name, const std::string &format, const void *var, int size, const std::string &desc) const |
unsigned long | addRef () |
StatusCode | queryInterface (const InterfaceID &riid, void **) |
Static Public Member Functions | |
static const InterfaceID & | interfaceID () |
static const InterfaceID & | interfaceID () |
static const InterfaceID & | interfaceID () |
Public Attributes | |
SUCCESS | |
NO_INTERFACE | |
VERSMISMATCH | |
LAST_ERROR | |
Protected Types | |
typedef std::map< std::string, StatEntity > | Statistics |
typedef std::map< std::string, unsigned int > | Counter |
typedef std::vector< IAlgTool * > | AlgTools |
typedef std::pair< IInterface *, std::string > | ServiceEntry |
typedef std::vector< ServiceEntry > | Services |
Protected Member Functions | |
StatusCode | releaseTool (const IAlgTool *tool) const |
StatusCode | releaseSvc (const IInterface *svc) const |
bool | isInitialized () const |
bool | isFinalized () const |
int | outputLevel () const |
IntegerProperty & | outputLevelProperty () |
void | initOutputLevel (Property &prop) |
Static Protected Attributes | |
static const bool | IgnoreRootInTES |
static const bool | UseRootInTES |
Private Member Functions | |
StatusCode | processParentHeaders (DataObject *dobj) |
ObjectReg * | findRegistration (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 |
Definition at line 24 of file SmartFilterAlg.h.
SmartFilterAlg::SmartFilterAlg | ( | const std::string & | name, | |
ISvcLocator * | pSvcLocator | |||
) |
Definition at line 14 of file SmartFilterAlg.cc.
00015 : GaudiAlgorithm(name,pSvcLocator), 00016 m_keepParents(), 00017 m_keepChildren(), 00018 m_archiveSvc(0), 00019 m_keptHeaders(), 00020 m_uniform(0) 00021 { 00022 declareProperty("ClearAll", 00023 m_clearAll=false, 00024 "Clear all data from output"); 00025 00026 declareProperty("KeepLocation", 00027 m_keepLocation="", 00028 "Location in TES where filter begins"); 00029 00030 declareProperty("Prescale", 00031 m_prescale=-1, 00032 "Prescale fraction for filtering"); 00033 00034 declareProperty("KeepAllParents", 00035 m_keepAllParents=false, 00036 "Keep all parent headers of filtered data"); 00037 00038 declareProperty("KeepParents", 00039 m_keepParents, 00040 "List of specific parent headers to keep"); 00041 00042 declareProperty("ParentPrescale", 00043 m_parentPrescale=-1, 00044 "Additional prescale applied to parent headers"); 00045 00046 declareProperty("KeepAllChildren", 00047 m_keepAllChildren=false, 00048 "Keep all children headers of filtered data"); 00049 00050 declareProperty("KeepChildren", 00051 m_keepChildren, 00052 "List of specific child headers to keep"); 00053 00054 declareProperty("ChildrenPrescale", 00055 m_childrenPrescale=-1, 00056 "Additional prescale applied to child headers"); 00057 00058 declareProperty("MaxKeptHistory", 00059 m_maxKeptHistory=5, 00060 "Maximum number of filtered events to search for children"); 00061 }
SmartFilterAlg::~SmartFilterAlg | ( | ) | [virtual] |
StatusCode SmartFilterAlg::initialize | ( | ) | [virtual] |
Reimplemented from GaudiAlgorithm.
Definition at line 67 of file SmartFilterAlg.cc.
00068 { 00069 00070 StatusCode sc = service("EventDataArchiveSvc",m_archiveSvc); 00071 if(sc.isFailure()){ 00072 warning() << "Failed to access the Archive event store" << endreq; 00073 } 00074 00075 if(m_prescale>0 || m_parentPrescale>0 || m_childrenPrescale>0){ 00076 // Initialize random number service if needed 00077 IRndmGenSvc *rgs = 0; 00078 StatusCode sc; 00079 sc = service("RndmGenSvc",rgs,true); 00080 if( sc.isFailure() ){ 00081 error() << "Failed to get random service" << endreq; 00082 return StatusCode::FAILURE; 00083 } 00084 m_uniform = new Rndm::Numbers(); 00085 sc = m_uniform->initialize(rgs, Rndm::Flat(0,1)); 00086 if( sc.isFailure() ) { 00087 error() << "Failed to initialize uniform random numbers" << endreq; 00088 return StatusCode::FAILURE; 00089 } 00090 } 00091 00092 return StatusCode::SUCCESS; 00093 }
StatusCode SmartFilterAlg::execute | ( | ) | [virtual] |
Reimplemented from GaudiAlgorithm.
Definition at line 95 of file SmartFilterAlg.cc.
00096 { 00097 StatusCode sc; 00098 00099 DayaBay::RegistrationSequence* regSeq 00100 = get<DayaBay::RegistrationSequence>("/Event/RegistrationSequence"); 00101 00102 IRegistrationSequence::Registrations& registrations 00103 = const_cast<IRegistrationSequence::Registrations&>(regSeq->registrations()); 00104 IRegistrationSequence::Registrations::iterator it, 00105 done = registrations.end(); 00106 00107 // Clear all data, if requested 00108 if(m_clearAll){ 00109 for (it = registrations.begin(); it != done; ++it) { 00110 it->setStore(false); 00111 } 00112 } 00113 00114 if(m_keepLocation.size()==0){ 00115 // No more filtering to do... 00116 return StatusCode::SUCCESS; 00117 } 00118 00119 // Loop over registrations, and look for the header we are filtering 00120 for (it = registrations.begin(); it != done; ++it) { 00121 DataObject* dobj = it->object(); 00122 debug() << "Checking object: " << dobj->registry()->identifier() << endreq; 00123 if(dobj->registry()->identifier() != m_keepLocation){ 00124 // Not the path we are interested in... 00125 continue; 00126 } 00127 double rand = 0; 00128 if(m_uniform){ 00129 rand = (*m_uniform)(); 00130 } 00131 if(m_prescale>0 && m_prescale<rand){ 00132 // Don't keep this one, prescaled 00133 continue; 00134 } 00135 // We are keeping this entry 00136 it->setStore(true); 00137 debug() << "Keeping: " << dobj->registry()->identifier() << endreq; 00138 00139 // Look for parent headers to keep 00140 if(m_keepAllParents || m_keepParents.size()>0){ 00141 double effectiveParentPrescale = m_parentPrescale; 00142 if(m_prescale>0 && m_parentPrescale>0){ 00143 effectiveParentPrescale = m_prescale*m_parentPrescale; 00144 } 00145 if( m_parentPrescale<0 || rand < effectiveParentPrescale ){ 00146 sc = this->processParentHeaders(dobj); 00147 } 00148 } 00149 00150 // Keep a reference so we can check children 00151 if( m_keepAllChildren || m_keepChildren.size()>0 ){ 00152 double effectiveChildrenPrescale = m_childrenPrescale; 00153 if(m_prescale>0 && m_childrenPrescale>0){ 00154 effectiveChildrenPrescale = m_prescale*m_childrenPrescale; 00155 } 00156 if( m_childrenPrescale<0 || rand < effectiveChildrenPrescale ){ 00157 dobj->addRef(); 00158 m_keptHeaders.push_back(dobj); 00159 if(m_keptHeaders.size() > m_maxKeptHistory){ 00160 // Remove stale header 00161 m_keptHeaders.front()->release(); 00162 m_keptHeaders.pop_front(); 00163 } 00164 } 00165 } 00166 } // end loop over registrations 00167 00168 if( m_keepAllChildren || m_keepChildren.size()>0 ) { 00169 // Loop over registrations again, and look for child headers 00170 for (it = registrations.begin(); it != done; ++it) { 00171 DataObject* childObj = it->object(); 00172 debug() << "Checking child: " << childObj->registry()->identifier() 00173 << endreq; 00174 if( !m_keepAllChildren 00175 && std::find(m_keepChildren.begin(), 00176 m_keepChildren.end(), 00177 childObj->registry()->identifier() ) 00178 == m_keepChildren.end() ){ 00179 // Not an interesting child 00180 continue; 00181 } 00182 // Is this a child? 00183 if( !this->isChild( childObj ) ) continue; 00184 // This is a child to keep 00185 it->setStore(true); 00186 debug() << "Keeping child: " << childObj->registry()->identifier() 00187 << endreq; 00188 } // end loop over child candidates 00189 } 00190 00191 return StatusCode::SUCCESS; 00192 }
StatusCode SmartFilterAlg::finalize | ( | ) | [virtual] |
Reimplemented from GaudiAlgorithm.
Definition at line 194 of file SmartFilterAlg.cc.
00195 { 00196 if(m_archiveSvc){ 00197 m_archiveSvc->release(); 00198 } 00199 if(m_uniform){ 00200 delete m_uniform; 00201 m_uniform=0; 00202 } 00203 return this->GaudiAlgorithm::finalize(); 00204 }
StatusCode SmartFilterAlg::processParentHeaders | ( | DataObject * | dobj | ) | [private] |
Definition at line 207 of file SmartFilterAlg.cc.
00208 { 00209 // Helper function to traverse and filter parent headers 00210 DayaBay::IHeader* header = dynamic_cast<DayaBay::IHeader*>(dobj); 00211 if(!header){ 00212 error() << "Invalid data object" << endreq; 00213 return StatusCode::FAILURE; 00214 } 00215 // Loop over input headers 00216 for(unsigned int ihIdx=0;ihIdx<header->inputHeaders().size();ihIdx++){ 00217 const DayaBay::IHeader* inputHeader = header->inputHeaders()[ihIdx]; 00218 const DataObject* tmpObj 00219 = dynamic_cast<const DataObject*>( inputHeader ); 00220 DataObject* parentObj = const_cast<DataObject*>(tmpObj); 00221 if( !m_keepAllParents 00222 && std::find(m_keepParents.begin(), 00223 m_keepParents.end(), 00224 parentObj->registry()->identifier()) 00225 ==m_keepParents.end()){ 00226 // Don't keep this parent 00227 continue; 00228 } 00229 ObjectReg* parentReg = this->findRegistration(parentObj); 00230 if(parentReg){ 00231 parentReg->setStore(true); 00232 debug() << "Keeping parent: " << parentObj->registry()->identifier() 00233 << endreq; 00234 // Don't forget to check the grandparents 00235 StatusCode sc = this->processParentHeaders(parentObj); 00236 if(sc.isFailure()) return sc; 00237 } 00238 } 00239 00240 return StatusCode::SUCCESS; 00241 }
ObjectReg * SmartFilterAlg::findRegistration | ( | DataObject * | dobj | ) | [private] |
Definition at line 243 of file SmartFilterAlg.cc.
00244 { 00245 // Try to find the registration for this data object 00246 00247 // FIXME: Can't navigate directly to ObjectReg for a given header object. 00248 // 00249 // Instead, use the following HACK 00250 // Check all archived regseq. to look for each input header 00251 if(m_archiveSvc){ 00252 DybArchiveList* arcRegList = 0; 00253 arcRegList = get<DybArchiveList*>(m_archiveSvc, 00254 "/Event/RegistrationSequence"); 00255 if(!arcRegList){ 00256 error() << "Failed to get archive of registrations sequences" << endreq; 00257 return 0; 00258 } 00259 for(unsigned int regSeqIdx=0; regSeqIdx<arcRegList->size(); regSeqIdx++){ 00260 DayaBay::RegistrationSequence* regSeq 00261 = dynamic_cast<DayaBay::RegistrationSequence*>( 00262 arcRegList->dataObject(regSeqIdx)); 00263 if(!regSeq){ 00264 error() << "Invalid registration sequence in AES!" << endreq; 00265 continue; 00266 } 00267 ObjectReg* objReg = regSeq->registration(dobj); 00268 if(objReg){ 00269 // Found it! 00270 return objReg; 00271 } 00272 } 00273 }else{ 00274 // Just use current RegSeq 00275 IRegistrationSequence* regSeq 00276 = get<IRegistrationSequence>("/Event/RegistrationSequence"); 00277 if(!regSeq){ 00278 error() << "Invalid registration sequence in TES!" << endreq; 00279 return 0; 00280 } 00281 ObjectReg* objReg = regSeq->registration(dobj); 00282 if(objReg){ 00283 // Found it! 00284 return objReg; 00285 } 00286 } 00287 warning() << "Failed to find registration for object " 00288 << dobj->registry()->identifier() << endreq; 00289 return 0; 00290 }
bool SmartFilterAlg::isChild | ( | const DataObject * | dobj | ) | [private] |
Definition at line 293 of file SmartFilterAlg.cc.
00293 { 00294 // Check if this object is a child of a kept object 00295 const DayaBay::IHeader* header = dynamic_cast<const DayaBay::IHeader*>(dobj); 00296 if(!header){ 00297 error() << "Invalid data object" << endreq; 00298 return false; 00299 } 00300 // Loop over input headers 00301 for(unsigned int ihIdx=0;ihIdx<header->inputHeaders().size();ihIdx++){ 00302 const DayaBay::IHeader* inputHeader = header->inputHeaders()[ihIdx]; 00303 const DataObject* parentObj 00304 = dynamic_cast<const DataObject*>( inputHeader ); 00305 if(std::find(m_keptHeaders.begin(), 00306 m_keptHeaders.end(), 00307 parentObj) != m_keptHeaders.end()){ 00308 return true; 00309 } 00310 // check ancestors as well 00311 if( this->isChild( parentObj ) ) return true; 00312 } 00313 return false; 00314 }
bool SmartFilterAlg::m_clearAll [private] |
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.
bool SmartFilterAlg::m_keepAllParents [private] |
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.
double SmartFilterAlg::m_parentPrescale [private] |
Property ParentPrescale - Prescale fraction for parent headers.
Definition at line 63 of file SmartFilterAlg.h.
bool SmartFilterAlg::m_keepAllChildren [private] |
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.
double SmartFilterAlg::m_childrenPrescale [private] |
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.