Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:18

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 
0006 #include "DstExampleSource.h"
0007 
0008 #include <JANA/JApplication.h>
0009 #include <JANA/JEvent.h>
0010 #include "DataObjects.h"
0011 
0012 
0013 DstExampleSource::DstExampleSource() : JEventSource() {
0014     SetTypeName(NAME_OF_THIS); // Provide JANA with class name
0015     SetCallbackStyle(CallbackStyle::ExpertMode);
0016 }
0017 
0018 void DstExampleSource::Open() {
0019 
0020     /// Open is called exactly once when processing begins.
0021     
0022     /// Get any configuration parameters from the JApplication
0023     // GetApplication()->SetDefaultParameter("DstExampleSource:random_seed", m_seed, "Random seed");
0024 
0025     /// For opening a file, get the filename via:
0026     // std::string resource_name = GetResourceName();
0027     /// Open the file here!
0028 }
0029 
0030 void DstExampleSource::Close() {
0031 }
0032 
0033 JEventSource::Result DstExampleSource::Emit(JEvent& event) {
0034 
0035     /// Calls to GetEvent are synchronized with each other, which means they can
0036     /// read and write state on the JEventSource without causing race conditions.
0037     
0038     /// Configure event and run numbers
0039     static size_t current_event_number = 1;
0040     event.SetEventNumber(current_event_number++);
0041     event.SetRunNumber(22);
0042 
0043     /// Limit ourselves to 1 event
0044     if (current_event_number > 2) {
0045         return Result::FailureFinished;
0046     }
0047 
0048     /// Insert some canned MyJObjects
0049     std::vector<MyJObject*> my_jobjects;
0050     my_jobjects.push_back(new MyJObject(7,7,1.8));
0051     my_jobjects.push_back(new MyJObject(8,8,9.9));
0052     auto my_jobj_fac = event.Insert(my_jobjects);
0053 
0054     /// Enable automatic upcast to JObject
0055     my_jobj_fac->EnableGetAs<JObject>();
0056 
0057     /// Insert some canned MyRenderables
0058     std::vector<MyRenderable*> my_renderables;
0059     my_renderables.push_back(new MyRenderable(0,0,22.2));
0060     my_renderables.push_back(new MyRenderable(0,1,17.0));
0061     my_renderables.push_back(new MyRenderable(1,0,21.9));
0062     auto my_ren_fac = event.Insert(my_renderables);
0063 
0064     /// Enable automatic upcast to Renderable
0065     my_ren_fac->EnableGetAs<Renderable>();
0066 
0067     /// Insert some canned MyRenderableJObjects
0068     std::vector<MyRenderableJObject*> my_renderable_jobjects;
0069     my_renderable_jobjects.push_back(new MyRenderableJObject(1,1,1.1));
0070     auto my_both_fac = event.Insert(my_renderable_jobjects, "from_source");
0071 
0072     /// Enable automatic upcast to both JObjects and Renderable
0073     my_both_fac->EnableGetAs<JObject>();
0074     my_both_fac->EnableGetAs<Renderable>();
0075 
0076     return Result::Success;
0077 }
0078 
0079 std::string DstExampleSource::GetDescription() {
0080     return "Dummy source for demonstrating DST example";
0081 }
0082 
0083 
0084 template <>
0085 double JEventSourceGeneratorT<DstExampleSource>::CheckOpenable(std::string resource_name) {
0086 
0087     /// CheckOpenable() decides how confident we are that this EventSource can handle this resource.
0088     ///    0.0        -> 'Cannot handle'
0089     ///    (0.0, 1.0] -> 'Can handle, with this confidence level'
0090     
0091     /// To determine confidence level, feel free to open up the file and check for magic bytes or metadata.
0092     /// Returning a confidence <- {0.0, 1.0} is perfectly OK!
0093     
0094     return (resource_name == "DstExampleSource") ? 1.0 : 0.0;
0095 }