Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright 2020, Jefferson Science Associates, LLC.
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 
0004 #ifndef _JControlEventProcessor_h_
0005 #define _JControlEventProcessor_h_
0006 
0007 #include <map>
0008 #include <set>
0009 #include <sstream>
0010 #include <JANA/JEventProcessor.h>
0011 #include <JANA/Services/JComponentManager.h>
0012 #include <JANA/Utils/JStringification.h>
0013 
0014 template <typename T>
0015 std::string ToString(const T &t){
0016     std::stringstream ss;
0017     ss << t;
0018     return ss.str();
0019 }
0020 
0021 /// The JControlEventProcessor class is used by the janacontrol plugin, primarily
0022 /// to help with its debugging feature. It can be used to stall event processing
0023 /// while events are inspected. It will also grab lists of factories and objects
0024 /// from a JEvent and encode them in forms (e.g. strings) that can be easily
0025 /// browsed.
0026 class JControlEventProcessor : public JEventProcessor {
0027 
0028     // Shared state (e.g. histograms, TTrees, TFiles) live
0029     std::mutex m_mutex;
0030 
0031     struct JFactorySummaryCompare
0032     {
0033         bool operator() (const JFactorySummary& lhs, const JFactorySummary& rhs) const
0034         {
0035             if( lhs.object_name != rhs.object_name ) return lhs.object_name < rhs.object_name;
0036             if( lhs.factory_tag != rhs.factory_tag ) return lhs.factory_tag < rhs.factory_tag;
0037             if( lhs.factory_name != rhs.factory_name ) return lhs.factory_name < rhs.factory_name;
0038             return lhs.plugin_name < rhs.plugin_name;
0039         }
0040     };
0041 
0042 
0043 public:
0044 
0045     JControlEventProcessor(JApplication *japp=nullptr);
0046     virtual ~JControlEventProcessor() = default;
0047 
0048     void Init() override;
0049     void Process(const std::shared_ptr<const JEvent>& event) override;
0050     void Finish() override;
0051 
0052     void SetDebugMode(bool debug_mode);
0053     bool GetDebugMode(void){return _debug_mode;}
0054     void SetFetchFactories(std::set<std::string> &factorytags);
0055     bool GetFetchFlag(void){return _fetch_flag;}
0056     void FetchObjects(std::shared_ptr<const JEvent> jevent);
0057     void FetchObjectsNow(void);
0058     auto GetLastFetchResult(void){return _fetch_object_summaries;}
0059     auto GetLastFetchMetadata(void){return _fetch_metadata;}
0060     void NextEvent(void);
0061     void GetObjectStatus( std::map<JFactorySummary, std::size_t> &factory_object_counts );
0062     void GetObjects(const std::string &factory_name, const std::string &factory_tag, const std::string &object_name, std::map<std::string, JObjectSummary> &objects);
0063     uint32_t GetRunNumber(void);
0064     uint64_t GetEventNumber(void);
0065 
0066 protected:
0067     bool _debug_mode    = false;
0068     bool _wait          = true;
0069     bool _fetch_flag    = false;
0070     std::set<std::string> _fetch_factorytags;
0071     std::map<std::string, std::string> _fetch_metadata;
0072     std::map<std::string, std::map<std::string, JObjectSummary> > _fetch_object_summaries;
0073     std::shared_ptr<const JEvent> _jevent;
0074     std::shared_ptr<JStringification> jstringification;
0075 };
0076 
0077 // Compare function to allow JFactorySummary to be used as keys in std::map
0078 // ( used in argument to JControlEventProcessor::GetObjectStatus() )
0079 inline bool operator<(const JFactorySummary& lhs, const JFactorySummary& rhs){
0080     if( lhs.object_name != rhs.object_name ) return lhs.object_name < rhs.object_name;
0081     if( lhs.factory_tag != rhs.factory_tag ) return lhs.factory_tag < rhs.factory_tag;
0082     if( lhs.factory_name != rhs.factory_name ) return lhs.factory_name < rhs.factory_name;
0083     return lhs.plugin_name < rhs.plugin_name;
0084 }
0085 
0086 #endif // _JControlEventProcessor_h_
0087