Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-29 07:06:07

0001 #pragma once
0002 
0003 #include <JANA/JApplication.h>
0004 #include <JANA/JEvent.h>
0005 #include <JANA/JEventProcessor.h>
0006 #include <algorithm>
0007 #include <cctype>
0008 #include <memory>
0009 #include <string>
0010 #include <vector>
0011 
0012 #include "extensions/spdlog/SpdlogMixin.h"
0013 
0014 class DumpFlags_processor: public JEventProcessor, public eicrecon::SpdlogMixin
0015 {
0016 public:
0017     explicit DumpFlags_processor(JApplication *);
0018     ~DumpFlags_processor() override = default;
0019 
0020     //----------------------------
0021     // Init
0022     //
0023     // This is called once before the first call to the Process method
0024     // below. You may, for example, want to open an output file here.
0025     // Only one thread will call this.
0026     void Init() override;
0027 
0028     //----------------------------
0029     // Process
0030     //
0031     // This is called for every event. Multiple threads may call this
0032     // simultaneously. If you write something to an output file here
0033     // then make sure to protect it with a mutex or similar mechanism.
0034     // Minimize what is done while locked since that directly affects
0035     // the multi-threaded performance.
0036     void Process(const std::shared_ptr<const JEvent>& event) override;
0037 
0038     //----------------------------
0039     // Finish
0040     //
0041     // This is called once after all events have been processed. You may,
0042     // for example, want to close an output file here.
0043     // Only one thread will call this.
0044     void Finish() override;
0045 
0046 private:
0047     /// If not empty, a python eicrecon run file is created
0048     std::string m_python_file_name = "";
0049 
0050     /// If not null, such markdown file is created
0051     std::string m_markdown_file_name = "";
0052 
0053     /// If not null, such json file is created
0054     std::string m_json_file_name = "";
0055 
0056     /// If not null, such jana configuration file is created
0057     std::string m_janaconfig_file_name = "jana.conf";
0058 
0059     /// Print parameter summary to screen at end of job
0060     bool m_print_to_screen = true;
0061 
0062     /// Print only reconstruction flags
0063     bool m_only_reco = true;
0064 
0065     /// Prefixes of flags that belongs to reconstruction parameters
0066     std::vector<std::string> m_reco_prefixes = {
0067             "B0TRK",
0068             "BEMC",
0069             "DRICH",
0070             "BTRK",
0071             "BVTX",
0072             "ECTRK",
0073             "EEMC",
0074             "FOFFMTRK",
0075             "HCAL",
0076             "MPGD",
0077             "RPOTS",
0078             "LOWQ2",
0079             "ZDC",
0080             "Tracking",
0081             "Reco",
0082             "Digi",
0083             "Calorimetry"
0084     };
0085 
0086     /// Checks if flags starts with one of m_reco_prefixes
0087     bool isReconstructionFlag(std::string flag_name) { // (!) copy value is important here! don't do const& NOLINT(performance-unnecessary-value-param)
0088 
0089         // convert flag_name to lower
0090         std::transform(flag_name.begin(), flag_name.end(), flag_name.begin(), static_cast<int (*)(int)>(&std::tolower));
0091 
0092         for(auto subsystem: m_reco_prefixes) {     // (!) copy value is important here! don't do auto&
0093 
0094             // Convert subsystem to lower
0095             std::transform(subsystem.begin(), subsystem.end(), subsystem.begin(), static_cast<int (*)(int)>(&std::tolower));
0096 
0097             // if not sure, read this
0098             // https://stackoverflow.com/questions/1878001/how-do-i-check-if-a-c-stdstring-starts-with-a-certain-string-and-convert-a
0099             if (flag_name.rfind(subsystem, 0) == 0) { // pos=0 limits the search to the prefix
0100                 // s starts with prefix
0101                 return true;
0102             }
0103         }
0104 
0105         // flag prefix is not in list
0106         return false;
0107     }
0108 
0109     std::string findCategory(std::string flag_name) { // (!) copy value is important here! don't do const& NOLINT(performance-unnecessary-value-param)
0110 
0111         // convert flag_name to lower
0112         std::transform(flag_name.begin(), flag_name.end(), flag_name.begin(), static_cast<int (*)(int)>(&std::tolower));
0113 
0114         for(auto subsystem: m_reco_prefixes) {     // (!) copy value is important here! don't do auto&
0115 
0116             // Convert subsystem to lower
0117             std::string original_subsystem_name = subsystem;
0118             std::transform(subsystem.begin(), subsystem.end(), subsystem.begin(), static_cast<int (*)(int)>(&std::tolower));
0119 
0120             // if not sure, read this
0121             // https://stackoverflow.com/questions/1878001/how-do-i-check-if-a-c-stdstring-starts-with-a-certain-string-and-convert-a
0122             if (flag_name.rfind(subsystem, 0) == 0) { // pos=0 limits the search to the prefix
0123                 // s starts with prefix
0124                 return original_subsystem_name;
0125             }
0126         }
0127 
0128         // flag prefix is not in list
0129         return "";
0130     }
0131 };