| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

TestInputLoadAlg.cc

Go to the documentation of this file.
00001 #include "TestInputLoadAlg.h"
00002 
00003 #include "Event/HeaderObject.h"
00004 
00005 #include "GaudiKernel/MsgStream.h"
00006 
00007 #include <sstream>
00008 
00009 using namespace DayaBay;
00010 
00011 TestInputLoadAlg::TestInputLoadAlg(const std::string& name, ISvcLocator* pSvcLocator)
00012     : GaudiAlgorithm(name,pSvcLocator)
00013 {
00014     declareProperty("Loader", m_loader, "A IDybInputLoadTool");
00015     declareProperty("Policy", m_policy, "A IDybEntryPolicyTool");
00016     declareProperty("Path", m_path, "A TES-like path to the HeaderObject to load");
00017     declareProperty("TestType", m_test_type=0, "Which tests to run [0,1,2,3,4]");
00018 }
00019 
00020 TestInputLoadAlg::~TestInputLoadAlg()
00021 {
00022 }
00023 
00024 StatusCode TestInputLoadAlg::initialize()
00025 {
00026     MsgStream log(msgSvc(), "TestInputLoadAlg");
00027 
00028     {
00029         StatusCode sc = m_loader.retrieve();
00030         if (sc.isFailure()) {
00031             log << MSG::ERROR << "Failed to retrieve " << m_loader << endreq;
00032             return sc;
00033         }
00034     }
00035 
00036     {
00037         StatusCode sc = m_policy.retrieve();
00038         if (sc.isFailure()) {
00039             log << MSG::ERROR << "Failed to retrieve " << m_policy << endreq;
00040             return sc;
00041         }
00042     }
00043     return StatusCode::SUCCESS;
00044 }
00045 
00046 // Walk the input headers such that bucket gets filled with oldest
00047 // HeaderObject first
00048 void collect_input_headers(MsgStream& log, const HeaderObject* start, 
00049                            std::vector<const HeaderObject*> &bucket)
00050 {
00051     std::vector<const IHeader*> ihlist = start->inputHeaders();
00052 
00053     for (size_t ind=0; ind<ihlist.size(); ++ind) {
00054         const HeaderObject* ho = dynamic_cast<const HeaderObject*>(ihlist[ind]);
00055         log << MSG::DEBUG << "Recursing on " 
00056             << const_cast<HeaderObject*>(ho)->defLoc() 
00057             << " with bucked filed to " << bucket.size()
00058             << endreq;
00059         collect_input_headers(log,ho,bucket);
00060     }
00061 
00062     log << MSG::DEBUG << "Saving " 
00063         << const_cast<HeaderObject*>(start)->defLoc() << endreq;
00064     bucket.push_back(start);
00065 
00066 }
00067 
00068 StatusCode TestInputLoadAlg::get_header(int entry, const std::string& path, bool input_headers)
00069 {
00070     MsgStream log(msgSvc(), "TestInputLoadAlg");
00071 
00072     HeaderObject* ho = m_loader->get_header(entry,path,input_headers);
00073     if (!ho) {
00074         log << MSG::ERROR << "Failed to get HeaderObject at entry "
00075             << entry << " and path \"" << path << "\"" << endreq;
00076         return StatusCode::FAILURE;
00077     }
00078     log << MSG::DEBUG << "Found Header object at entry "
00079         << entry << " and path \"" << path << "\"" << endreq;
00080     log << MSG::DEBUG << ho->earliest() << endreq;
00081     std::vector<const HeaderObject*> bucket;
00082     collect_input_headers(log, ho, bucket);
00083     
00084     log << MSG::DEBUG << "Got " << bucket.size() << " HeaderObjects" << endreq;
00085 
00086     for (size_t ind=0; ind<bucket.size(); ++ind) {
00087         HeaderObject* hop = const_cast<HeaderObject*>(bucket[ind]);
00088         log << MSG::DEBUG << "Putting HeaderObject at " << hop->defLoc() << endreq;
00089         this->put(hop,hop->defLoc());
00090     }
00091 
00092     return StatusCode::SUCCESS;
00093 }
00094 
00095 StatusCode TestInputLoadAlg::get_frame(int entry, const std::string& path, bool input_headers)
00096 {
00097     MsgStream log(msgSvc(), "TestInputLoadAlg");
00098 
00099     IDybInputLoadTool::ExecutionFrame ef = m_loader->get_frame(entry,path,input_headers);
00100     if (!ef.size()) {
00101         log << MSG::ERROR << "Failed to get non-empty ExecutionFrame at entry "
00102             << entry << " and path \"" << path << "\"" << endreq;
00103         return StatusCode::FAILURE;
00104     }
00105     log << MSG::DEBUG << "Found ExecutionFrame object at entry "
00106         << entry << " and path \"" << path << "\"" << endreq;
00107     
00108     log << MSG::DEBUG << "Got " << ef.size() << " HeaderObjects" << endreq;
00109 
00110     for (size_t ind=0; ind < ef.size(); ++ind) {
00111         log << MSG::DEBUG << ind << " " << ef[ind].first << endreq;
00112         this->put(ef[ind].second,ef[ind].first);
00113     }
00114 
00115     return StatusCode::SUCCESS;
00116 }
00117 
00118 StatusCode TestInputLoadAlg::execute()
00119 {
00120     MsgStream log(msgSvc(), "TestInputLoadAlg");
00121 
00122     int entry = m_policy->next_entry();
00123 
00124     int which = entry%4;
00125     if (m_test_type) which = m_test_type-1;
00126 
00127     log << MSG::DEBUG << "test " << which << " loading entry " << entry << endreq;
00128     
00129     std::string rspath = "/Event/RegistrationSequence";
00130 
00131     switch(which) {
00132     case 0:
00133         return this->get_header(entry,m_path,false);
00134         break;
00135     case 1:
00136         return this->get_header(entry,m_path,true);
00137         break;
00138     case 2:
00139         return this->get_frame(entry,rspath,true);
00140         break;
00141     case 3:
00142         return this->get_frame(entry,rspath,true);
00143         break;
00144     }
00145 
00146     log << MSG::ERROR << "got unknown test code: " << which+1 << " should be in [0-4]" << endreq;
00147     return StatusCode::FAILURE;
00148 }
00149 
00150 StatusCode TestInputLoadAlg::finalize()
00151 {
00152     return StatusCode::SUCCESS;
00153 }
00154 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:47:44 2011 for DybIO by doxygen 1.4.7