Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:12:31

0001 #include "PidCandidatev1.h"
0002 
0003 #include <phool/phool.h>
0004 
0005 #include <cstdlib>
0006 
0007 using namespace std;
0008 
0009 ClassImp(PidCandidatev1)
0010 
0011 PidCandidatev1::PidCandidatev1():
0012 _candidateid(INT_MAX)
0013 {
0014 }
0015 
0016 PidCandidatev1::PidCandidatev1(PidCandidate const &tc)
0017 {
0018   Copy(tc);
0019 }
0020 
0021 void
0022 PidCandidatev1::Reset()
0023 {
0024   prop_map.clear();
0025 }
0026 
0027 void
0028 PidCandidatev1::print() const {
0029   std::cout << "New PidCandidate 0x" << hex << _candidateid << std::endl;
0030 
0031   for (prop_map_t::const_iterator i = prop_map.begin(); i!= prop_map.end(); ++i)
0032     {
0033       PROPERTY prop_id = static_cast<PROPERTY>(i->first);
0034       pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0035       cout << "\t" << prop_id << ":\t" << property_info.first << " = \t";
0036       switch(property_info.second)
0037         {
0038         case type_int:
0039           cout << get_property_int(prop_id);
0040           break;
0041         case type_uint:
0042           cout << get_property_uint(prop_id);
0043           break;
0044         case type_float:
0045           cout << get_property_float(prop_id);
0046           break;
0047         default:
0048           cout << " unknown type ";
0049         }
0050       cout <<endl;
0051     }
0052 }
0053 
0054 bool
0055 PidCandidatev1::has_property(const PROPERTY prop_id) const
0056 {
0057   prop_map_t::const_iterator i = prop_map.find(prop_id);
0058   return i!=prop_map.end();
0059 }
0060 
0061 float
0062 PidCandidatev1::get_property_float(const PROPERTY prop_id) const
0063 {
0064   if (!check_property(prop_id,type_float))
0065     {
0066       pair<const string,PROPERTY_TYPE> property_info =get_property_info(prop_id);
0067       cout << PHWHERE << " Property " << property_info.first << " with id "
0068            << prop_id << " is of type " << get_property_type(property_info.second)
0069            << " not " << get_property_type(type_float) << endl;
0070       exit(1);
0071     }
0072   prop_map_t::const_iterator i = prop_map.find(prop_id);
0073 
0074   if (i!=prop_map.end()) return u_property(i->second).fdata;
0075 
0076   return   NAN ;
0077 }
0078 
0079 int
0080 PidCandidatev1::get_property_int(const PROPERTY prop_id) const
0081 {
0082   if (!check_property(prop_id,type_int))
0083     {
0084       pair<const string,PROPERTY_TYPE> property_info =get_property_info(prop_id);
0085       cout << PHWHERE << " Property " << property_info.first << " with id "
0086            << prop_id << " is of type " << get_property_type(property_info.second)
0087            << " not " << get_property_type(type_int) << endl;
0088       exit(1);
0089     }
0090   prop_map_t::const_iterator i = prop_map.find(prop_id);
0091 
0092   if (i!=prop_map.end()) return u_property(i->second).idata;
0093 
0094   return INT_MIN;
0095 }
0096 
0097 unsigned int
0098 PidCandidatev1::get_property_uint(const PROPERTY prop_id) const
0099 {
0100   if (!check_property(prop_id,type_uint))
0101     {
0102       pair<const string,PROPERTY_TYPE> property_info =get_property_info(prop_id);
0103       cout << PHWHERE << " Property " << property_info.first << " with id "
0104            << prop_id << " is of type " << get_property_type(property_info.second)
0105            << " not " << get_property_type(type_uint) << endl;
0106       exit(1);
0107     }
0108   prop_map_t::const_iterator i = prop_map.find(prop_id);
0109 
0110   if (i!=prop_map.end()) return u_property(i->second).uidata;
0111 
0112   return UINT_MAX ;
0113 }
0114 
0115 void
0116 PidCandidatev1::set_property(const PROPERTY prop_id, const float value)
0117 {
0118   if (!check_property(prop_id,type_float))
0119     {
0120       pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
0121       cout << PHWHERE << " Property " << property_info.first << " with id "
0122            << prop_id << " is of type " << get_property_type(property_info.second)
0123            << " not " << get_property_type(type_float) << endl;
0124       exit(1);
0125     }
0126   prop_map[prop_id] = u_property(value).get_storage();
0127 }
0128 
0129 void
0130 PidCandidatev1::set_property(const PROPERTY prop_id, const int value)
0131 {
0132   if (!check_property(prop_id,type_int))
0133     {
0134       pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
0135       cout << PHWHERE << " Property " << property_info.first << " with id "
0136            << prop_id << " is of type " << get_property_type(property_info.second)
0137            << " not " << get_property_type(type_int) << endl;
0138       exit(1);
0139     }
0140   prop_map[prop_id] = u_property(value).get_storage();
0141 }
0142 
0143 void
0144 PidCandidatev1::set_property(const PROPERTY prop_id, const unsigned int value)
0145 {
0146   if (!check_property(prop_id,type_uint))
0147     {
0148       pair<const string,PROPERTY_TYPE> property_info = get_property_info(prop_id);
0149       cout << PHWHERE << " Property " << property_info.first << " with id "
0150            << prop_id << " is of type " << get_property_type(property_info.second)
0151            << " not " << get_property_type(type_uint) << endl;
0152       exit(1);
0153     }
0154   prop_map[prop_id] = u_property(value).get_storage();
0155 }
0156 
0157 unsigned int
0158 PidCandidatev1::get_property_nocheck(const PROPERTY prop_id) const
0159 {
0160   prop_map_t::const_iterator iter = prop_map.find(prop_id);
0161   if (iter != prop_map.end())
0162     {
0163       return iter->second;
0164     }
0165   return UINT_MAX;
0166 }
0167 
0168 void
0169 PidCandidatev1::identify(ostream& os) const
0170 {
0171   cout << "PidCandidatev1 with candidate_id: 0x" << hex << _candidateid << dec << endl;
0172   cout << "Class " << this->ClassName() << endl;
0173 
0174   for (prop_map_t::const_iterator i = prop_map.begin(); i!= prop_map.end(); ++i)
0175     {
0176       PROPERTY prop_id = static_cast<PROPERTY>(i->first);
0177       pair<const string, PROPERTY_TYPE> property_info = get_property_info(prop_id);
0178       cout << "\t" << prop_id << ":\t" << property_info.first << " = \t";
0179       switch(property_info.second)
0180         {
0181         case type_int:
0182           cout << get_property_int(prop_id);
0183           break;
0184         case type_uint:
0185           cout << get_property_uint(prop_id);
0186           break;
0187         case type_float:
0188           cout << get_property_float(prop_id);
0189           break;
0190         default:
0191           cout << " unknown type ";
0192         }
0193       cout <<endl;
0194     }
0195 }