File indexing completed on 2025-08-06 08:22:00
0001 #include "GenericUnpackPRDF.h"
0002
0003 #include "PROTOTYPE2_FEM.h"
0004 #include "RawTower_Prototype2.h"
0005
0006 #include <calobase/RawTower.h> // for RawTower
0007 #include <calobase/RawTowerContainer.h>
0008 #include <calobase/RawTowerDefs.h> // for NONE
0009
0010 #include <fun4all/Fun4AllBase.h> // for Fun4AllBase::VERBOSITY_SOME
0011 #include <fun4all/Fun4AllReturnCodes.h>
0012 #include <fun4all/SubsysReco.h> // for SubsysReco
0013
0014 #include <phool/PHCompositeNode.h>
0015 #include <phool/PHIODataNode.h> // for PHIODataNode
0016 #include <phool/PHNodeIterator.h> // for PHNodeIterator
0017 #include <phool/PHObject.h> // for PHObject
0018 #include <phool/getClass.h>
0019
0020 #include <Event/Event.h>
0021 #include <Event/packet.h>
0022
0023 #include <cassert>
0024 #include <cmath> // for NAN
0025 #include <cstdlib> // for exit
0026 #include <iostream>
0027 #include <string>
0028
0029 using namespace std;
0030
0031
0032 GenericUnpackPRDF::GenericUnpackPRDF(const string &detector)
0033 : SubsysReco("GenericUnpackPRDF_" + detector)
0034 ,
0035 _detector(detector)
0036 , _towers(nullptr)
0037 {
0038 }
0039
0040
0041 int GenericUnpackPRDF::InitRun(PHCompositeNode *topNode)
0042 {
0043 CreateNodeTree(topNode);
0044 return Fun4AllReturnCodes::EVENT_OK;
0045 }
0046
0047
0048 int GenericUnpackPRDF::process_event(PHCompositeNode *topNode)
0049 {
0050 Event *_event = findNode::getClass<Event>(topNode, "PRDF");
0051 if (!_event)
0052 {
0053 if (Verbosity() >= VERBOSITY_SOME)
0054 cout << "GenericUnpackPRDF::Process_Event - Event not found" << endl;
0055 return Fun4AllReturnCodes::DISCARDEVENT;
0056 }
0057
0058 if (Verbosity() >= VERBOSITY_SOME)
0059 _event->identify();
0060
0061 map<int, Packet *> packet_list;
0062
0063 for (hbd_channel_map::const_iterator it = _hbd_channel_map.begin();
0064 it != _hbd_channel_map.end(); ++it)
0065 {
0066 const int packet_id = it->first.first;
0067 const int channel = it->first.second;
0068 const int tower_id = it->second;
0069
0070 if (packet_list.find(packet_id) == packet_list.end())
0071 {
0072 packet_list[packet_id] = _event->getPacket(packet_id);
0073 }
0074
0075 Packet *packet = packet_list[packet_id];
0076
0077 if (!packet)
0078 {
0079
0080 cout << "GenericUnpackPRDF::process_event - failed to locate packet "
0081 << packet_id << endl;
0082 continue;
0083 }
0084 assert(packet);
0085
0086 packet->setInternalParameter(PROTOTYPE2_FEM::NSAMPLES);
0087
0088 RawTower_Prototype2 *tower =
0089 dynamic_cast<RawTower_Prototype2 *>(_towers->getTower(tower_id));
0090 if (!tower)
0091 {
0092 tower = new RawTower_Prototype2();
0093 tower->set_energy(NAN);
0094 _towers->AddTower(tower_id, tower);
0095 }
0096 tower->set_HBD_channel_number(channel);
0097 for (int isamp = 0; isamp < PROTOTYPE2_FEM::NSAMPLES; isamp++)
0098 {
0099 tower->set_signal_samples(isamp, packet->iValue(channel, isamp));
0100 }
0101 }
0102
0103 for (map<int, Packet *>::iterator it = packet_list.begin();
0104 it != packet_list.end(); ++it)
0105 {
0106 if (it->second)
0107 delete it->second;
0108 }
0109
0110 return Fun4AllReturnCodes::EVENT_OK;
0111 }
0112
0113
0114 void GenericUnpackPRDF::CreateNodeTree(PHCompositeNode *topNode)
0115 {
0116 PHNodeIterator nodeItr(topNode);
0117
0118 PHCompositeNode *dst_node = static_cast<PHCompositeNode *>(
0119 nodeItr.findFirst("PHCompositeNode", "DST"));
0120 if (!dst_node)
0121 {
0122 cout << "PHComposite node created: DST" << endl;
0123 dst_node = new PHCompositeNode("DST");
0124 topNode->addNode(dst_node);
0125 }
0126
0127
0128 PHCompositeNode *data_node = static_cast<PHCompositeNode *>(
0129 nodeItr.findFirst("PHCompositeNode", "RAW_DATA"));
0130 if (!data_node)
0131 {
0132 if (Verbosity())
0133 cout << "PHComposite node created: RAW_DATA" << endl;
0134 data_node = new PHCompositeNode("RAW_DATA");
0135 dst_node->addNode(data_node);
0136 }
0137
0138
0139 _towers = new RawTowerContainer(RawTowerDefs::NONE);
0140 PHIODataNode<PHObject> *towerNode =
0141 new PHIODataNode<PHObject>(_towers, "TOWER_RAW_" + _detector, "PHObject");
0142 data_node->addNode(towerNode);
0143 }
0144
0145 void GenericUnpackPRDF::add_channel(const int packet_id,
0146 const int channel,
0147 const int tower_id
0148 )
0149 {
0150 hbd_channel_typ hbd_channel(packet_id, channel);
0151
0152 if (_hbd_channel_map.find(hbd_channel) != _hbd_channel_map.end())
0153 {
0154 cout << "GenericUnpackPRDF::add_channel - packet " << packet_id
0155 << ", channel " << channel << " is already registered as tower "
0156 << _hbd_channel_map.find(hbd_channel)->second << endl;
0157 exit(12);
0158 }
0159 _hbd_channel_map[hbd_channel] = tower_id;
0160 }