File indexing completed on 2026-04-02 08:12:37
0001 #include "BcoLumiReco.h"
0002
0003 #include "BcoInfo.h"
0004 #include "BcoInfov1.h"
0005
0006 #include <ffaobjects/SyncDefs.h>
0007 #include <ffaobjects/SyncObject.h>
0008
0009 #include <fun4all/Fun4AllReturnCodes.h>
0010 #include <fun4all/SubsysReco.h> // for SubsysReco
0011
0012 #include <phool/PHCompositeNode.h>
0013 #include <phool/PHIODataNode.h>
0014 #include <phool/PHNode.h> // for PHNode
0015 #include <phool/PHNodeIterator.h> // for PHNodeIterator
0016 #include <phool/PHObject.h> // for PHObject
0017 #include <phool/getClass.h>
0018 #include <phool/phool.h> // for PHWHERE
0019
0020 #include <Event/Event.h>
0021 #include <Event/EventTypes.h>
0022 #include <Event/packet.h> // for Packet
0023 #
0024 #include <iostream>
0025
0026 BcoLumiReco::BcoLumiReco(const std::string &name)
0027 : SubsysReco(name)
0028 {
0029 return;
0030 }
0031
0032 BcoLumiReco::~BcoLumiReco()
0033 {
0034 delete m_synccopy;
0035 delete m_tmpsync;
0036 }
0037
0038 int BcoLumiReco::Init(PHCompositeNode *topNode)
0039 {
0040 int iret = CreateNodeTree(topNode);
0041 return iret;
0042 }
0043
0044 int BcoLumiReco::CreateNodeTree(PHCompositeNode *topNode)
0045 {
0046 PHNodeIterator iter(topNode);
0047 PHCompositeNode *dstNode;
0048 dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
0049 if (!dstNode)
0050 {
0051 std::cout << PHWHERE << " DST Node is missing doing nothing" << std::endl;
0052 return Fun4AllReturnCodes::ABORTRUN;
0053 }
0054 BcoInfo *bcoinfo = findNode::getClass<BcoInfo>(topNode, "BCOINFO");
0055 if (!bcoinfo)
0056 {
0057 bcoinfo = new BcoInfov1();
0058 PHIODataNode<PHObject> *newnode = new PHIODataNode<PHObject>(bcoinfo, "BCOINFO", "PHObject");
0059 dstNode->addNode(newnode);
0060 }
0061 return Fun4AllReturnCodes::EVENT_OK;
0062 }
0063
0064 int BcoLumiReco::process_event(PHCompositeNode *topNode)
0065 {
0066 static bool ifirst = true;
0067 SyncObject *syncobject = findNode::getClass<SyncObject>(topNode, syncdefs::SYNCNODENAME);
0068 Event *evt = findNode::getClass<Event>(topNode, "PRDF");
0069 if (evt)
0070 {
0071 if (Verbosity() > 1)
0072 {
0073 evt->identify();
0074 }
0075 if (evt->getEvtType() != DATAEVENT)
0076 {
0077 return Fun4AllReturnCodes::ABORTEVENT;
0078 }
0079 Packet *packet = evt->getPacket(14001);
0080 uint64_t gtm_bco = packet->lValue(0, "BCO");
0081 if (Verbosity() > 1)
0082 {
0083 std::cout << std::hex << "packet ival: 0x" << packet->lValue(0, "BCO")
0084 << " uint64_t: 0x" << gtm_bco << std::dec << std::endl;
0085 }
0086 push_bco(gtm_bco);
0087 delete packet;
0088 }
0089 if (syncobject)
0090 {
0091 push_evtno(syncobject->EventNumber());
0092 }
0093 if (ifirst)
0094 {
0095 ifirst = false;
0096 return Fun4AllReturnCodes::ABORTEVENT;
0097 }
0098 if (!m_synccopy)
0099 {
0100 m_synccopy = dynamic_cast<SyncObject *>(syncobject->CloneMe());
0101 m_tmpsync = dynamic_cast<SyncObject *>(m_synccopy->CloneMe());
0102 return Fun4AllReturnCodes::ABORTEVENT;
0103 }
0104 BcoInfo *bcoinfo = findNode::getClass<BcoInfo>(topNode, "BCOINFO");
0105
0106 if (Verbosity() > 0)
0107 {
0108 std::cout << "current event is: " << syncobject->EventNumber() << "\n";
0109 std::cout << "saving as event: " << m_synccopy->EventNumber() << "\n";
0110 }
0111
0112 *m_tmpsync = *syncobject;
0113 *syncobject = *m_synccopy;
0114 *m_synccopy = *m_tmpsync;
0115 if (Verbosity() > 0)
0116 {
0117 std::cout << std::hex;
0118 std::cout << "previous bco: " << get_previous_bco() << "\n";
0119 std::cout << "current bco: " << get_current_bco() << "\n";
0120 std::cout << "future bco: " << get_future_bco() << std::endl;
0121 std::cout << std::dec;
0122 }
0123 bcoinfo->set_previous_bco(get_previous_bco());
0124 bcoinfo->set_current_bco(get_current_bco());
0125 bcoinfo->set_future_bco(get_future_bco());
0126 bcoinfo->set_previous_evtno(get_previous_evtno());
0127 bcoinfo->set_current_evtno(get_current_evtno());
0128 bcoinfo->set_future_evtno(get_future_evtno());
0129 return Fun4AllReturnCodes::EVENT_OK;
0130 }
0131
0132 void BcoLumiReco::push_bco(uint64_t value)
0133 {
0134 m_bco[0] = m_bco[1];
0135 m_bco[1] = m_bco[2];
0136 m_bco[2] = value;
0137 }
0138
0139 void BcoLumiReco::push_evtno(int value)
0140 {
0141 m_evtno[0] = m_evtno[1];
0142 m_evtno[1] = m_evtno[2];
0143 m_evtno[2] = value;
0144 }