Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

RawCrateMonitorBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawCrateMonitorBlock.cxx,v 1.7 2005/08/26 19:04:53 rhatcher Exp $
00003 // 
00004 // RawCrateMonitorBlock 
00005 // 
00006 // RawCrateMonitorBlock holds a block of raw digitizations
00007 //  and knows how to unpack it into individual RawDigits
00008 //
00009 // Author:  R. Hatcher 2000.04.19
00010 //
00012 
00013 #include "RawData/RawCrateMonitorBlock.h"
00014 
00015 enum EDebugCrateMonitorBlock {
00016    kdbg_ForceHexDump  = 0x0001
00017 };
00018 UInt_t RawCrateMonitorBlock::fgDebugFlags = 0;
00019 
00020 #include "MessageService/MsgStream.h"
00021 #include "MessageService/MsgService.h"
00022 #include "MessageService/MsgFormat.h"
00023 CVSID("$Id: RawCrateMonitorBlock.cxx,v 1.7 2005/08/26 19:04:53 rhatcher Exp $");
00024 
00025 #include "RawData/RawBlockRegistry.h"
00026 REGISTERRAWBLOCK(RawCrateMonitorBlock,kMdBlockCrateMonitor,0);
00027 
00028 ClassImp(RawCrateMonitorBlock::RawVfbMonitor)
00029 
00030 ClassImp(RawCrateMonitorBlock)
00031 
00032 enum ECrateMonitorBlkPos {
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_sec        =  5,
00040    indx_nsec       =  6,
00041    indx_crateid    =  7,
00042    indx_tf         =  8,
00043    indx_roptempcpu =  9,
00044    indx_roptempmem = 10,
00045    indx_roptemppmc = 11,
00046    indx_nfeeblks   = 12,
00047    zzzz_last       = 13
00048 };
00049 
00050 static RawCrateMonitorBlock::RawVfbMonitor    dummyVfbMonitor;
00051 static RawCrateMonitorBlock::RawMasterMonitor dummyMasterMonitor;
00052 
00053 //_____________________________________________________________________________
00054 RawCrateMonitorBlock::RawCrateMonitorBlock()
00055   : RawDataBlock(), fCrateId()
00056 {
00057    // Default constructor
00058 }
00059 
00060 //_____________________________________________________________________________
00061 RawCrateMonitorBlock::RawCrateMonitorBlock(const Int_t *block)
00062   : RawDataBlock(block), fCrateId()
00063 {
00064    //  stored block format is:
00065    //---------------------
00066    //  0   # words in block
00067    //  1   checksum
00068    //  2   Block Id
00069    //-----
00070    //  3   run #
00071    //  4   subRunAndType
00072    //  5   timestamp sec
00073    //  6   timestamp nsec
00074    //  7   crateIdentifier
00075    //  8   timeFrameNumber
00076    //  9   ropTempCpuInDegC
00077    // 10   ropTempMemInDegC
00078    // 11   ropTempPmcInDegC
00079    // 12   numFeeMonitorBlocks
00080    //  ...  some number of sub structures
00081 
00082 }
00083 
00084 //_____________________________________________________________________________
00085 RawCrateMonitorBlock::~RawCrateMonitorBlock()
00086 {
00087   // dtor
00088 }
00089 
00090 //____________________________________________________________________________
00091 RawCrateMonitorBlock& RawCrateMonitorBlock::operator=(const RawCrateMonitorBlock& rhs)
00092 {
00093    // deep copy assignment 
00094    if (this != &rhs) {
00095      RawDataBlock::operator=(rhs);
00096      fCrateId = rhs.fCrateId;
00097    }
00098    return *this;
00099 }
00100 
00101 //_____________________________________________________________________________
00102 VldTimeStamp RawCrateMonitorBlock::GetTimeStamp() const
00103 {
00104    // get the timestamp
00105    if (fSize > indx_nsec) 
00106       return VldTimeStamp(fRawBlock[indx_sec],fRawBlock[indx_nsec]);
00107 
00108    return VldTimeStamp((time_t)0,(Int_t)0);
00109 }
00110 
00111 //_____________________________________________________________________________
00112 Int_t RawCrateMonitorBlock::GetRun() const
00113 {
00114    // get the run number
00115    if (fSize > indx_run) return fRawBlock[indx_run];
00116    return -1;
00117 }
00118 
00119 //_____________________________________________________________________________
00120 Short_t RawCrateMonitorBlock::GetSubRun() const
00121 {
00122    // get the subrun number
00123    if (fSize > indx_subrun) return (fRawBlock[indx_subrun]>>16)&0xffff;
00124    return -1;
00125 }
00126 
00127 //_____________________________________________________________________________
00128 Short_t RawCrateMonitorBlock::GetRunType() const
00129 {
00130    // get the run type
00131    if (fSize > indx_runtype) return fRawBlock[indx_runtype]&0xffff;
00132    return -1;
00133 }
00134 
00135 //_____________________________________________________________________________
00136 Int_t RawCrateMonitorBlock::GetCrateIdInfo() const
00137 {
00138    // get the crate id info (packed)
00139    if (fSize > indx_crateid) return fRawBlock[indx_crateid];
00140    return -1;
00141 }
00142 
00143 //_____________________________________________________________________________
00144 Int_t RawCrateMonitorBlock::GetTimeFrameNum() const
00145 {
00146    // get the time frame
00147    if (fSize > indx_tf) return fRawBlock[indx_tf];
00148    return -1;
00149 }
00150 
00151 //_____________________________________________________________________________
00152 float RawCrateMonitorBlock::GetRopTempCpuC() const
00153 {
00154    // get the ROP CPU temperature in deg C
00155    if (fSize > indx_roptempcpu) return fRawBlock[indx_roptempcpu];
00156    return -1;
00157 }
00158 
00159 //_____________________________________________________________________________
00160 float RawCrateMonitorBlock::GetRopTempMemC() const
00161 {
00162    // get the ROP memory temperature in deg C
00163    if (fSize > indx_roptempmem) return fRawBlock[indx_roptempmem];
00164    return -1;
00165 }
00166 
00167 //_____________________________________________________________________________
00168 float RawCrateMonitorBlock::GetRopTempPmcC() const
00169 {
00170    // get the ROP "pmc" temperature in deg C
00171    if (fSize > indx_roptemppmc) return fRawBlock[indx_roptemppmc];
00172    return -1;
00173 }
00174 
00175 //_____________________________________________________________________________
00176 Int_t RawCrateMonitorBlock::GetNumFeeMonitors() const
00177 {
00178    // get the # of FEE Monitor sub-blocks
00179    if (fSize > indx_nfeeblks) return fRawBlock[indx_nfeeblks];
00180    return -1;
00181 }
00182 
00183 //_____________________________________________________________________________
00184 Int_t RawCrateMonitorBlock::GetNumVfbMonitors() const
00185 {
00186    // get the # of Vfb Monitor sub-blocks
00187    UnpackFeeMonitors();
00188    return fVfbMonitors.size();
00189 }
00190 
00191 //_____________________________________________________________________________
00192 const RawCrateMonitorBlock::RawVfbMonitor& 
00193 RawCrateMonitorBlock::GetVfbMonitor(UInt_t indx) const
00194 {
00195    // get the i--th Vfb Monitor sub-blocks
00196    size_t nvfbs = GetNumVfbMonitors();
00197    if (indx >= nvfbs) {
00198      MSG("Raw",Msg::kWarning)
00199        << "GetVfbMonitors() can't get index " << indx
00200        << " as there are only " << nvfbs << endl;
00201      return dummyVfbMonitor;
00202    }
00203    return fVfbMonitors[indx];
00204 }
00205 
00206 //_____________________________________________________________________________
00207 const RawCrateMonitorBlock::RawVfbMonitor& 
00208 RawCrateMonitorBlock::GetVfbMonitor(RawChannelId rcidLookFor) const
00209 {
00210    // get the Vfb Monitor for a given raw channel (ignore chip,chan fields)
00211 
00212    if (rcidLookFor.GetElecType() != ElecType::kVA) {
00213      MSG("Raw",Msg::kWarning)
00214        << "GetVfbMonitor was supplied raw channel of wrong ElecType: "
00215        << rcidLookFor << endl;
00216      return dummyVfbMonitor;
00217    }
00218 
00219    size_t nvfbs = GetNumVfbMonitors();
00220    for (size_t indx = 0; indx < nvfbs; ++indx) {
00221      const RawVfbMonitor& vfbmon = fVfbMonitors[indx];
00222      // compare w/ pseudo (incomplete) RawChannelId 
00223      if (rcidLookFor.IsSameVfb(vfbmon.pseudo_rcid)) return vfbmon;
00224    }
00225 
00226    // fell through without finding anything appropriate
00227    MSG("Raw",Msg::kWarning)
00228        << "GetVfbMonitors() can't get find a match for " 
00229        << rcidLookFor << endl;
00230    return dummyVfbMonitor;
00231 }
00232 
00233 //_____________________________________________________________________________
00234 Int_t RawCrateMonitorBlock::GetNumMasterMonitors() const
00235 {
00236    // get the # of Master Monitor sub-blocks
00237    UnpackFeeMonitors();
00238    return fMasterMonitors.size();
00239 }
00240 
00241 //_____________________________________________________________________________
00242 const RawCrateMonitorBlock::RawMasterMonitor&
00243 RawCrateMonitorBlock::GetMasterMonitor(UInt_t indx) const
00244 {
00245    // get the i--th Master Monitor sub-blocks
00246    size_t nmasters = GetNumMasterMonitors();
00247    if (indx >= nmasters) {
00248      MSG("Raw",Msg::kWarning)
00249        << "GetMasterMonitors() can't get index " << indx
00250        << " as there are only " << nmasters << endl;
00251      return dummyMasterMonitor;
00252    }
00253    return fMasterMonitors[indx];
00254 }
00255 
00256 //_____________________________________________________________________________
00257 const RawCrateMonitorBlock::RawMasterMonitor&
00258 RawCrateMonitorBlock::GetMasterMonitor(RawChannelId rcidLookFor) const
00259 {
00260    // get the Master Monitor for a given raw channel (ignore chip,chan fields)
00261 
00262    if (rcidLookFor.GetElecType() != ElecType::kQIE) {
00263      MSG("Raw",Msg::kWarning)
00264        << "GetMasterMonitor was supplied raw channel of wrong ElecType: "
00265        << rcidLookFor << endl;
00266      return dummyMasterMonitor;
00267    }
00268 
00269    if (rcidLookFor.GetDetector() != GetBlockId().GetDetector() ||
00270        rcidLookFor.GetCrate()    != GetCrate()                    ) {
00271      MSG("Raw",Msg::kWarning)
00272        << "GetMasterMonitor was supplied wrong crate: "
00273        << rcidLookFor << endl;
00274      return dummyMasterMonitor;
00275    }
00276 
00277    UShort_t geoAddr = rcidLookFor.GetGeographicAddress();
00278 
00279    size_t nmasters = GetNumMasterMonitors();
00280    for (size_t indx = 0; indx < nmasters; ++indx) {
00281      const RawMasterMonitor& mastermon = fMasterMonitors[indx];
00282      // compare w/ pseudo (incomplete) RawChannelId 
00283      if ( mastermon.masterSlot == geoAddr ) return mastermon;
00284    }
00285 
00286    // fell through without finding anything appropriate
00287    MSG("Raw",Msg::kWarning)
00288        << "GetMasterMonitors() can't get find a match for " 
00289        << rcidLookFor << endl;
00290    return dummyMasterMonitor;
00291 }
00292 
00293 //_____________________________________________________________________________
00294 VldContext RawCrateMonitorBlock::GetVldContext() const
00295 {
00296    // build validity context
00297   RawBlockId rbid = GetBlockId();
00298   return VldContext(rbid.GetDetector(),rbid.GetSimFlag(),GetTimeStamp());
00299 }
00300 
00301 //_____________________________________________________________________________
00302 std::ostream& RawCrateMonitorBlock::FormatToOStream(ostream& os,
00303                                                     Option_t *option) const
00304 {
00305    if (fgDebugFlags & kdbg_ForceHexDump) option = "x";
00306 
00307    RawDataBlock::FormatToOStream(os,option);
00308    if (option[0] == 'X') return os;
00309 
00310    // additional block specific formatted output is done here
00311 
00312    os << " TimeStamp " << GetTimeStamp().AsString("c")
00313       << " TimeFrame " << GetTimeFrameNum() << endl;
00314    os << " Run " << GetRun()
00315       << " SubRun " << GetSubRun()
00316       << " RunType " << GetRunType();
00317    int crateid = GetCrateIdInfo();
00318 
00319    MsgFormat f8p3("f8.3");
00320    MsgFormat f9p3("f9.3");
00321 
00322    os << " Crate " << (crateid&0x3f)
00323       << " (0x" << hex << crateid << dec << ") had: " << endl
00324       << " ROP Temperatures (degC): "
00325       << f8p3(GetRopTempCpuC()) << " (CPU), "
00326       << f8p3(GetRopTempMemC()) << " (mem), "
00327       << f8p3(GetRopTempPmcC()) << " (pmc) " << endl;
00328 
00329    ElecType::Elec_t etype = GetElecType();
00330    os << " ElecType: " << ElecType::AsString(etype);
00331    switch(etype) {
00332    case ElecType::kVA:
00333      {
00334        UInt_t nvfb = GetNumVfbMonitors();
00335        os << ", unpacked into " << nvfb << " VfbMonitors " << endl;
00336        os << "       varc vfb :    grnd     asd   +rail  -rail0  -rail1  -rail2 (V)  temp (C)" << endl;
00337        //     xx[ii]x           -12345 -12345 -12345 -12345 -12345 -12345 1234567
00338        for (UInt_t indxVfb = 0; indxVfb < nvfb; ++indxVfb) {
00339          // print out the info for this VFB
00340          const RawVfbMonitor& vfbmon = GetVfbMonitor(indxVfb);
00341          os << "  " << "[" << setw(2) << indxVfb << "] "
00342             << setw(4) << vfbmon.varcId << setw(4) << vfbmon.vfbId
00343             << " :" 
00344             << f8p3(vfbmon.groundPlaneV)
00345             << f8p3(vfbmon.asdSupplyV)
00346             << f8p3(vfbmon.positiveVaRailV)
00347             << f8p3(vfbmon.negativeVaRail0V)
00348             << f8p3(vfbmon.negativeVaRail1V)
00349             << f8p3(vfbmon.negativeVaRail2V)
00350             << "   "
00351             << f9p3(vfbmon.vfbTempC)
00352            // << " [" << vfbmon.pseudo_rcid.AsString("ec") << "]"
00353             << endl;
00354        }
00355        break;
00356      };
00357    case ElecType::kQIE:
00358      {
00359        UInt_t nmaster = GetNumMasterMonitors();
00360        os << ", unpacked into " << nmaster << " MasterMonitors " << endl;
00361        for (UInt_t indxMaster = 0; indxMaster < nmaster; ++indxMaster) {
00362          // print out the info for this master
00363          const RawMasterMonitor& mastermon = GetMasterMonitor(indxMaster);
00364          os << "  " << "[" << setw(2) << indxMaster << "] "
00365             << " masterId " << setw(4) << mastermon.masterId << " "
00366             << " Slot " << setw(2) << mastermon.masterSlot << " "
00367             << " Ctrl " <<setw(2) << mastermon.masterCtrl 
00368             << " dynodeThreshold ";
00369          for (int ithr=0; ithr<4; ++ithr)
00370            os << mastermon.dynodeThreshold[ithr] << " ";
00371          os << endl;
00372          // print out the minders read out by this master
00373          UInt_t nminder = mastermon.fMinderMonitors.size();
00374          for (UInt_t indxMinder = 0; indxMinder < nminder; ++indxMinder) {
00375            const RawMinderMonitor& mindermon = 
00376              mastermon.fMinderMonitors[indxMinder];
00377            os << "     (" << indxMinder << ") "
00378               << " serial# " << setw(4) 
00379               << mindermon.GetMinderSerialNum() << " "
00380               << " slot# " << setw(2) 
00381               << mindermon.GetMinderSlot() << " "
00382               << " (0x" << hex << mindermon.minderId << dec << ") "
00383               << " sparsThr " << mindermon.sparsThreshold
00384               << endl;
00385          }
00386        }
00387        break;
00388      }
00389    default:
00390      os << " can't be unpacked (yet)." << endl;
00391    }
00392    os << endl;
00393    return os;
00394 }
00395 
00396 //_____________________________________________________________________________
00397 void RawCrateMonitorBlock::FillCrateId() const
00398 {
00399    // unpack crate info
00400    if (!fCrateId.IsNull()) return;
00401    fCrateId = RawChannelId(GetBlockId().GetDetector(),GetCrateIdInfo(),0x1fff);
00402 }
00403 
00404 //_____________________________________________________________________________
00405 void RawCrateMonitorBlock::UnpackFeeMonitors() const
00406 {
00407   // unpack individual monitor sub-blocks
00408   if (!fVfbMonitors.empty() || !fMasterMonitors.empty()) return;
00409 
00410   switch (GetElecType()) {
00411   case ElecType::kVA:  UnpackVfbMonitors(); break;
00412   case ElecType::kQIE: UnpackQieMonitors(); break;
00413   default:
00414     MSG("Raw",Msg::kWarning)
00415       << "Unpacking of data for "
00416       << ElecType::AsString(GetElecType())
00417       << " crates not yet supported" << endl;
00418   }
00419 
00420 }
00421 
00422 //_____________________________________________________________________________
00423 void RawCrateMonitorBlock::UnpackVfbMonitors() const
00424 {
00425   // unpack individual VFB monitor sub-blocks
00426 
00427   Int_t *varc_start, *vfb_start;
00428   Int_t *toofar = fRawBlock + fSize;
00429   Int_t  nvarc = GetNumFeeMonitors();
00430   Int_t  ivarc = 0;
00431 
00432   const  size_t sizeVarcSubBlk = 2;
00433   const  size_t sizeVfbSubBlk  = 8;
00434 
00435   varc_start = fRawBlock + indx_nfeeblks + 1;
00436 
00437   Detector::Detector_t det   = GetBlockId().GetDetector();
00438   ElecType::Elec_t     etype = GetElecType(); 
00439   UShort_t             crate = GetCrate();
00440 
00441   while (varc_start < toofar) {
00442     unsigned long   varcId, numVfbs;
00443     varcId  = varc_start[0];
00444     numVfbs = varc_start[1];
00445     vfb_start = varc_start + sizeVarcSubBlk;
00446     for (unsigned long currVfb = 0; currVfb < numVfbs; ++currVfb) {
00447       RawVfbMonitor vfbmon;
00448 
00449       vfbmon.varcId           = varcId;
00450       vfbmon.vfbId            = vfb_start[0];
00451       const float mVtoV = 0.001;
00452       const float mCtoC = 0.001;
00453       vfbmon.groundPlaneV     = vfb_start[1] * mVtoV;
00454       vfbmon.asdSupplyV       = vfb_start[2] * mVtoV;
00455       vfbmon.positiveVaRailV  = vfb_start[3] * mVtoV;
00456       vfbmon.negativeVaRail0V = vfb_start[4] * mVtoV;
00457       vfbmon.negativeVaRail1V = vfb_start[5] * mVtoV;
00458       vfbmon.negativeVaRail2V = vfb_start[6] * mVtoV;
00459       vfbmon.vfbTempC         = vfb_start[7] * mCtoC;
00460       UInt_t vmm    = vfbmon.vfbId >> 1;
00461       UInt_t adcsel = vfbmon.vfbId  & 1;
00462       const UInt_t vachip = 0;
00463       const UInt_t vachan = 0;
00464       vfbmon.pseudo_rcid = 
00465         RawChannelId(det,etype,crate,varcId,vmm,adcsel,vachip,vachan);
00466                                         
00467       fVfbMonitors.push_back(vfbmon);
00468       vfb_start += sizeVfbSubBlk;
00469     }
00470     ++ivarc;
00471     varc_start = vfb_start;
00472   }
00473 
00474   if (ivarc != nvarc || varc_start != toofar)
00475     MSG("Raw",Msg::kWarning)
00476       << "Unpacking reached end in an inconsistent manner"
00477       << " ptr @ " << varc_start << " should be " << toofar
00478       << " saw " << ivarc << " of " << nvarc 
00479       << " fee (Varc) sub-blocks " << endl;
00480 }
00481 
00482 //_____________________________________________________________________________
00483 void RawCrateMonitorBlock::UnpackQieMonitors() const
00484 {
00485   // unpack individual Master/Minder monitor sub-blocks
00486 
00487   Int_t *master_start, *minder_start;
00488   Int_t *toofar = fRawBlock + fSize;
00489   Int_t  nmasters = GetNumFeeMonitors();
00490   Int_t  imaster = 0;
00491 
00492   const  size_t sizeMasterSubBlk = 8;
00493   const  size_t sizeMinderSubBlk = 2;
00494   
00495   master_start = fRawBlock + indx_nfeeblks + 1;
00496     
00497   //Detector::Detector_t det   = GetBlockId().GetDetector();
00498   //ElecType::Elec_t         etype = GetElecType(); 
00499   //UShort_t                 crate = GetCrate();
00500 
00501   while (master_start < toofar) {
00502     RawMasterMonitor mastermon;
00503     mastermon.masterId           = master_start[0];
00504     mastermon.masterSlot         = master_start[1];
00505     mastermon.masterCtrl         = master_start[2];
00506     mastermon.dynodeThreshold[0] = master_start[3];
00507     mastermon.dynodeThreshold[1] = master_start[4];
00508     mastermon.dynodeThreshold[2] = master_start[5];
00509     mastermon.dynodeThreshold[3] = master_start[6];
00510     unsigned long numMinders     = master_start[7];
00511     minder_start = master_start + sizeMasterSubBlk;
00512     for (unsigned long currMinder = 0; currMinder < numMinders; ++currMinder) {
00513       RawMinderMonitor mindermon;
00514       mindermon.minderId         = minder_start[0];
00515       mindermon.sparsThreshold   = minder_start[1];  
00516       mastermon.fMinderMonitors.push_back(mindermon);
00517       minder_start += sizeMinderSubBlk;
00518     }
00519     ++imaster;
00520     fMasterMonitors.push_back(mastermon);
00521     master_start = minder_start;
00522   }
00523 
00524   if (imaster != nmasters || master_start != toofar)
00525     MSG("Raw",Msg::kWarning)
00526       << "Unpacking reached end in an inconsistent manner"
00527       << " ptr @ " << master_start << " should be " << toofar
00528       << " saw " << imaster << " of " << nmasters 
00529       << " fee (Master) sub-blocks " << endl;
00530 }
00531 
00532 //_____________________________________________________________________________

Generated on Mon Feb 15 11:07:28 2010 for loon by  doxygen 1.3.9.1