00001
00002
00003
00004
00005
00006
00007
00008
00009
00011 #include <cstring>
00012
00013 #include "RawData/RawDcsMagnetMonitorBlock.h"
00014
00015 UInt_t RawDcsMagnetMonitorBlock::fgDebugFlags = 0;
00016
00017 #include "MessageService/MsgService.h"
00018 CVSID("$Id: RawDcsMagnetMonitorBlock.cxx,v 1.16 2009/02/28 21:46:16 gmieg Exp $");
00019
00020 #include "MessageService/MsgFormat.h"
00021 #include "RawData/RawBlockRegistry.h"
00022
00023 REGISTERRAWBLOCK(RawDcsMagnetMonitorBlock,kMdBlockDcsMagnetMonitor,kMdBlockSourceDcs);
00024
00025 ClassImp(RawDcsMagnetMonitorBlock)
00026
00027 enum EDcsMagnetMonitorBlkPos {
00028 indx_size = 0,
00029 indx_checksum = 1,
00030 indx_blockid = 2,
00031 zzzz_last = 3
00032 };
00033
00034
00035 RawDcsMagnetMonitorBlock::RawDcsMagnetMonitorBlock()
00036 : MagnetArray(0)
00037 {
00038
00039 }
00040
00041
00042 RawDcsMagnetMonitorBlock::RawDcsMagnetMonitorBlock(const Int_t *block)
00043 : RawDataBlock(block), MagnetArray(0)
00044 {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 }
00071
00072
00073 RawDcsMagnetMonitorBlock::~RawDcsMagnetMonitorBlock()
00074 {
00075
00076 }
00077
00078
00079 std::ostream& RawDcsMagnetMonitorBlock::FormatToOStream(ostream& os,
00080 Option_t *option) const
00081 {
00082 RawDataBlock::FormatToOStream(os,option);
00083 if (option[0] == 'X') return os;
00084
00085 MsgFormat ffmt("%9.3f");
00086 Int_t iArray[30];
00087 Float_t fArray[30];
00088 Int_t numEntries=GetNumEntries();
00089 os << " Number of Entries " << numEntries
00090 << " Number of Events " << GetNumEvents() << endl;
00091 if (GetMagDetector()==Detector::kFar)
00092 {
00093 for(Int_t i = 0; i < numEntries; i++)
00094 {
00095 os << "Timestamp " << GetTimeStamp(i).AsString("c") << setw(5)
00096 << " Current " << ffmt(GetFarCurrent(i)) << " Voltage "
00097 << ffmt(GetFarVoltage(i)) << " Supermodule number "<<GetFarSupermodule(i);
00098 GetFarThermocoupleArray(i,iArray);
00099 for(Int_t k = 0; k < 29; k++)
00100 {
00101 fArray[k] = 0;
00102 memcpy(&fArray[k],&iArray[k],4);
00103 }
00104 for(Int_t j = 0; j < 29; j++)
00105 {
00106 os << " Thermocouple " << j+1 << " "
00107 << ffmt(fArray[j]);
00108 }
00109 os << " Imbalance voltage " << ffmt(GetFarImbalanceVoltage(i)) << endl;
00110 }
00111 }
00112 if (GetMagDetector()==Detector::kCalDet)
00113 {
00114 for(Int_t i = 0; i < numEntries; i++)
00115 {
00116 os << "Timestamp " << GetTimeStamp(i).AsString("c") << setw(5);
00117 if (GetCalIsT7(i)==1)
00118 {
00119 os << " ZT7_BHZ01S7 " << ffmt(GetCalZT7_BHZ01S7(i))
00120 << " ZT7_BHZ01NS7 " << ffmt(GetCalZT7_BHZ01NS7(i))
00121 << " ZT7_BHZ02 " << ffmt(GetCalZT7_BHZ02(i))
00122 << " ZT7_QFO01 " << ffmt(GetCalZT7_QFO01(i))
00123 << " ZT7_QDE02 " << ffmt(GetCalZT7_QDE02(i))
00124 << " ZT7_QFO03 " << ffmt(GetCalZT7_QFO03(i))
00125 << " ZT7_QDE04 " << ffmt(GetCalZT7_QDE04(i))
00126 << " ZT7_QFO05 " << ffmt(GetCalZT7_QFO05(i));
00127 }
00128 if (GetCalIsT11(i)==1)
00129 {
00130 os << " ZT11_QDE01 " << ffmt(GetCalZT11_QDE01(i))
00131 << " ZT11_QFO02 " << ffmt(GetCalZT11_QFO02(i))
00132 << " ZT11_BHZ01 " << ffmt(GetCalZT11_BHZ01(i))
00133 << " ZT11_QFO03 " << ffmt(GetCalZT11_QFO03(i))
00134 << " ZT11_BHZ02 " << ffmt(GetCalZT11_BHZ02(i))
00135 << " ZT11_QFO04 " << ffmt(GetCalZT11_QFO04(i))
00136 << " ZT11_QDE05 " << ffmt(GetCalZT11_QDE05(i))
00137 << " ZT11_QVT01 " << ffmt(GetCalZT11_QVT01(i));
00138 }
00139 os << endl;
00140 }
00141 os << endl;
00142 }
00143 if (GetMagDetector()==Detector::kNear)
00144 {
00145 for(Int_t i = 0; i < numEntries; i++)
00146 {
00147 os << "Timestamp " << GetTimeStamp(i).AsString("c") << setw(5)
00148 << " Current " << ffmt(GetNearCurrent(i)) << " Voltage "
00149 << ffmt(GetNearVoltage(i)) << " Voltage ref: "
00150 << ffmt(GetNearVoltageReference(i))
00151 << " On or Off (on is 1): " << GetNearOnOffState(i)
00152 << " Raw Data: " << GetNearRawData(i) << " Remote: "
00153 << GetNearLocalRemoteState(i) << " Interlocks: "
00154 << GetNearInterLockState(i) << " ground fault: "
00155 << GetNearGroundFault(i) << " current reg: "
00156 << GetNearCurrentRegMode(i);
00157 }
00158 os << endl;
00159 }
00160 return os;
00161 }
00162
00163 Int_t RawDcsMagnetMonitorBlock::GetMagDetector() const
00164 {
00165 RawBlockId rbid = GetBlockId();
00166 return rbid.GetDetector();
00167 }
00168
00169 void RawDcsMagnetMonitorBlock::FillMagnetArray() const
00170 {
00171
00173 MagnetArray = 3 + GetData();
00174 }
00175
00176 VldTimeStamp RawDcsMagnetMonitorBlock::GetTimeStamp(Int_t indx) const
00177 {
00178 FillMagnetArray();
00179 if (GetMagDetector()==Detector::kCalDet)
00180 return VldTimeStamp(MagnetArray[indx*11],0);
00181 if (GetMagDetector()==Detector::kNear)
00182 return VldTimeStamp(MagnetArray[indx*5],0);
00183 if (GetMinorId()==1)
00184 return VldTimeStamp(MagnetArray[(indx*32)],0);
00185 if (GetMinorId()==2)
00186 return VldTimeStamp(MagnetArray[(indx*33)],0);
00187 if (GetMinorId()==3)
00188 return VldTimeStamp(MagnetArray[(indx*34)],0);
00189 printf("fell through on minor version number\n");
00190 exit(1);
00191 }
00192
00193 Float_t RawDcsMagnetMonitorBlock::GetNearCurrent(Int_t indx) const
00194 {
00195 FillMagnetArray();
00196 Float_t fValue=0.0;
00197 if (GetMinorId()==4)
00198 memcpy(&fValue,&MagnetArray[(indx*5)+1],4);
00199 return fValue;
00200 }
00201
00202 Float_t RawDcsMagnetMonitorBlock::GetNearVoltage(Int_t indx) const {
00203 FillMagnetArray();
00204 Float_t fValue=0.0;
00205 if (GetMinorId()==4)
00206 memcpy(&fValue,&MagnetArray[(indx*5)+2],4);
00207 return fValue;
00208 }
00209
00210 Float_t RawDcsMagnetMonitorBlock::GetNearVoltageReference(Int_t indx) const {
00211 FillMagnetArray();
00212 Float_t fValue=0.0;
00213 if (GetMinorId()==4)
00214 memcpy(&fValue,&MagnetArray[(indx*5)+3],4);
00215 return fValue;
00216 }
00217
00218 Int_t RawDcsMagnetMonitorBlock::GetNearRawData(Int_t indx) const {
00219 FillMagnetArray();
00220 if (GetMinorId()==4)
00221 return MagnetArray[(indx*5)+4];
00222
00223 return 0;
00224 }
00225
00226 Int_t RawDcsMagnetMonitorBlock::GetNearLocalRemoteState(Int_t indx) const {
00227 Int_t raw = GetNearRawData(indx);
00228 return (raw%2);
00229 }
00230
00231 Int_t RawDcsMagnetMonitorBlock::GetNearInterLockState(Int_t indx) const {
00232 Int_t raw = GetNearRawData(indx);
00233 return (raw/2)%2;
00234 }
00235
00236 Int_t RawDcsMagnetMonitorBlock::GetNearOnOffState(Int_t indx) const {
00237 Int_t raw = GetNearRawData(indx);
00238 return (raw/4)%2;
00239 }
00240
00241 Int_t RawDcsMagnetMonitorBlock::GetNearGroundFault(Int_t indx) const {
00242 Int_t raw = GetNearRawData(indx);
00243 return (raw/8)%2;
00244 }
00245
00246 Int_t RawDcsMagnetMonitorBlock::GetNearDCOverCurrent(Int_t indx) const {
00247 Int_t raw = GetNearRawData(indx);
00248 return (raw/16)%2;
00249 }
00250
00251 Int_t RawDcsMagnetMonitorBlock::GetNearOverTemp(Int_t indx) const {
00252 Int_t raw = GetNearRawData(indx);
00253 return (raw/32)%2;
00254 }
00255
00256 Int_t RawDcsMagnetMonitorBlock::GetNearCurrentRegMode(Int_t indx) const {
00257 Int_t raw = GetNearRawData(indx);
00258 return (raw/64)%2;
00259 }
00260
00261 Int_t RawDcsMagnetMonitorBlock::GetNearExternalRef(Int_t indx) const {
00262 Int_t raw = GetNearRawData(indx);
00263 return (raw/128)%2;
00264 }
00265
00266 Int_t RawDcsMagnetMonitorBlock::GetNearPolarity(Int_t indx) const {
00267 Int_t raw = GetNearRawData(indx);
00268 return (raw/256)%2;
00269 }
00270
00271
00272 Float_t RawDcsMagnetMonitorBlock::GetFarCurrent(Int_t indx) const
00273 {
00274 FillMagnetArray();
00275 Float_t fValue=0.0;
00276 if (GetMinorId()==1)
00277 memcpy(&fValue,&MagnetArray[(indx*32)+1],4);
00278 if (GetMinorId()==2)
00279 memcpy(&fValue,&MagnetArray[(indx*33)+1],4);
00280 if (GetMinorId()==3)
00281 memcpy(&fValue,&MagnetArray[(indx*34)+1],4);
00282 return fValue;
00283 }
00284
00285 Float_t RawDcsMagnetMonitorBlock::GetFarVoltage(Int_t indx) const
00286 {
00287 FillMagnetArray();
00288 Float_t fValue = 0.0;
00289 if (GetMinorId()==1)
00290 memcpy(&fValue,&MagnetArray[(indx*32)+2],4);
00291 if (GetMinorId()==2)
00292 memcpy(&fValue,&MagnetArray[(indx*33)+2],4);
00293 if (GetMinorId()==3)
00294 memcpy(&fValue,&MagnetArray[(indx*34)+2],4);
00295 return fValue;
00296 }
00297
00298 Float_t RawDcsMagnetMonitorBlock::GetFarImbalanceVoltage(Int_t indx) const
00299 {
00300 FillMagnetArray();
00301 Float_t fValue = 0.0;
00302 if (GetMinorId()<3)
00303 return fValue;
00304 memcpy(&fValue,&MagnetArray[(indx*34)+33],4);
00305 return fValue;
00306 }
00307
00308 Int_t RawDcsMagnetMonitorBlock::GetFarSupermodule(Int_t indx) const
00309 {
00310 FillMagnetArray();
00311 Int_t iValue=0;
00312 if (GetMinorId()==1)
00313 return 1;
00314 if (GetMinorId()==2)
00315 {
00316 memcpy(&iValue,&MagnetArray[(indx*33)+32],4);
00317 return iValue;
00318 }
00319 if (GetMinorId()==3)
00320 {
00321 memcpy(&iValue,&MagnetArray[(indx*34)+32],4);
00322 return iValue;
00323 }
00324 return 0;
00325 }
00326
00327 void RawDcsMagnetMonitorBlock::GetFarThermocoupleArray(Int_t indx, Int_t iArray[30]) const
00328 {
00329 FillMagnetArray();
00330 if (GetMinorId()==1)
00331 for(Int_t i = 0; i < 29; i++)
00332 {
00333 iArray[i] = MagnetArray[(indx*32)+3+i];
00334 }
00335 if (GetMinorId()==2)
00336 for (Int_t i = 0; i < 30; i++)
00337 {
00338 iArray[i] = MagnetArray[(indx*33)+3+i];
00339 }
00340 if (GetMinorId()==3)
00341 for (Int_t i = 0; i < 30; i++)
00342 {
00343 iArray[i] = MagnetArray[(indx*34)+3+i];
00344 }
00345 }
00346
00347 Int_t RawDcsMagnetMonitorBlock::GetNumEntries() const
00348 {
00349 if (GetMagDetector()==Detector::kCalDet)
00350 {
00351 if((fSize-3)%18)
00352 {
00353 MSG("RawData",Msg::kError)
00354 << " Size of Magnet Block screwed up. Have: "
00355 << (fSize-3)%18 << " left over from modulo 18. "
00356 << endl;
00357 return -1;
00358 }
00359 return ((fSize-3)/18);
00360 }
00361 if (GetMinorId()==1)
00362 {
00363 if((fSize-3)%32)
00364 {
00365 MSG("RawData",Msg::kError)
00366 << " Size of Magnet Block screwed up. Have: "
00367 << (fSize-3)%32 << " left over from modulo 32. "
00368 << endl;
00369 return -1;
00370 }
00371 return ((fSize-3)/32);
00372 }
00373 if (GetMinorId()==2)
00374 {
00375 if((fSize-3)%33)
00376 {
00377 MSG("RawData",Msg::kError)
00378 << " Size of Magnet Block screwed up. Have: "
00379 << (fSize-3)%33 << " left over from modulo 33. "
00380 << endl;
00381 return -1;
00382 }
00383 return ((fSize-3)/33);
00384 }
00385 if (GetMinorId()==3)
00386 {
00387 if((fSize-3)%34)
00388 {
00389 MSG("RawData",Msg::kError)
00390 << " Size of Magnet Block screwed up. Have: "
00391 << (fSize-3)%34 << " left over from modulo 34. "
00392 << endl;
00393 return -1;
00394 }
00395 return ((fSize-3)/34);
00396 }
00397 if ((GetMinorId()==4)&&(GetMagDetector()==Detector::kNear))
00398 {
00399 if((fSize-3)%5)
00400 {
00401 MSG("RawData",Msg::kError)
00402 << " Size of Magnet Block screwed up. Have: "
00403 << (fSize-3)%5 << " left over from modulo 34. "
00404 << endl;
00405 return -1;
00406 }
00407 return ((fSize-3)/5);
00408 }
00409 return 0;
00410 }
00411
00412 Int_t RawDcsMagnetMonitorBlock::GetNumEvents() const
00413 {
00414 return GetNumEntries();
00415 }
00416
00417 VldContext RawDcsMagnetMonitorBlock::GetVldContext() const
00418 {
00419 RawBlockId rbid = GetBlockId();
00420 return VldContext(rbid.GetDetector(),rbid.GetSimFlag(),GetTimeStamp(0));
00421 }
00422
00423
00424
00425 Int_t RawDcsMagnetMonitorBlock::GetCalIsT7(Int_t indx) const
00426 {
00427 if(GetMagDetector()!=Detector::kCalDet)
00428 return 0;
00429 FillMagnetArray();
00430 return MagnetArray[(indx*18)+1];
00431 }
00432
00433 Int_t RawDcsMagnetMonitorBlock::GetCalIsT11(Int_t indx) const
00434 {
00435 if (GetCalIsT7(indx)==1)
00436 return 0;
00437 return 1;
00438 }
00439
00440 Float_t RawDcsMagnetMonitorBlock::GetCalZT7_BHZ01S7(Int_t indx) const
00441 {
00442 if(GetMagDetector()!=Detector::kCalDet)
00443 return 0.0;
00444 FillMagnetArray();
00445 Float_t fValue=0;
00446 memcpy(&fValue,&MagnetArray[(indx*18)+2],4);
00447 return fValue;
00448 }
00449
00450 Float_t RawDcsMagnetMonitorBlock::GetCalZT7_BHZ01NS7(Int_t indx) const
00451 {
00452 if(GetMagDetector()!=Detector::kCalDet)
00453 return 0.0;
00454 FillMagnetArray();
00455 Float_t fValue=0;
00456 memcpy(&fValue,&MagnetArray[(indx*18)+3],4);
00457 return fValue;
00458 }
00459
00460 Float_t RawDcsMagnetMonitorBlock::GetCalZT7_BHZ02(Int_t indx) const
00461 {
00462 if(GetMagDetector()!=Detector::kCalDet)
00463 return 0.0;
00464 FillMagnetArray();
00465 Float_t fValue=0;
00466 memcpy(&fValue,&MagnetArray[(indx*18)+4],4);
00467 return fValue;
00468 }
00469
00470 Float_t RawDcsMagnetMonitorBlock::GetCalZT7_QFO01(Int_t indx) const
00471 {
00472 if(GetMagDetector()!=Detector::kCalDet)
00473 return 0.0;
00474 FillMagnetArray();
00475 Float_t fValue=0;
00476 memcpy(&fValue,&MagnetArray[(indx*18)+5],4);
00477 return fValue;
00478 }
00479
00480 Float_t RawDcsMagnetMonitorBlock::GetCalZT7_QDE02(Int_t indx) const
00481 {
00482 if(GetMagDetector()!=Detector::kCalDet)
00483 return 0.0;
00484 FillMagnetArray();
00485 Float_t fValue=0;
00486 memcpy(&fValue,&MagnetArray[(indx*18)+6],4);
00487 return fValue;
00488 }
00489
00490 Float_t RawDcsMagnetMonitorBlock::GetCalZT7_QFO03(Int_t indx) const
00491 {
00492 if(GetMagDetector()!=Detector::kCalDet)
00493 return 0.0;
00494 FillMagnetArray();
00495 Float_t fValue=0;
00496 memcpy(&fValue,&MagnetArray[(indx*18)+7],4);
00497 return fValue;
00498 }
00499
00500 Float_t RawDcsMagnetMonitorBlock::GetCalZT7_QDE04(Int_t indx) const
00501 {
00502 if(GetMagDetector()!=Detector::kCalDet)
00503 return 0.0;
00504 FillMagnetArray();
00505 Float_t fValue=0;
00506 memcpy(&fValue,&MagnetArray[(indx*18)+8],4);
00507 return fValue;
00508 }
00509
00510 Float_t RawDcsMagnetMonitorBlock::GetCalZT7_QFO05(Int_t indx) const
00511 {
00512 if(GetMagDetector()!=Detector::kCalDet)
00513 return 0.0;
00514 FillMagnetArray();
00515 Float_t fValue=0;
00516 memcpy(&fValue,&MagnetArray[(indx*18)+9],4);
00517 return fValue;
00518 }
00519
00520 Float_t RawDcsMagnetMonitorBlock::GetCalZT11_QDE01(Int_t indx) const
00521 {
00522 if(GetMagDetector()!=Detector::kCalDet)
00523 return 0.0;
00524 FillMagnetArray();
00525 Float_t fValue=0;
00526 memcpy(&fValue,&MagnetArray[(indx*18)+10],4);
00527 return fValue;
00528 }
00529
00530 Float_t RawDcsMagnetMonitorBlock::GetCalZT11_QFO02(Int_t indx) const
00531 {
00532 if(GetMagDetector()!=Detector::kCalDet)
00533 return 0.0;
00534 FillMagnetArray();
00535 Float_t fValue=0;
00536 memcpy(&fValue,&MagnetArray[(indx*18)+11],4);
00537 return fValue;
00538 }
00539
00540 Float_t RawDcsMagnetMonitorBlock::GetCalZT11_BHZ01(Int_t indx) const
00541 {
00542 if(GetMagDetector()!=Detector::kCalDet)
00543 return 0.0;
00544 FillMagnetArray();
00545 Float_t fValue=0;
00546 memcpy(&fValue,&MagnetArray[(indx*18)+12],4);
00547 return fValue;
00548 }
00549
00550 Float_t RawDcsMagnetMonitorBlock::GetCalZT11_QFO03(Int_t indx) const
00551 {
00552 if(GetMagDetector()!=Detector::kCalDet)
00553 return 0.0;
00554 FillMagnetArray();
00555 Float_t fValue=0;
00556 memcpy(&fValue,&MagnetArray[(indx*18)+13],4);
00557 return fValue;
00558 }
00559
00560 Float_t RawDcsMagnetMonitorBlock::GetCalZT11_BHZ02(Int_t indx) const
00561 {
00562 if(GetMagDetector()!=Detector::kCalDet)
00563 return 0.0;
00564 FillMagnetArray();
00565 Float_t fValue=0;
00566 memcpy(&fValue,&MagnetArray[(indx*18)+14],4);
00567 return fValue;
00568 }
00569
00570 Float_t RawDcsMagnetMonitorBlock::GetCalZT11_QFO04(Int_t indx) const
00571 {
00572 if(GetMagDetector()!=Detector::kCalDet)
00573 return 0.0;
00574 FillMagnetArray();
00575 Float_t fValue=0;
00576 memcpy(&fValue,&MagnetArray[(indx*18)+15],4);
00577 return fValue;
00578 }
00579
00580 Float_t RawDcsMagnetMonitorBlock::GetCalZT11_QDE05(Int_t indx) const
00581 {
00582 if(GetMagDetector()!=Detector::kCalDet)
00583 return 0.0;
00584 FillMagnetArray();
00585 Float_t fValue=0;
00586 memcpy(&fValue,&MagnetArray[(indx*18)+16],4);
00587 return fValue;
00588 }
00589
00590 Float_t RawDcsMagnetMonitorBlock::GetCalZT11_QVT01(Int_t indx) const
00591 {
00592 if(GetMagDetector()!=Detector::kCalDet)
00593 return 0.0;
00594 FillMagnetArray();
00595 Float_t fValue=0;
00596 memcpy(&fValue,&MagnetArray[(indx*18)+17],4);
00597 return fValue;
00598 }
00599