00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include "RawData/RawDeadChipBlock.h"
00013
00014 UInt_t RawDeadChipBlock::fgDebugFlags = 0;
00015 UInt_t RawDeadChipBlock::fgStdVaChannel = 0;
00016
00017 #include "MessageService/MsgService.h"
00018
00019
00020 #include "RawData/RawBlockRegistry.h"
00021 REGISTERRAWBLOCK(RawDeadChipBlock,kMdBlockVaDeadChips,0);
00022
00023 ClassImp(RawDeadChipBlock)
00024
00025 enum EDeadChipBlkPos {
00026 indx_size = 0,
00027 indx_checksum = 1,
00028 indx_blockid = 2,
00029 zzzz_last = 3
00030 };
00031
00032
00033 RawDeadChipBlock::RawDeadChipBlock() : RawDataBlock(), fUnpacked(false)
00034 {
00035
00036 }
00037
00038
00039 RawDeadChipBlock::RawDeadChipBlock(const Int_t *block)
00040 : RawDataBlock(block), fUnpacked(false)
00041 {
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 }
00055
00056
00057 RawDeadChipBlock::RawDeadChipBlock(const VldContext& vldc,
00058 const RawChannelIdSet& inset)
00059 : RawDataBlock(), fUnpacked(false)
00060 {
00061
00062
00063
00064 Int_t ncrates = 0;
00065 Int_t *crate_count = 0;
00066 if (inset.size()>0) {
00067 RawChannelId rcid_last = *inset.rbegin();
00068 ncrates = rcid_last.GetCrate() + 1;
00069
00070 crate_count = new Int_t [ncrates];
00071 for (int i=0; i<ncrates; i++) crate_count[i] = 0;
00072 RawChannelIdSetConstIter iter = inset.begin();
00073 while (iter != inset.end()) {
00074 RawChannelId rcid = *iter;
00075 crate_count[rcid.GetCrate()] += 1;
00076 iter++;
00077 }
00078 }
00079
00080 fSize = 3 + ncrates + inset.size();
00081 if (fRawBlock) delete [] fRawBlock;
00082 fRawBlock = new Int_t [fSize];
00083
00084 fRawBlock[0] = fSize;
00085
00086
00087 RawBlockRegistry& rbr = RawBlockRegistry::Instance();
00088 RawBlockProxy* rbp = rbr.LookUp("RawDeadChipBlock");
00089
00090 Bool_t isDCS = rbp->IsDCS();
00091 Int_t majorId = rbp->GetMajorId();
00092 Int_t minorId = 0;
00093 RawBlockId rbid(majorId,minorId,isDCS,
00094 vldc.GetDetector(),vldc.GetSimFlag());
00095 fRawBlock[2] = rbid.GetEncoded();
00096
00097 Int_t *p = fRawBlock + 3;
00098 Int_t this_crate = -1;
00099 RawChannelIdSetConstIter iter = inset.begin();
00100 while (iter != inset.end()) {
00101 RawChannelId rcid = *iter;
00102 while (this_crate != rcid.GetCrate()) {
00103 this_crate++;
00104 *p = crate_count[this_crate];
00105 p++;
00106 }
00107 *p = rcid.GetChAdd();
00108 p++;
00109 iter++;
00110 }
00111
00112
00113
00114 rdxsum_fill((long*)fRawBlock,0);
00115
00116
00117 delete crate_count;
00118 }
00119
00120
00121 RawDeadChipBlock::~RawDeadChipBlock()
00122 {
00123
00124 }
00125
00126
00127 RawDeadChipBlock& RawDeadChipBlock::operator=(const RawDeadChipBlock& rhs)
00128 {
00129
00130 if (this != &rhs) {
00131 RawDataBlock::operator=(rhs);
00132
00133 fUnpacked = false;
00134 fDeadChannels.clear();
00135 }
00136 return *this;
00137 }
00138
00139
00140 std::ostream& RawDeadChipBlock::FormatToOStream(ostream& os,
00141 Option_t *option) const
00142 {
00143 RawDataBlock::FormatToOStream(os,option);
00144 if (option[0] == 'X') return os;
00145
00146
00147
00148 FillDeadChannels();
00149 RawChannelIdSetConstIter iter = fDeadChannels.begin();
00150 while (iter != fDeadChannels.end()) {
00151 RawChannelId rcid = *iter;
00152 os << " " << rcid.AsString("e") << " was dead " << endl;
00153 iter++;
00154 }
00155 return os;
00156 }
00157
00158
00159 void RawDeadChipBlock::FillDeadChannels() const
00160 {
00161
00162
00163 if (fUnpacked) return;
00164
00165 Detector::Detector_t det = GetBlockId().GetDetector();
00166
00167 ElecType::Elec_t elec = ElecType::kVA;
00168
00169 Int_t crate = -1;
00170 Int_t* ptr = fRawBlock+zzzz_last;
00171 while (ptr < fRawBlock+fSize) {
00172
00173 crate++;
00174 int ndead = *ptr; ptr++;
00175 for (int i=0; i<ndead; i++) {
00176 Int_t chad = *ptr; ptr++;
00177 RawChannelId rcid0(det,elec,crate,chad);
00178 rcid0.ClearModeBits();
00179
00180
00181 rcid0.SetVaChannel(fgStdVaChannel);
00182 fDeadChannels.insert(rcid0);
00183 }
00184 }
00185 }
00186
00187
00188 Bool_t RawDeadChipBlock::ChipWasDead(const RawChannelId& rcid) const
00189 {
00190
00191 FillDeadChannels();
00192
00193
00194 RawChannelId rcid0 = rcid;
00195 rcid0.ClearModeBits();
00196
00197
00198 rcid0.SetVaChannel(fgStdVaChannel);
00199
00200 return fDeadChannels.end() != fDeadChannels.find(rcid0);
00201 }
00202
00203