| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# StoreSnifferAlg.cpp

Go to the documentation of this file.

    00001 // $Header: $
    00002 //  ====================================================================
    00003 //  StoreSnifferAlg.cpp
    00004 //  --------------------------------------------------------------------
    00005 //
    00006 //  Author    : Markus Frank
    00007 //
    00008 //  ====================================================================
    00009 #include "GaudiKernel/DataObject.h"
    00010 #include "GaudiKernel/LinkManager.h"
    00011 #include "GaudiKernel/IDataProviderSvc.h"
    00012 #include "GaudiKernel/IDataManagerSvc.h"
    00013 #include "GaudiKernel/SmartDataPtr.h"
    00014 #include "GaudiKernel/AlgFactory.h"
    00015 #include "GaudiKernel/Algorithm.h"
    00016 #include "GaudiKernel/IRegistry.h"
    00017 #include "GaudiKernel/MsgStream.h"
    00018 #include "GaudiKernel/SmartIF.h"
    00019
    00020 using namespace std;
    00021
    00030 class StoreSnifferAlg : public Algorithm {
    00031 public:
    00032
    00033   SmartIF<IDataManagerSvc> m_mgr;
    00034
    00035   struct LeafInfo {
    00036     int  count;
    00037     int  id;
    00038     CLID clid;
    00039   };
    00040   typedef map<string, LeafInfo> SniffInfo;
    00041   typedef map<string,map<int,int> > Correlations;
    00042
    00043   SniffInfo    m_info, m_curr;
    00044   Correlations m_corr, m_links;
    00045
    00047   StoreSnifferAlg(const string& name, ISvcLocator* pSvc) : Algorithm(name, pSvc)  {
    00048   }
    00050   virtual ~StoreSnifferAlg()     {
    00051   }
    00052
    00053   size_t explore(IRegistry* pObj)    {
    00054     if ( 0 != pObj )    {
    00055       SmartIF<IDataManagerSvc> mgr(eventSvc());
    00056       if ( mgr )    {
    00057         typedef vector<IRegistry*> Leaves;
    00058         Leaves leaves;
    00059         StatusCode sc = m_mgr->objectLeaves(pObj, leaves);
    00060         if ( sc.isSuccess() )  {
    00061           for (Leaves::const_iterator i=leaves.begin(); i != leaves.end(); i++ )   {
    00062             IRegistry* pReg = *i;
    00063             const string& id = pReg->identifier();
    00065             if ( pReg->address() && pReg->object() )  {
    00066               SniffInfo::iterator j=m_info.find(id);
    00067               if ( j == m_info.end() )   {
    00068                 m_info[id] = LeafInfo();
    00069                 j = m_info.find(id);
    00070                 (*j).second.count = 0;
    00071                 (*j).second.id    = m_info.size();
    00072                 (*j).second.clid  = pReg->object()->clID();
    00073               }
    00074               m_curr[id].id    = m_info[id].id;
    00075               m_curr[id].count = explore(pReg);
    00076             }
    00077           }
    00078           return leaves.size();
    00079         }
    00080       }
    00081     }
    00082     return 0;
    00083   }
    00084
    00086   virtual StatusCode initialize()   {
    00087     m_info.clear();
    00088     m_mgr = eventSvc();
    00089     return StatusCode::SUCCESS;
    00090   }
    00091
    00093   virtual StatusCode finalize() {
    00094     MsgStream log(msgSvc(), name());
    00095     log << MSG::ALWAYS << "== BEGIN ============= Access list content:" << m_info.size() << endmsg;
    00096     for(SniffInfo::const_iterator i=m_info.begin(); i!=m_info.end();++i) {
    00097       const LeafInfo& info = (*i).second;
    00098       log << "== ITEM == " << right << setw(4) << dec << info.id << " clid:"
    00099           << right << setw(8) << hex << info.clid << " Count:"
    00100           << right << setw(6) << dec << info.count << " "
    00101           << (*i).first+":"
    00102           << endmsg;
    00103       Correlations::const_iterator c=m_corr.find((*i).first);
    00104       if ( c != m_corr.end() ) {
    00105         int cnt = 0;
    00106         log << "== CORRELATIONS:" << (*c).second.size() << endmsg;
    00107         for(map<int,int>::const_iterator k=(*c).second.begin(); k!=(*c).second.end();++k) {
    00108           if ( (*k).second > 0 ) {
    00109             log << dec << (*k).first << ":" << (*k).second << "  ";
    00110             if ( ++cnt == 10 ) {
    00111               cnt = 0;
    00112               log << endmsg;
    00113             }
    00114           }
    00115         }
    00116         if ( cnt > 0 ) log << endmsg;
    00117       }
    00118       Correlations::const_iterator l=m_links.find((*i).first);
    00119       if ( l != m_links.end() ) {
    00120         int cnt = 0;
    00121         log << "== LINKS:" << (*l).second.size() << endmsg;
    00122         for(map<int,int>::const_iterator k=(*l).second.begin(); k!=(*l).second.end();++k) {
    00123           if ( (*k).second > 0 ) {
    00124             log << dec << (*k).first << ":" << (*k).second << "  ";
    00125             if ( ++cnt == 10 ) {
    00126               cnt = 0;
    00127               log << endmsg;
    00128             }
    00129           }
    00130         }
    00131         if ( cnt > 0 ) log << endmsg;
    00132       }
    00133     }
    00134     log << MSG::ALWAYS << "== END =============== Access list content:" << m_info.size() << endmsg;
    00135     m_info.clear();
    00136     m_mgr = 0;
    00137     return StatusCode::SUCCESS;
    00138   }
    00139
    00141   virtual StatusCode execute()    {
    00142     SmartDataPtr<DataObject> root(eventSvc(),"/Event");
    00143     if ( root )    {
    00144       m_curr.clear();
    00145       m_curr["/Event"].count = explore(root->registry());
    00146       m_curr["/Event"].clid  = root->clID();
    00147       m_curr["/Event"].id    = m_curr.size();
    00148       for(SniffInfo::const_iterator i=m_curr.begin(); i!=m_curr.end();++i) {
    00149         LeafInfo& li = m_info[(*i).first];
    00150         li.count++;
    00151       }
    00152       for(SniffInfo::const_iterator i=m_info.begin(); i!=m_info.end();++i) {
    00153         const string& nam = (*i).first;
    00154         // const LeafInfo& leaf = (*i).second;
    00155         Correlations::iterator c=m_corr.find(nam);
    00156         if ( c == m_corr.end() )  {
    00157           m_corr[nam] = map<int,int>();
    00158           c = m_corr.find(nam);
    00159         }
    00160         for(SniffInfo::const_iterator l=m_curr.begin(); l!=m_curr.end();++l) {
    00161           const LeafInfo& li = (*l).second;
    00162           map<int,int>::iterator k = (*c).second.find(li.id);
    00163           if ( k==(*c).second.end() ) (*c).second[li.id] = 0;
    00164           ++((*c).second[li.id]);
    00165         }
    00166
    00167         c=m_links.find(nam);
    00168         if ( c == m_links.end() )  {
    00169           m_links[nam] = map<int,int>();
    00170           c = m_links.find(nam);
    00171         }
    00172         if ( m_curr.find(nam) != m_curr.end() ) {
    00173           SmartDataPtr<DataObject> obj(eventSvc(),nam);
    00174           if ( obj ) {
    00175             LinkManager* m = obj->linkMgr();
    00176             for(long l=0; l<m->size(); ++l) {
    00177               LinkManager::Link* lnk=m->link(l);
    00178               SniffInfo::const_iterator il=m_curr.find(lnk->path());
    00179               // cout << "Link:" << lnk->path() << " " << (char*)(il != m_curr.end() ? "Found" : "Not there") << endl;
    00180               if ( il != m_curr.end() ) {
    00181                 if ( lnk->object() ) {
    00182                   const LeafInfo& li = (*il).second;
    00183                   map<int,int>::iterator k = (*c).second.find(li.id);
    00184                   if ( k==(*c).second.end() ) (*c).second[li.id] = 0;
    00185                   ++((*c).second[li.id]);
    00186                 }
    00187               }
    00188             }
    00189           }
    00190         }
    00191       }
    00192       return StatusCode::SUCCESS;
    00193     }
    00194     return StatusCode::SUCCESS;
    00195   }
    00196 };
    00197
    00198 DECLARE_ALGORITHM_FACTORY(StoreSnifferAlg)