Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:55:24

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