00001 #include "SetupRecord.h"
00002
00003
00004 #include <stdexcept>
00005 #include <iostream>
00006
00007
00008
00009
00010 #include "TSetupData.h"
00011
00012
00014 class unknown_channel_error : public std::out_of_range {
00015 public:
00016 unknown_channel_error()
00017 : std::out_of_range("Unknown Channel")
00018 {}
00019 };
00020
00021
00022
00023 SetupRecord::SetupRecord(const TSetupData* setup_data)
00024 : fInfoLookup(0)
00025 {
00026 InitChannels(setup_data);
00027 InitMetaData(setup_data);
00028
00029
00030
00031
00032
00033 }
00034
00035
00036
00037 SetupRecord::~SetupRecord()
00038 {}
00039
00040
00041
00042 int SetupRecord::InitChannels(const TSetupData* setup_data)
00043 {
00044 typedef const std::map<std::string, std::string> StrStrMap;
00045 typedef StrStrMap::const_iterator StrStrIt;
00046
00047
00048 UInt_t lut_size = fInfoLookup.size();
00049 StrStrMap& b2d = setup_data->fBankToDetectorMap;
00050 fInfoLookup.resize(b2d.size());
00051 for (StrStrIt it = b2d.begin() ; it != b2d.end(); ++it){
00052 const std::string& name = it->first;
00053 if (name.size() > 4) throw std::out_of_range("Bank name too long!");
00054 ChannelID cid(it->second);
00055 fNameOrderLookup.insert(std::make_pair(name,lut_size));
00056 fIDOrderLookup.insert(std::make_pair(cid,lut_size));
00057
00058 BankInfo_t& info = fInfoLookup.at(lut_size);
00059 name.copy(info.Name, 4); info.Name[4] = '\0';
00060 info.ID = cid;
00061 ++lut_size;
00062 }
00063 return lut_size;
00064 }
00065
00066
00067 int SetupRecord::InitMetaData(const TSetupData* setup_data)
00068 {
00069 typedef const std::map<std::string, int> StrIntMap;
00070 typedef StrIntMap::const_iterator StrIntIt;
00071
00072 UInt_t lut_size = fInfoLookup.size();
00073 const StrIntMap& bit_map = setup_data->fBankToBitMap;
00074 if (bit_map.size() > lut_size){
00075 BankInfo_t blank;
00076 blank.ID = ChannelID(IDs::kErrorDetector,
00077 IDs::kErrorSlowFast);
00078 fInfoLookup.resize(bit_map.size(), blank);
00079 }
00080
00081
00082
00083 for (StrIntIt it = bit_map.begin(); it != bit_map.end(); ++it){
00084 std::string name = it->first;
00085 if (fNameOrderLookup.count(name) == 0){
00086 fNameOrderLookup.insert(make_pair(name, lut_size));
00087 ++lut_size;
00088 }
00089
00090 BankInfo_t& info = BankInfo(name);
00091 name.copy(info.Name, 4); info.Name[4] = '\0';
00092 info.TickLength = setup_data->GetClockTick(name);
00093 info.LinearWidthLSB = setup_data->GetADCSlopeCalib(name);
00094 info.LinearZeroPoint = setup_data->GetADCOffsetCalib(name);
00095 info.TimeFromMuSc = setup_data->GetTimeShift(name);
00096 info.ADCDepth = setup_data->GetNBits(name);
00097 info.Pedestal = setup_data->GetPedestal(name);
00098 info.Polarity = setup_data->GetTriggerPolarity(name);
00099 info.Enabled = setup_data->GetEnableBit(name);
00100 }
00101 return lut_size;
00102 }
00103
00104
00105
00106 const SetupRecord::BankInfo_t&
00107 SetupRecord::BankInfo(const std::string& bankname) const
00108 {
00109 std::map<std::string, UInt_t>::const_iterator it;
00110 it = fNameOrderLookup.find(bankname);
00111 if (it == fNameOrderLookup.end() ) throw unknown_channel_error();
00112 return fInfoLookup.at(it->second);
00113 }
00114
00115
00116
00117 const SetupRecord::BankInfo_t&
00118 SetupRecord::BankInfo(const ChannelID& cid) const
00119 {
00120 std::map<ChannelID, unsigned int>::const_iterator it;
00121 it = fIDOrderLookup.find(cid);
00122 if (it == fIDOrderLookup.end()) throw unknown_channel_error();
00123 return fInfoLookup.at(it->second);
00124 }
00125
00126
00127
00128 SetupRecord::BankInfo_t&
00129 SetupRecord::BankInfo(const std::string& bankname)
00130 {
00131 const SetupRecord* c_this = this;
00132 return const_cast<BankInfo_t&>(c_this->BankInfo(bankname));
00133 }
00134
00135
00136
00137 SetupRecord::BankInfo_t&
00138 SetupRecord::BankInfo(const ChannelID& cid)
00139 {
00140 const SetupRecord* c_this = this;
00141 return const_cast<BankInfo_t&>(c_this->BankInfo(cid));
00142 }
00143
00144
00145
00146 void SetupRecord::BankInfo_t::Print() const
00147 {
00148 std::cout << ID << " at bank " << Name
00149 << (Enabled>0 ? " (enabled)" : " (disabled)")
00150 << "\n" << "- - - - - - - - - - - - - - - - - - - - -"
00151 << "\n" << " Tick: " << TickLength
00152 << "\n" << " Time offset: " << TimeFromMuSc
00153 << "\n" << " ADC depth: " << ADCDepth
00154 << " [Max: " << (1<<ADCDepth) << "]"
00155 << "\n" << " Pedestal: " << Pedestal
00156 << "\n" << " Polarity: " << (Polarity>0 ? "+" : "-")
00157
00158
00159 << std::endl;
00160 }