File indexing completed on 2026-04-05 08:08:19
0001 #include "DstPhotonSelection.h"
0002 #include <fun4all/Fun4AllReturnCodes.h>
0003 #include <phool/getClass.h>
0004
0005
0006 #include <odbc++/connection.h>
0007 #include <odbc++/drivermanager.h>
0008 #include <odbc++/resultset.h>
0009 #include <odbc++/resultsetmetadata.h>
0010 #include <uspin/SpinDBContent.h>
0011 #include <uspin/SpinDBContentv1.h>
0012 #include <uspin/SpinDBOutput.h>
0013
0014 #include <format>
0015 #include <fstream>
0016 #include <iomanip>
0017 #include <iostream>
0018 #include <sstream>
0019
0020 DstPhotonSelection::DstPhotonSelection(const std::string &name, const int runnb)
0021 : SubsysReco(name)
0022 , runnumber(runnb)
0023 {
0024 }
0025
0026 DstPhotonSelection::~DstPhotonSelection()
0027 {
0028 }
0029
0030 int DstPhotonSelection::Init(PHCompositeNode *)
0031 {
0032 return 0;
0033 }
0034
0035 int DstPhotonSelection::InitRun(PHCompositeNode *topNode)
0036 {
0037 gl1packet = findNode::getClass<Gl1Packet>(topNode, "14001");
0038 if (!gl1packet)
0039 {
0040 std::cerr << "AnNeutralMeson Gl1Packet node is missing" << std::endl;
0041 return Fun4AllReturnCodes::ABORTRUN;
0042 }
0043
0044
0045 odbc::Connection *con = nullptr;
0046 try
0047 {
0048 con = odbc::DriverManager::getConnection(db_name, user_name, "");
0049 }
0050 catch (odbc::SQLException &e)
0051 {
0052 std::cout << std::format("Error: {}.", e.getMessage()) << std::endl;
0053 return Fun4AllReturnCodes::ABORTRUN;
0054 }
0055
0056 std::stringstream cmd;
0057 cmd << "SELECT * FROM " << table_name << " WHERE runnumber=" << runnumber << ";";
0058 odbc::Statement *stmt = con->createStatement();
0059 odbc::ResultSet *rs = nullptr;
0060 try
0061 {
0062 rs = stmt->executeQuery(cmd.str());
0063 }
0064 catch (odbc::SQLException &e)
0065 {
0066 std::cout << std::format("Error: {}.", e.getMessage()) << std::endl;
0067 delete rs;
0068 delete stmt;
0069 delete con;
0070 return Fun4AllReturnCodes::ABORTRUN;
0071 }
0072
0073 if (rs->next() == 0)
0074 {
0075 std::cout << std::format("Error: Can't find GL1 scaledown data for run {}", runnumber) << std::endl;
0076 delete rs;
0077 delete stmt;
0078 delete con;
0079 return Fun4AllReturnCodes::ABORTRUN;
0080 }
0081
0082
0083 int ncols = rs->getMetaData()->getColumnCount();
0084 for (int icol = 0; icol < ncols; icol++)
0085 {
0086 std::string col_name = rs->getMetaData()->getColumnName(icol + 1);
0087
0088 if (col_name.starts_with("scaledown"))
0089 {
0090 int scaledown_index = std::stoi(col_name.substr(9,2));
0091 std::string cont = rs->getString(col_name);
0092 scaledown[scaledown_index] = std::stoi(cont);
0093 }
0094 }
0095
0096 return Fun4AllReturnCodes::EVENT_OK;
0097 }
0098
0099 int DstPhotonSelection::process_event(PHCompositeNode *)
0100 {
0101
0102 live_trigger = gl1packet->getLiveVector();
0103 scaled_trigger = gl1packet->getScaledVector();
0104
0105 trigger_mbd_photon_3 = false;
0106 trigger_mbd_photon_4 = false;
0107 trigger_mbd_photon_5 = false;
0108
0109
0110 if (scaledown[25] != -1)
0111 {
0112 trigger_mbd_photon_3 = (trigger_mbd_photon_3 ||
0113 ((scaled_trigger >> 25 & 0x1U) == 0x1U));
0114 }
0115
0116 if (!trigger_mbd_photon_3 && (scaledown[36] != -1))
0117 {
0118 trigger_mbd_photon_3 = (trigger_mbd_photon_3 ||
0119 ((scaled_trigger >> 36 & 0x1U) == 0x1U));
0120 }
0121
0122 if (!trigger_mbd_photon_3 && (scaledown[29] == 0))
0123 {
0124 trigger_mbd_photon_3 = (trigger_mbd_photon_3 ||
0125 ((live_trigger >> 25 & 0x1U) == 0x1U) ||
0126 ((live_trigger >> 36 & 0x1U) == 0x1U));
0127 }
0128
0129
0130 if (scaledown[26] != -1)
0131 {
0132 trigger_mbd_photon_4 = (trigger_mbd_photon_4 ||
0133 ((scaled_trigger >> 26 & 0x1U) == 0x1U));
0134 }
0135
0136 if (!trigger_mbd_photon_4 && (scaledown[37] != -1))
0137 {
0138 trigger_mbd_photon_4 = (trigger_mbd_photon_4 ||
0139 ((scaled_trigger >> 37 & 0x1U) == 0x1U));
0140 }
0141
0142 if (!trigger_mbd_photon_4 && (scaledown[30] == 0))
0143 {
0144 trigger_mbd_photon_4 = (trigger_mbd_photon_4 ||
0145 ((live_trigger >> 26 & 0x1U) == 0x1U) ||
0146 ((live_trigger >> 37 & 0x1U) == 0x1U));
0147 }
0148
0149
0150 if (scaledown[27] != -1)
0151 {
0152 trigger_mbd_photon_5 = (trigger_mbd_photon_5 ||
0153 ((scaled_trigger >> 27 & 0x1U) == 0x1U));
0154 }
0155
0156 if (!trigger_mbd_photon_5 && (scaledown[38] != -1))
0157 {
0158 trigger_mbd_photon_5 = (trigger_mbd_photon_5 ||
0159 ((scaled_trigger >> 38 & 0x1U) == 0x1U));
0160 }
0161
0162 if (!trigger_mbd_photon_5 && (scaledown[31] == 0))
0163 {
0164 trigger_mbd_photon_5 = (trigger_mbd_photon_5 ||
0165 ((live_trigger >> 27 & 0x1U) == 0x1U) ||
0166 ((live_trigger >> 38 & 0x1U) == 0x1U));
0167 }
0168
0169 if (!(trigger_mbd_photon_3 || trigger_mbd_photon_4 || trigger_mbd_photon_5))
0170 return Fun4AllReturnCodes::ABORTEVENT;
0171
0172 return Fun4AllReturnCodes::EVENT_OK;
0173 }
0174
0175 int DstPhotonSelection::End(PHCompositeNode *)
0176 {
0177 return 0;
0178 }