00001
00002
00003
00004
00005
00006
00007
00008
00009
00011 #include <cstring>
00012
00013 #include "RawData/RawPedestalTableBlock.h"
00014 #include "RawData/RawCrateStatus.h"
00015
00016 UInt_t RawPedestalTableBlock::fgDebugFlags = 0;
00017
00018 #include "MessageService/MsgStream.h"
00019 #include "MessageService/MsgFormat.h"
00020
00021 #include "MessageService/MsgService.h"
00022 CVSID("$Id: RawPedestalTableBlock.cxx,v 1.17 2009/02/28 21:46:16 gmieg Exp $");
00023
00024 #include "RawData/RawBlockRegistry.h"
00025 REGISTERRAWBLOCK(RawPedestalTableBlock,kMdBlockPedestalTable,0);
00026
00027 ClassImp(RawPedestalTableBlock)
00028
00029 enum EPedestalTableBlkPos {
00030 indx_size = 0,
00031 indx_checksum = 1,
00032 indx_blockid = 2,
00033 indx_run = 3,
00034 indx_subrun = 4,
00035 indx_runtype = indx_subrun,
00036 indx_loadsec = 5,
00037 indx_loadnsec = 6,
00038 indx_crateid = 7,
00039 indx_nvalues = 8,
00040 zzzz_last = 9
00041 };
00042
00043
00044 RawPedestalTableBlock::RawPedestalTableBlock()
00045 : fRawCrateStatus(0)
00046 {
00047
00048 }
00049
00050
00051 RawPedestalTableBlock::RawPedestalTableBlock(const Int_t *block)
00052 : RawDataBlock(block), fRawCrateStatus(0)
00053 {
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 }
00069
00070
00071 RawPedestalTableBlock::~RawPedestalTableBlock()
00072 {
00073
00074 if (fRawCrateStatus) delete fRawCrateStatus;
00075 fRawCrateStatus = 0;
00076 }
00077
00078
00079 RawPedestalTableBlock& RawPedestalTableBlock::operator=(const RawPedestalTableBlock& rhs)
00080 {
00081
00082 if (this != &rhs) {
00083 RawDataBlock::operator=(rhs);
00084 if (fRawCrateStatus) { delete fRawCrateStatus; fRawCrateStatus = 0; }
00085 }
00086 return *this;
00087 }
00088
00089
00090 std::ostream& RawPedestalTableBlock::FormatToOStream(std::ostream& os,
00091 Option_t *option) const
00092 {
00093 RawDataBlock::FormatToOStream(os,option);
00094 if (option[0] == 'X') return os;
00095
00096
00097
00098 os << " Loaded " << GetLoadTime().AsString("c") << endl;
00099 os << " Run " << GetRun()
00100 << " SubRun " << GetSubRun()
00101 << " RunType " << GetRunType() << endl;
00102 os << " " << *GetCrateStatus() << endl;
00103 os << " " << GetNumberOfValues() << " pedestal values" << endl;
00104
00105 if (strchr(option,'q') != 0) return os;
00106
00107 Int_t indx, value;
00108
00109 RawChannelId rcid;
00110
00111 switch (GetElecType()) {
00112 case (ElecType::kVA): {
00113 for (indx=0; indx<GetNumberOfValues(); indx++) {
00114 GetPedValue(indx,rcid,value);
00115
00116 os << " [" << setw(4) << indx << "] "
00117 << rcid.AsString("e") << " := " << setw(5) << value
00118
00119 << endl;
00120 }
00121 break;
00122 }
00123 case (ElecType::kQIE):
00124
00125 default:
00126 MSG("RawData",Msg::kWarning)
00127 << "FormatToOStream not implemented for electronics type "
00128 << ElecType::AsString(GetElecType()) << endl;
00129 }
00130
00131 return os;
00132 }
00133
00134
00135 Int_t RawPedestalTableBlock::GetRun() const
00136 {
00137
00138 if (fSize > indx_run) return fRawBlock[indx_run];
00139 return -1;
00140 }
00141
00142
00143 Short_t RawPedestalTableBlock::GetSubRun() const
00144 {
00145
00146 if (fSize > indx_subrun) return (fRawBlock[indx_subrun]>>16)&0xffff;
00147 return -1;
00148 }
00149
00150
00151 Short_t RawPedestalTableBlock::GetRunType() const
00152 {
00153
00154 if (fSize > indx_runtype) return fRawBlock[indx_runtype]&0xffff;
00155 return -1;
00156 }
00157
00158
00159 VldTimeStamp RawPedestalTableBlock::GetLoadTime() const
00160 {
00161
00162 if (fSize >= zzzz_last)
00163 return VldTimeStamp(fRawBlock[indx_loadsec],fRawBlock[indx_loadnsec]);
00164
00165 return VldTimeStamp((time_t)0,(Int_t)0);
00166 }
00167
00168
00169 const RawCrateStatus* RawPedestalTableBlock::GetCrateStatus() const
00170 {
00171
00172 if (fRawCrateStatus) return fRawCrateStatus;
00173
00174 if (fSize > indx_crateid) {
00175 const Int_t* crateid_ptr = fRawBlock+indx_crateid;
00176 fRawCrateStatus = new RawCrateStatus(GetBlockId(),crateid_ptr);
00177
00178 return fRawCrateStatus;
00179 }
00180 return 0;
00181 }
00182
00183
00184 Int_t RawPedestalTableBlock::GetNumberOfValues() const
00185 {
00186
00187 if (fSize > indx_nvalues) return fRawBlock[indx_nvalues];
00188 return -1;
00189 }
00190
00191
00192 void RawPedestalTableBlock::GetPedValue(Int_t indx, RawChannelId& rcid,
00193 Int_t& value) const
00194 {
00195 if (indx >= GetNumberOfValues()) {
00196 rcid = RawChannelId();
00197 value = -1;
00198 return;
00199 }
00200
00201 RawBlockId rbid = GetBlockId();
00202
00203 switch (GetElecType()) {
00204 case (ElecType::kVA): {
00205
00206
00207 Int_t tmp = indx;
00208 Int_t vachan = tmp%22; tmp /= 22;
00209 Int_t vachip = tmp%3; tmp /= 3;
00210 Int_t xyzzy = tmp%12; tmp /= 12;
00211 Int_t adcsel = xyzzy&1;
00212 Int_t vmm = xyzzy>>1;
00213 Int_t varc = tmp%3; tmp /= 3;
00214
00215 rcid = RawChannelId(rbid.GetDetector(),
00216 fRawCrateStatus->GetElecType(),
00217 fRawCrateStatus->GetCrate(),
00218 varc,vmm,adcsel,vachip,vachan);
00219 rcid.SetModeBits(fRawCrateStatus->GetCommonMode(),
00220 fRawCrateStatus->GetSparsMode(),
00221 fRawCrateStatus->GetPedMode());
00222
00223 Int_t offset = indx/2;
00224 if (indx&1) {
00225
00226 value = fRawBlock[zzzz_last+offset] & 0xffff;
00227 }
00228 else {
00229
00230 value = (fRawBlock[zzzz_last+offset] >> 16) & 0xffff;
00231 }
00232 break;
00233 }
00234 case (ElecType::kQIE):
00235
00236 default:
00237 MSG("RawData",Msg::kWarning)
00238 << "Print not implemented for electronics type "
00239 << ElecType::AsString(GetElecType()) << endl;
00240 }
00241 }
00242
00243
00244 Int_t RawPedestalTableBlock::GetPedValue(const RawChannelId& rcid) const
00245 {
00246 Int_t indx = -1;
00247
00248 RawBlockId rbid = GetBlockId();
00249
00250 const Int_t kBadValue = -1;
00251
00252 if (GetElecType() != rcid.GetElecType()) {
00253 MSG("RawData",Msg::kWarning)
00254 << "RawChannelId " << rcid
00255 << " does not match ElecType of crate "
00256 << ElecType::AsString(fRawCrateStatus->GetElecType())
00257 << endl;
00258 return kBadValue;
00259 }
00260
00261 if (fRawCrateStatus->GetCrate() != rcid.GetCrate()) {
00262 MSG("RawData",Msg::kWarning)
00263 << "RawChannelId " << rcid
00264 << " does not match of crate # of table "
00265 << fRawCrateStatus->GetCrate()
00266 << endl;
00267 return kBadValue;
00268 }
00269
00270 switch (GetElecType()) {
00271 case (ElecType::kVA): {
00272
00273
00274 Int_t vachan = rcid.GetVaChannel();
00275 Int_t vachip = rcid.GetVaChip();
00276 Int_t adcsel = rcid.GetVaAdcSel();
00277 Int_t vmm = rcid.GetVmm();
00278 Int_t varc = rcid.GetVarcId();
00279 Int_t xyzzy = (vmm<<1) + adcsel;
00280 indx = (((varc)*12 + xyzzy)*3 + vachip)*22 + vachan;
00281
00282 if (indx<0 || indx> GetNumberOfValues()) {
00283 MSG("RawData",Msg::kWarning)
00284 << "calulated index out of range "
00285 << indx << " (max " << GetNumberOfValues() << ")" << endl;
00286 return kBadValue;
00287 }
00288
00289 Int_t offset = indx/2;
00290 if (indx&1) {
00291
00292 return fRawBlock[zzzz_last+offset] & 0xffff;
00293 }
00294 else {
00295
00296 return (fRawBlock[zzzz_last+offset] >> 16) & 0xffff;
00297 }
00298
00299 return kBadValue;
00300 break;
00301 }
00302 case (ElecType::kQIE):
00303
00304 default:
00305 MSG("RawData",Msg::kWarning)
00306 << "Print not implemented for electronics type "
00307 << ElecType::AsString(GetElecType()) << endl;
00308 return kBadValue;
00309 break;
00310 }
00311
00312 return kBadValue;
00313 }
00314
00315