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