File indexing completed on 2026-07-16 08:13:57
0001 #include "StreamingBcoReco.h"
0002
0003 #include "BcoInfo.h"
0004 #include "StreamingBcoInfo.h"
0005 #include "StreamingBcoInfov1.h"
0006
0007
0008 #include <ffaobjects/SyncDefs.h>
0009 #include <ffaobjects/SyncObject.h>
0010
0011 #include <ffarawobjects/Gl1Packet.h>
0012
0013 #include <fun4all/Fun4AllReturnCodes.h>
0014 #include <fun4all/SubsysReco.h> // for SubsysReco
0015 #include <fun4all/Fun4AllHistoManager.h>
0016 #include <fun4all/Fun4AllServer.h>
0017
0018
0019 #include <phool/PHCompositeNode.h>
0020 #include <phool/PHNode.h> // for PHNode
0021 #include <phool/PHNodeIterator.h> // for PHNodeIterator
0022 #include <phool/getClass.h>
0023 #include <phool/phool.h> // for PHWHERE
0024
0025 #include <Event/Event.h>
0026 #include <Event/EventTypes.h>
0027 #include <Event/packet.h> // for Packet
0028
0029 #include <TH1.h>
0030
0031 #include <iostream>
0032
0033 StreamingBcoReco::StreamingBcoReco(const std::string &name)
0034 : SubsysReco(name)
0035 {
0036 hm = new Fun4AllHistoManager("bco_histos");
0037 Fun4AllServer *se = Fun4AllServer::instance();
0038 se->registerHistoManager(hm);
0039 return;
0040 }
0041
0042 int StreamingBcoReco::Init(PHCompositeNode *topNode)
0043 {
0044 int iret = CreateNodeTree(topNode);
0045 h_bco_diff = new TH1I("h_bco_diff", ";bco diff;", 3500, 0, 3500);
0046
0047
0048
0049
0050
0051
0052
0053 h_bco_tag = new TH1I("h_bco_tag", ";usable bco tag;", 2, -0.5, 1.5);
0054 hm->registerHisto(h_bco_diff);
0055 hm->registerHisto(h_bco_tag);
0056
0057 return iret;
0058 }
0059
0060 int StreamingBcoReco::CreateNodeTree(PHCompositeNode *topNode)
0061 {
0062 PHNodeIterator iter(topNode);
0063 PHCompositeNode *dstNode;
0064 dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0065 if (!dstNode)
0066 {
0067 std::cout << PHWHERE << " DST Node is missing doing nothing" << std::endl;
0068 return Fun4AllReturnCodes::ABORTRUN;
0069 }
0070 StreamingBcoInfo *streaming_bco_info = findNode::getClass<StreamingBcoInfo>(topNode, "STREAMINGBCOINFO");
0071 if (!streaming_bco_info)
0072 {
0073 streaming_bco_info = new StreamingBcoInfov1();
0074 PHIODataNode<PHObject> *bconode = new PHIODataNode<PHObject>(streaming_bco_info, "STREAMINGBCOINFO", "PHObject");
0075 dstNode->addNode(bconode);
0076 }
0077 return Fun4AllReturnCodes::EVENT_OK;
0078 }
0079
0080 int StreamingBcoReco::process_event(PHCompositeNode *topNode)
0081 {
0082 BcoInfo *bcoinfo = findNode::getClass<BcoInfo>(topNode, "BCOINFO");
0083 SyncObject *syncobject = findNode::getClass<SyncObject>(topNode, syncdefs::SYNCNODENAME);
0084 if (Verbosity() > 2)
0085 {
0086 if (!syncobject)
0087 {
0088 std::cout << PHWHERE << " SyncObject missing" << std::endl;
0089 return Fun4AllReturnCodes::ABORTEVENT;
0090 }
0091 std::cout << "Event No: " << syncobject->EventNumber() << std::endl;
0092 }
0093 if (bcoinfo)
0094 {
0095 if (Verbosity() > 2)
0096 {
0097 std::cout << "prev event: " << bcoinfo->get_previous_evtno()
0098 << " bco: " << bcoinfo->get_previous_bco() << std::dec << std::endl;
0099 std::cout << "curr event: " << bcoinfo->get_current_evtno()
0100 << " bco: " << bcoinfo->get_current_bco() << std::dec << std::endl;
0101 std::cout << "futu event: " << bcoinfo->get_future_evtno()
0102 << " bco: " << bcoinfo->get_future_bco() << std::dec << std::endl;
0103 }
0104 StreamingBcoInfo *streaming_bco_info = findNode::getClass<StreamingBcoInfo>(topNode, "STREAMINGBCOINFO");
0105 if (!streaming_bco_info)
0106 {
0107 std::cout << PHWHERE << " STREAMINGBCOINFO node missing" << std::endl;
0108 return Fun4AllReturnCodes::ABORTEVENT;
0109 }
0110 m_bco = bcoinfo->get_current_bco();
0111
0112
0113 uint64_t bco_prev = bcoinfo->get_previous_bco();
0114 uint64_t bco_futu = bcoinfo->get_future_bco();
0115 uint64_t bco_diff_prev = m_bco - bco_prev;
0116 uint64_t bco_diff_futu = bco_futu - m_bco;
0117
0118
0119 if (bco_diff_prev < m_default_positive_window_length)
0120 {
0121 m_usable_bco_tag = true;
0122 }
0123 else
0124 {
0125 m_usable_bco_tag = false;
0126 }
0127 if (bco_diff_futu < m_default_positive_window_length)
0128 {
0129
0130 m_bco_streaming_window = std::make_pair(get_bco() - m_default_negative_window_length, bco_futu - m_default_negative_window_length + 1);
0131 }
0132 else
0133 {
0134 m_bco_streaming_window = std::make_pair(get_bco() - m_default_negative_window_length, get_bco() + m_default_positive_window_length);
0135 }
0136 if (Verbosity() > 2)
0137 {
0138 std::cout << "bco_diff_prev : " << bco_diff_prev << std::endl;
0139 std::cout << "bco_diff_futu : " << bco_diff_futu << std::endl;
0140 }
0141 h_bco_diff->Fill(bco_diff_prev);
0142 h_bco_tag->Fill(m_usable_bco_tag);
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153 streaming_bco_info->set_bco(get_bco());
0154 streaming_bco_info->set_usable_bco_tag(get_usable_bco_tag());
0155 streaming_bco_info->set_bco_streaming_window(get_bco_streaming_window());
0156 if (syncobject)
0157 {
0158 streaming_bco_info->set_evtno(syncobject->EventNumber());
0159 }
0160 }
0161 return Fun4AllReturnCodes::EVENT_OK;
0162 }