File indexing completed on 2025-08-06 08:17:13
0001 #include "TpcBcoDump.h"
0002
0003 #include <fun4all/Fun4AllReturnCodes.h>
0004 #include <fun4all/SubsysReco.h> // for SubsysReco
0005
0006 #include <fun4all/Fun4AllHistoManager.h>
0007
0008 #include <phool/PHCompositeNode.h>
0009 #include <phool/PHDataNode.h>
0010 #include <phool/PHNode.h> // for PHNode
0011 #include <phool/PHNodeIterator.h> // for PHNodeIterator
0012 #include <phool/getClass.h>
0013
0014 #include <Event/Event.h>
0015 #include <Event/packet.h>
0016
0017 #include <TFile.h>
0018 #include <TSystem.h>
0019 #include <TTree.h>
0020
0021 #include <iostream> // for operator<<, endl, basic_ost...
0022 #include <set>
0023 #include <utility> // for pair
0024 #include <vector> // for vector
0025
0026
0027 TpcBcoDump::TpcBcoDump(const std::string &name)
0028 : SubsysReco(name)
0029 {
0030 }
0031
0032
0033 int TpcBcoDump::InitRun(PHCompositeNode * )
0034 {
0035 if (outfilename.empty())
0036 {
0037 std::cout << "no output filename given" << std::endl;
0038 gSystem->Exit(1);
0039 }
0040
0041 outfile = new TFile(outfilename.c_str(), "RECREATE");
0042 ttree = new TTree("bco", "bco");
0043 ttree->Branch("id", &m_id);
0044 ttree->Branch("evt", &m_evt);
0045 ttree->Branch("bco", &m_bco);
0046 ttree->Branch("bcodiff", &m_bcodiff);
0047 return Fun4AllReturnCodes::EVENT_OK;
0048 }
0049
0050
0051 int TpcBcoDump::process_event(PHCompositeNode *topNode)
0052 {
0053 Event *evt = findNode::getClass<Event>(topNode, "PRDF");
0054 if (!evt)
0055 {
0056 std::cout << "No Event found" << std::endl;
0057 exit(1);
0058 }
0059
0060 int EventSequence = evt->getEvtSequence();
0061 std::vector<Packet *> pktvec = evt->getPacketVector();
0062 std::map<int, std::set<uint64_t>> bcoset;
0063 for (auto *packet : pktvec)
0064 {
0065 int packetid = packet->getIdentifier();
0066 lastbco.insert(std::make_pair(packetid, 0));
0067 int numBCOs = packet->lValue(0, "N_TAGGER");
0068 for (int j = 0; j < numBCOs; j++)
0069 {
0070 const auto is_lvl1 = static_cast<uint8_t>(packet->lValue(j, "IS_LEVEL1_TRIGGER"));
0071 if (is_lvl1)
0072 {
0073 uint64_t bco = packet->lValue(j, "BCO");
0074 bcoset[packetid].insert(bco);
0075 }
0076 }
0077 delete packet;
0078 }
0079
0080 for (auto &mapiter : bcoset)
0081 {
0082 if (!mapiter.second.empty())
0083 {
0084 for (const auto &bco : mapiter.second)
0085 {
0086 uint64_t prevbco = lastbco[mapiter.first];
0087 if (prevbco > 0 && prevbco != bco)
0088 {
0089 int64_t diffbco = bco - prevbco;
0090
0091 m_id = mapiter.first;
0092 m_evt = EventSequence;
0093 m_bco = bco;
0094 m_bcodiff = diffbco;
0095
0096 ttree->Fill();
0097 }
0098 lastbco[mapiter.first] = bco;
0099 }
0100 }
0101 }
0102 return Fun4AllReturnCodes::EVENT_OK;
0103 }
0104
0105
0106 int TpcBcoDump::End(PHCompositeNode * )
0107 {
0108 outfile->cd();
0109 ttree->Write();
0110 outfile->Close();
0111 delete outfile;
0112 return Fun4AllReturnCodes::EVENT_OK;
0113 }