psana/test/DataSourceTest.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: DataSourceTest.cpp 7715 2014-02-28 03:30:21Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Test suite case for the DataSourceTest.
00007 //
00008 //------------------------------------------------------------------------
00009 
00010 //---------------
00011 // C++ Headers --
00012 //---------------
00013 #include <boost/make_shared.hpp>
00014 #include <algorithm>
00015 #include <iterator>
00016 #include <iostream>
00017 
00018 //-------------------------------
00019 // Collaborating Class Headers --
00020 //-------------------------------
00021 #include "psana/DataSource.h"
00022 #include "psana/InputModule.h"
00023 #include "PSEnv/Env.h"
00024 
00025 using namespace psana ;
00026 
00027 #define BOOST_TEST_MODULE DataSourceTest
00028 #include <boost/test/included/unit_test.hpp>
00029 
00030 /**
00031  * Simple test suite for module DataSourceTest.
00032  * See http://www.boost.org/doc/libs/1_36_0/libs/test/doc/html/index.html
00033  */
00034 
00035 namespace {
00036 
00037 // Implementation of the InputModulle which generates predefined sequences of events
00038 class TestInputModule: public InputModule {
00039 public:
00040   
00041   TestInputModule(const InputModule::Status states[], int nstates) : InputModule("TestInputModule")
00042   {
00043     std::copy(states, states+nstates, std::back_inserter(m_states));
00044   }
00045   
00046   virtual void beginJob(Event& evt, Env& env) {}
00047 
00048   virtual Status event(Event& evt, Env& env) {
00049     InputModule::Status state = InputModule::Stop;
00050     if (not m_states.empty()) {
00051       state = m_states.front();
00052       m_states.pop_front();
00053     }
00054     return state;
00055   }
00056   
00057   virtual void endJob(Event& evt, Env& env) {}
00058 
00059 private:
00060   
00061   std::deque<psana::InputModule::Status> m_states;  
00062 };
00063 
00064 struct Fixture {
00065   
00066   Fixture(const InputModule::Status states[], int nstates) 
00067   {
00068     boost::shared_ptr<AliasMap> amap = boost::make_shared<AliasMap>();
00069     boost::shared_ptr<PSEnv::IExpNameProvider> expNameProvider;
00070     boost::shared_ptr<PSEnv::Env> env = boost::make_shared<PSEnv::Env>("", expNameProvider, "", amap, 0);
00071     boost::shared_ptr<InputModule> input = boost::make_shared<TestInputModule>(states, nstates);
00072     const std::vector<boost::shared_ptr<Module> > modules;
00073     dataSrc = boost::make_shared<DataSource>(input, modules, env);
00074   }
00075   
00076   boost::shared_ptr<DataSource> dataSrc;
00077 };
00078 
00079 
00080 }
00081 
00082 // ==============================================================
00083 
00084 BOOST_AUTO_TEST_CASE( test_1 )
00085 {
00086   InputModule::Status states[] = {
00087   };
00088 
00089   Fixture f(states, sizeof states/sizeof states[0]);
00090   
00091   BOOST_CHECK(not f.dataSrc->empty());
00092   
00093   DataSource src;
00094   BOOST_CHECK(src.empty());
00095 }
00096 // ==============================================================
00097 
00098 BOOST_AUTO_TEST_CASE( test_events_1 )
00099 {
00100   InputModule::Status states[] = {
00101       InputModule::BeginRun,
00102       InputModule::BeginCalibCycle,
00103       InputModule::DoEvent,
00104       InputModule::DoEvent,
00105       InputModule::EndCalibCycle,
00106       InputModule::EndRun,
00107   };
00108 
00109   Fixture f(states, sizeof states/sizeof states[0]);
00110 
00111   EventIter iter = f.dataSrc->events();
00112   boost::shared_ptr<PSEvt::Event> evt;
00113   
00114   evt = iter.next();
00115   BOOST_CHECK(evt);
00116   evt = iter.next();
00117   BOOST_CHECK(evt);
00118   evt = iter.next();
00119   BOOST_CHECK(not evt);
00120 }
00121 
00122 // ==============================================================
00123 
00124 BOOST_AUTO_TEST_CASE( test_events_2 )
00125 {
00126   InputModule::Status states[] = {
00127       InputModule::BeginRun,
00128       InputModule::BeginCalibCycle,
00129       InputModule::DoEvent,
00130       InputModule::DoEvent,
00131       InputModule::EndCalibCycle,
00132       InputModule::BeginCalibCycle,
00133       InputModule::DoEvent,
00134       InputModule::DoEvent,
00135       InputModule::EndCalibCycle,
00136       InputModule::EndRun,
00137   };
00138 
00139   Fixture f(states, sizeof states/sizeof states[0]);
00140 
00141   EventIter iter = f.dataSrc->events();
00142   boost::shared_ptr<PSEvt::Event> evt;
00143   
00144   evt = iter.next();
00145   BOOST_CHECK(evt);
00146   evt = iter.next();
00147   BOOST_CHECK(evt);
00148   evt = iter.next();
00149   BOOST_CHECK(evt);
00150   evt = iter.next();
00151   BOOST_CHECK(evt);
00152   evt = iter.next();
00153   BOOST_CHECK(not evt);
00154 }
00155 
00156 // ==============================================================
00157 
00158 BOOST_AUTO_TEST_CASE( test_events_3 )
00159 {
00160   InputModule::Status states[] = {
00161       InputModule::BeginRun,
00162       InputModule::BeginCalibCycle,
00163       InputModule::DoEvent,
00164       InputModule::DoEvent,
00165       InputModule::EndCalibCycle,
00166       InputModule::EndRun,
00167       InputModule::BeginRun,
00168       InputModule::BeginCalibCycle,
00169       InputModule::DoEvent,
00170       InputModule::DoEvent,
00171       InputModule::EndCalibCycle,
00172       InputModule::EndRun,
00173   };
00174 
00175   Fixture f(states, sizeof states/sizeof states[0]);
00176 
00177   EventIter iter = f.dataSrc->events();
00178   boost::shared_ptr<PSEvt::Event> evt;
00179   
00180   evt = iter.next();
00181   BOOST_CHECK(evt);
00182   evt = iter.next();
00183   BOOST_CHECK(evt);
00184   evt = iter.next();
00185   BOOST_CHECK(evt);
00186   evt = iter.next();
00187   BOOST_CHECK(evt);
00188   evt = iter.next();
00189   BOOST_CHECK(not evt);
00190 }
00191 
00192 // ==============================================================
00193 
00194 BOOST_AUTO_TEST_CASE( test_steps_1 )
00195 {
00196   InputModule::Status states[] = {
00197       InputModule::BeginRun,
00198       InputModule::BeginCalibCycle,
00199       InputModule::DoEvent,
00200       InputModule::DoEvent,
00201       InputModule::EndCalibCycle,
00202       InputModule::EndRun,
00203   };
00204 
00205   Fixture f(states, sizeof states/sizeof states[0]);
00206 
00207   StepIter iter = f.dataSrc->steps();
00208   Step step;
00209   BOOST_CHECK(not step);
00210   
00211   step = iter.next();
00212   BOOST_CHECK(step);
00213   step = iter.next();
00214   BOOST_CHECK(not step);
00215 }
00216 
00217 // ==============================================================
00218 
00219 BOOST_AUTO_TEST_CASE( test_steps_2 )
00220 {
00221   InputModule::Status states[] = {
00222       InputModule::BeginRun,
00223       InputModule::BeginCalibCycle,
00224       InputModule::DoEvent,
00225       InputModule::DoEvent,
00226       InputModule::EndCalibCycle,
00227       InputModule::BeginCalibCycle,
00228       InputModule::DoEvent,
00229       InputModule::DoEvent,
00230       InputModule::EndCalibCycle,
00231       InputModule::EndRun,
00232   };
00233 
00234   Fixture f(states, sizeof states/sizeof states[0]);
00235 
00236   StepIter iter = f.dataSrc->steps();
00237   Step step;
00238   BOOST_CHECK(not step);
00239   
00240   step = iter.next();
00241   BOOST_CHECK(step);
00242   step = iter.next();
00243   BOOST_CHECK(step);
00244   step = iter.next();
00245   BOOST_CHECK(not step);
00246 }
00247 // ==============================================================
00248 
00249 BOOST_AUTO_TEST_CASE( test_steps_3 )
00250 {
00251   InputModule::Status states[] = {
00252       InputModule::BeginRun,
00253       InputModule::BeginCalibCycle,
00254       InputModule::DoEvent,
00255       InputModule::DoEvent,
00256       InputModule::EndCalibCycle,
00257       InputModule::EndRun,
00258       InputModule::BeginRun,
00259       InputModule::BeginCalibCycle,
00260       InputModule::DoEvent,
00261       InputModule::DoEvent,
00262       InputModule::EndCalibCycle,
00263       InputModule::EndRun,
00264   };
00265 
00266   Fixture f(states, sizeof states/sizeof states[0]);
00267 
00268   StepIter iter = f.dataSrc->steps();
00269   Step step;
00270   BOOST_CHECK(not step);
00271   
00272   step = iter.next();
00273   BOOST_CHECK(step);
00274   step = iter.next();
00275   BOOST_CHECK(step);
00276   step = iter.next();
00277   BOOST_CHECK(not step);
00278 }
00279 
00280 // ==============================================================
00281 
00282 BOOST_AUTO_TEST_CASE( test_runs_1 )
00283 {
00284   InputModule::Status states[] = {
00285       InputModule::BeginRun,
00286       InputModule::BeginCalibCycle,
00287       InputModule::DoEvent,
00288       InputModule::DoEvent,
00289       InputModule::EndCalibCycle,
00290       InputModule::EndRun,
00291   };
00292 
00293   Fixture f(states, sizeof states/sizeof states[0]);
00294 
00295   RunIter iter = f.dataSrc->runs();
00296   Run run;
00297   BOOST_CHECK(not run);
00298   
00299   run = iter.next();
00300   BOOST_CHECK(run);
00301   run = iter.next();
00302   BOOST_CHECK(not run);
00303 }
00304 
00305 // ==============================================================
00306 
00307 BOOST_AUTO_TEST_CASE( test_runs_2 )
00308 {
00309   InputModule::Status states[] = {
00310       InputModule::BeginRun,
00311       InputModule::BeginCalibCycle,
00312       InputModule::DoEvent,
00313       InputModule::DoEvent,
00314       InputModule::EndCalibCycle,
00315       InputModule::EndRun,
00316       InputModule::BeginRun,
00317       InputModule::BeginCalibCycle,
00318       InputModule::DoEvent,
00319       InputModule::DoEvent,
00320       InputModule::EndCalibCycle,
00321       InputModule::EndRun,
00322   };
00323 
00324   Fixture f(states, sizeof states/sizeof states[0]);
00325 
00326   RunIter iter = f.dataSrc->runs();
00327   Run run;
00328   BOOST_CHECK(not run);
00329   
00330   run = iter.next();
00331   BOOST_CHECK(run);
00332   run = iter.next();
00333   BOOST_CHECK(run);
00334   run = iter.next();
00335   BOOST_CHECK(not run);
00336 }
00337 
00338 // ==============================================================
00339 
00340 BOOST_AUTO_TEST_CASE( test_steps_nest_1 )
00341 {
00342   InputModule::Status states[] = {
00343       InputModule::BeginRun,
00344       InputModule::BeginCalibCycle,
00345       InputModule::DoEvent,
00346       InputModule::DoEvent,
00347       InputModule::EndCalibCycle,
00348       InputModule::EndRun,
00349   };
00350 
00351   Fixture f(states, sizeof states/sizeof states[0]);
00352 
00353   StepIter sit = f.dataSrc->steps();
00354   Step step;
00355   boost::shared_ptr<PSEvt::Event> evt;  
00356   BOOST_CHECK(not step);
00357   
00358   step = sit.next();
00359   BOOST_CHECK(step);
00360 
00361   EventIter eit = step.events();
00362   evt = eit.next();
00363   BOOST_CHECK(evt);
00364   evt = eit.next();
00365   BOOST_CHECK(evt);
00366   evt = eit.next();
00367   BOOST_CHECK(not evt);
00368     
00369   step = sit.next();
00370   BOOST_CHECK(not step);
00371 }
00372 
00373 // ==============================================================
00374 
00375 BOOST_AUTO_TEST_CASE( test_steps_nest_2 )
00376 {
00377   InputModule::Status states[] = {
00378       InputModule::BeginRun,
00379       InputModule::BeginCalibCycle,
00380       InputModule::DoEvent,
00381       InputModule::DoEvent,
00382       InputModule::EndCalibCycle,
00383       InputModule::BeginCalibCycle,
00384       InputModule::DoEvent,
00385       InputModule::DoEvent,
00386       InputModule::EndCalibCycle,
00387       InputModule::EndRun,
00388   };
00389 
00390   Fixture f(states, sizeof states/sizeof states[0]);
00391 
00392   StepIter sit = f.dataSrc->steps();
00393   Step step;
00394   boost::shared_ptr<PSEvt::Event> evt;  
00395   
00396   step = sit.next();
00397   BOOST_CHECK(step);
00398 
00399   EventIter eit = step.events();
00400   evt = eit.next();
00401   BOOST_CHECK(evt);
00402   evt = eit.next();
00403   BOOST_CHECK(evt);
00404   evt = eit.next();
00405   BOOST_CHECK(not evt);
00406     
00407   step = sit.next();
00408   BOOST_CHECK(step);
00409 
00410   eit = step.events();
00411   evt = eit.next();
00412   BOOST_CHECK(evt);
00413   evt = eit.next();
00414   BOOST_CHECK(evt);
00415   evt = eit.next();
00416   BOOST_CHECK(not evt);
00417     
00418   step = sit.next();
00419   BOOST_CHECK(not step);
00420 }
00421 
00422 // ==============================================================
00423 
00424 BOOST_AUTO_TEST_CASE( test_runs_nest_1 )
00425 {
00426   InputModule::Status states[] = {
00427       InputModule::BeginRun,
00428       InputModule::BeginCalibCycle,
00429       InputModule::DoEvent,
00430       InputModule::DoEvent,
00431       InputModule::EndCalibCycle,
00432       InputModule::EndRun,
00433   };
00434 
00435   Fixture f(states, sizeof states/sizeof states[0]);
00436 
00437   RunIter rit = f.dataSrc->runs();
00438   Run run;
00439   boost::shared_ptr<PSEvt::Event> evt;  
00440   
00441   run = rit.next();
00442   BOOST_CHECK(run);
00443 
00444   EventIter eit = run.events();
00445   evt = eit.next();
00446   BOOST_CHECK(evt);
00447   evt = eit.next();
00448   BOOST_CHECK(evt);
00449   evt = eit.next();
00450   BOOST_CHECK(not evt);
00451     
00452   run = rit.next();
00453   BOOST_CHECK(not run);
00454 }
00455 
00456 // ==============================================================
00457 
00458 BOOST_AUTO_TEST_CASE( test_runs_nest_2 )
00459 {
00460   InputModule::Status states[] = {
00461       InputModule::BeginRun,
00462       InputModule::BeginCalibCycle,
00463       InputModule::DoEvent,
00464       InputModule::DoEvent,
00465       InputModule::EndCalibCycle,
00466       InputModule::EndRun,
00467       InputModule::BeginRun,
00468       InputModule::BeginCalibCycle,
00469       InputModule::DoEvent,
00470       InputModule::DoEvent,
00471       InputModule::EndCalibCycle,
00472       InputModule::EndRun,
00473   };
00474 
00475   Fixture f(states, sizeof states/sizeof states[0]);
00476 
00477   RunIter rit = f.dataSrc->runs();
00478   Run run;
00479   boost::shared_ptr<PSEvt::Event> evt;  
00480   
00481   run = rit.next();
00482   BOOST_CHECK(run);
00483 
00484   EventIter eit = run.events();
00485   evt = eit.next();
00486   BOOST_CHECK(evt);
00487   evt = eit.next();
00488   BOOST_CHECK(evt);
00489   evt = eit.next();
00490   BOOST_CHECK(not evt);
00491     
00492   run = rit.next();
00493   BOOST_CHECK(run);
00494 
00495   eit = run.events();
00496   evt = eit.next();
00497   BOOST_CHECK(evt);
00498   evt = eit.next();
00499   BOOST_CHECK(evt);
00500   evt = eit.next();
00501   BOOST_CHECK(not evt);
00502     
00503   run = rit.next();
00504   BOOST_CHECK(not run);
00505 }
00506 
00507 // ==============================================================
00508 
00509 BOOST_AUTO_TEST_CASE( test_runs_nest_3 )
00510 {
00511   InputModule::Status states[] = {
00512       InputModule::BeginRun,
00513       InputModule::BeginCalibCycle,
00514       InputModule::DoEvent,
00515       InputModule::DoEvent,
00516       InputModule::EndCalibCycle,
00517       InputModule::EndRun,
00518   };
00519 
00520   Fixture f(states, sizeof states/sizeof states[0]);
00521 
00522   RunIter rit = f.dataSrc->runs();
00523   Run run;
00524   Step step;
00525   boost::shared_ptr<PSEvt::Event> evt;  
00526   
00527   run = rit.next();
00528   BOOST_CHECK(run);
00529 
00530   StepIter sit = run.steps();
00531 
00532   step = sit.next();
00533   BOOST_CHECK(step);
00534 
00535   EventIter eit = step.events();
00536   evt = eit.next();
00537   BOOST_CHECK(evt);
00538   evt = eit.next();
00539   BOOST_CHECK(evt);
00540   evt = eit.next();
00541   BOOST_CHECK(not evt);
00542   
00543   step = sit.next();
00544   BOOST_CHECK(not step);
00545 
00546   run = rit.next();
00547   BOOST_CHECK(not run);
00548 }
00549 
00550 // ==============================================================
00551 
00552 BOOST_AUTO_TEST_CASE( test_runs_nest_4 )
00553 {
00554   InputModule::Status states[] = {
00555       InputModule::BeginRun,
00556       InputModule::BeginCalibCycle,
00557       InputModule::DoEvent,
00558       InputModule::DoEvent,
00559       InputModule::EndCalibCycle,
00560       InputModule::BeginCalibCycle,
00561       InputModule::DoEvent,
00562       InputModule::DoEvent,
00563       InputModule::EndCalibCycle,
00564       InputModule::EndRun,
00565   };
00566 
00567   Fixture f(states, sizeof states/sizeof states[0]);
00568 
00569   RunIter rit = f.dataSrc->runs();
00570   Run run;
00571   Step step;
00572   boost::shared_ptr<PSEvt::Event> evt;  
00573   
00574   run = rit.next();
00575   BOOST_CHECK(run);
00576 
00577   StepIter sit = run.steps();
00578   step = sit.next();
00579   BOOST_CHECK(step);
00580 
00581   EventIter eit = step.events();
00582   evt = eit.next();
00583   BOOST_CHECK(evt);
00584   evt = eit.next();
00585   BOOST_CHECK(evt);
00586   evt = eit.next();
00587   BOOST_CHECK(not evt);
00588   
00589   step = sit.next();
00590   BOOST_CHECK(step);
00591 
00592   eit = step.events();
00593   evt = eit.next();
00594   BOOST_CHECK(evt);
00595   evt = eit.next();
00596   BOOST_CHECK(evt);
00597   evt = eit.next();
00598   BOOST_CHECK(not evt);
00599   
00600   step = sit.next();
00601   BOOST_CHECK(not step);
00602 
00603   run = rit.next();
00604   BOOST_CHECK(not run);
00605 }
00606 
00607 // ==============================================================
00608 
00609 BOOST_AUTO_TEST_CASE( test_runs_nest_5 )
00610 {
00611   InputModule::Status states[] = {
00612       InputModule::BeginRun,
00613       InputModule::BeginCalibCycle,
00614       InputModule::DoEvent,
00615       InputModule::DoEvent,
00616       InputModule::EndCalibCycle,
00617       InputModule::BeginCalibCycle,
00618       InputModule::DoEvent,
00619       InputModule::DoEvent,
00620       InputModule::EndCalibCycle,
00621       InputModule::EndRun,
00622       InputModule::BeginRun,
00623       InputModule::BeginCalibCycle,
00624       InputModule::DoEvent,
00625       InputModule::DoEvent,
00626       InputModule::EndCalibCycle,
00627       InputModule::BeginCalibCycle,
00628       InputModule::DoEvent,
00629       InputModule::DoEvent,
00630       InputModule::EndCalibCycle,
00631       InputModule::EndRun,
00632   };
00633 
00634   Fixture f(states, sizeof states/sizeof states[0]);
00635 
00636   RunIter rit = f.dataSrc->runs();
00637   Run run;
00638   Step step;
00639   boost::shared_ptr<PSEvt::Event> evt;  
00640   
00641   run = rit.next();
00642   BOOST_CHECK(run);
00643 
00644   StepIter sit = run.steps();
00645   step = sit.next();
00646   BOOST_CHECK(step);
00647 
00648   EventIter eit = step.events();
00649   evt = eit.next();
00650   BOOST_CHECK(evt);
00651   evt = eit.next();
00652   BOOST_CHECK(evt);
00653   evt = eit.next();
00654   BOOST_CHECK(not evt);
00655   
00656   step = sit.next();
00657   BOOST_CHECK(step);
00658 
00659   eit = step.events();
00660   evt = eit.next();
00661   BOOST_CHECK(evt);
00662   evt = eit.next();
00663   BOOST_CHECK(evt);
00664   evt = eit.next();
00665   BOOST_CHECK(not evt);
00666   
00667   step = sit.next();
00668   BOOST_CHECK(not step);
00669 
00670   run = rit.next();
00671   BOOST_CHECK(run);
00672 
00673   sit = run.steps();
00674   step = sit.next();
00675   BOOST_CHECK(step);
00676 
00677   eit = step.events();
00678   evt = eit.next();
00679   BOOST_CHECK(evt);
00680   evt = eit.next();
00681   BOOST_CHECK(evt);
00682   evt = eit.next();
00683   BOOST_CHECK(not evt);
00684   
00685   step = sit.next();
00686   BOOST_CHECK(step);
00687 
00688   eit = step.events();
00689   evt = eit.next();
00690   BOOST_CHECK(evt);
00691   evt = eit.next();
00692   BOOST_CHECK(evt);
00693   evt = eit.next();
00694   BOOST_CHECK(not evt);
00695   
00696   step = sit.next();
00697   BOOST_CHECK(not step);
00698 
00699   run = rit.next();
00700   BOOST_CHECK(not run);
00701 }
00702 
00703 // ==============================================================
00704 

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7