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

RawSpillServerMonitorBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawSpillServerMonitorBlock.cxx,v 1.2 2005/01/26 20:29:21 rhatcher Exp $
00003 // 
00004 // RawSpillServerMonitorBlock 
00005 // 
00006 // RawSpillServerMonitorBlock holds the information about spill
00007 //    timing (and estimates thereof).
00008 //
00009 // Author:  R. Hatcher 2004.10.13
00010 //
00012 
00013 #include "RawData/RawSpillServerMonitorBlock.h"
00014 #include "TString.h"
00015 
00016 UInt_t RawSpillServerMonitorBlock::fgDebugFlags = 0;
00017 
00018 #include "MessageService/MsgService.h"
00019 //CVSID("$Id: RawSpillServerMonitorBlock.cxx,v 1.2 2005/01/26 20:29:21 rhatcher Exp $");
00020 //#include "MessageService/MsgStream.h"
00021 
00022 #include "RawData/RawBlockRegistry.h"
00023 REGISTERRAWBLOCK(RawSpillServerMonitorBlock,kMdBlockSpillServerMonitor,0);
00024 
00025 ClassImp(RawSpillServerMonitorBlock)
00026 
00027 enum EDaqHeaderBlkPos {
00028    indx_size       =  0,
00029    indx_checksum   =  1,
00030    indx_blockid    =  2,
00031    indx_run        =  3,
00032    indx_subrun     =  4,
00033    indx_runtype    =  indx_subrun,
00034    indx_start_sec  =  5,
00035    indx_start_nsec =  6,
00036    indx_tf         =  7,
00037    indx_end_sec    =  8,
00038    indx_end_nsec   =  9,
00039    indx_response   = 10,
00040    indx_spilldata  = 11, // start of structure
00041    indx_request    = 11,
00042    indx_isknown    = 12,
00043    indx_spilltype  = 13,
00044    indx_spillid    = 14,
00045    indx_near_sec   = 15,
00046    indx_near_nsec  = 16,
00047    indx_far_sec    = 17,
00048    indx_far_nsec   = 18,
00049    indx_esterr_ns  = 19,
00050    indx_open_ns    = 20,
00051    indx_close_ns   = 21,
00052    zzzz_last       = 22
00053 };
00054 
00055 //_____________________________________________________________________________
00056 RawSpillServerMonitorBlock::RawSpillServerMonitorBlock() : RawDataBlock()
00057 {
00058    // Default constructor
00059 }
00060 
00061 //_____________________________________________________________________________
00062 RawSpillServerMonitorBlock::RawSpillServerMonitorBlock(const Int_t *block)
00063    : RawDataBlock(block)
00064 {
00065    //  stored block format is:
00066    //---------------------
00067    //  0   # words in block
00068    //  1   checksum
00069    //  2   Block Id
00070    //-----
00071    //  3   run #
00072    //  4   {subrun #| run type}
00073    //  5   timeframe start timestamp (sec)
00074    //  6   timeframe start timestamp (nsec)
00075    //  7   timeframe #
00076    //  8   timeframe end timestamp (sec)
00077    //  9   timeframe end timestamp (nsec)
00078    // 10   query response time (usec if >=0; error code if <0)
00079    // 11   request sec
00080    // 12   isKnown
00081    // 13   spill type
00082    // 14   spill id (unique 'DAQ' id for spill)
00083    // 15   near spill timestamp (sec)
00084    // 16   near spill timestamp (nsec)
00085    // 17   far spill timestamp (sec)
00086    // 18   far spill timestamp (nsec)
00087    // 19   estimated worst case error (nsec)
00088    // 20   suggested window open time (nsec)
00089    // 21   suggested window close time (nsec)
00090 }
00091 //_____________________________________________________________________________
00092 RawSpillServerMonitorBlock::RawSpillServerMonitorBlock(const VldContext& vldc, Int_t run, 
00093                                      Short_t subrun, Short_t runtype,
00094                                      Int_t timeframe)
00095    : RawDataBlock()
00096 {
00097    // Component ctor
00098 
00099    fSize = zzzz_last;
00100    if (fRawBlock) delete [] fRawBlock;
00101    fRawBlock = new Int_t [fSize];
00102 
00103    fRawBlock[0] = fSize;
00104 // fRawBlock[1] = checksum... see below
00105 
00106    RawBlockRegistry& rbr = RawBlockRegistry::Instance();
00107    RawBlockProxy*    rbp = rbr.LookUp("RawSpillServerMonitorBlock");
00108 
00109    Bool_t isDCS   = rbp->IsDCS();
00110    Int_t  majorId = rbp->GetMajorId();
00111    Int_t  minorId = 1;  // latest and greatest minor version #
00112    RawBlockId rbid(majorId,minorId,isDCS,
00113                    vldc.GetDetector(),vldc.GetSimFlag());
00114    fRawBlock[2] = rbid.GetEncoded();
00115 
00116    fRawBlock[indx_run]         = run;
00117    fRawBlock[indx_subrun]      = (subrun&0xffff)<<16 | (runtype&0xffff);
00118    fRawBlock[indx_start_sec]   = vldc.GetTimeStamp().GetSec();
00119    fRawBlock[indx_start_nsec]  = vldc.GetTimeStamp().GetNanoSec();
00120    fRawBlock[indx_tf]          = timeframe;
00121    fRawBlock[indx_end_sec]     = fRawBlock[indx_start_sec] + 1;
00122    fRawBlock[indx_end_nsec]    = fRawBlock[indx_start_nsec];
00123    fRawBlock[indx_response]    = -1;
00124    fRawBlock[indx_request]     = 0;
00125    fRawBlock[indx_isknown]     = 0;
00126    fRawBlock[indx_spilltype]   = -1;
00127    fRawBlock[indx_spillid]     = 0;
00128    fRawBlock[indx_near_sec]    = 0;
00129    fRawBlock[indx_near_sec]    = 0;
00130    fRawBlock[indx_near_nsec]   = 0;
00131    fRawBlock[indx_far_sec]     = 0;
00132    fRawBlock[indx_far_nsec]    = 0;
00133    fRawBlock[indx_esterr_ns]   = 0;
00134    fRawBlock[indx_open_ns]     = 0;
00135    fRawBlock[indx_close_ns]    = 0;
00136 
00137    // fill checksum
00138    rdxsum_fill((long*)fRawBlock,0); 
00139 
00140 }
00141 
00142 //_____________________________________________________________________________
00143 RawSpillServerMonitorBlock::~RawSpillServerMonitorBlock()
00144 {
00145    // dtor
00146 }
00147 
00148 //_____________________________________________________________________________
00149 VldTimeStamp RawSpillServerMonitorBlock::GetFrameStartTime() const
00150 {
00151    // get the timestamp for the start of the timeframe
00152    if (fSize > indx_start_nsec) 
00153       return VldTimeStamp(fRawBlock[indx_start_sec],
00154                           fRawBlock[indx_start_nsec]);
00155 
00156    return VldTimeStamp((time_t)0,(Int_t)0);
00157 }
00158 
00159 //_____________________________________________________________________________
00160 VldTimeStamp RawSpillServerMonitorBlock::GetFrameEndTime() const
00161 {
00162    // get the timestamp for the end of the timeframe
00163 
00164    if (fSize > indx_end_nsec) 
00165       return VldTimeStamp(fRawBlock[indx_end_sec],
00166                           fRawBlock[indx_end_nsec]);
00167 
00168    return VldTimeStamp((time_t)0,(Int_t)0);
00169 }
00170 
00171 //_____________________________________________________________________________
00172 Int_t RawSpillServerMonitorBlock::GetRun() const
00173 {
00174    // get the run number
00175    if (fSize > indx_run) return fRawBlock[indx_run];
00176    return -1;
00177 }
00178 
00179 //_____________________________________________________________________________
00180 Short_t RawSpillServerMonitorBlock::GetSubRun() const
00181 {
00182    // get the subrun number
00183    if (fSize > indx_subrun) return (fRawBlock[indx_subrun]>>16)&0xffff;
00184    return -1;
00185 }
00186 
00187 //_____________________________________________________________________________
00188 Short_t RawSpillServerMonitorBlock::GetRunType() const
00189 {
00190    // get the run type
00191    if (fSize > indx_runtype) return fRawBlock[indx_runtype]&0xffff;
00192    return -1;
00193 }
00194 
00195 //_____________________________________________________________________________
00196 Int_t RawSpillServerMonitorBlock::GetTimeFrameNum() const
00197 {
00198    // get the timeframe number
00199    if (fSize > indx_tf) return fRawBlock[indx_tf];
00200    return -1;
00201 }
00202 
00203 //_____________________________________________________________________________
00204 Int_t RawSpillServerMonitorBlock::GetResponse() const
00205 {
00206    // get the time taken to obtain data from server (in usec)
00207    if (fSize > indx_response) return fRawBlock[indx_response];
00208    return -1;
00209 }
00210 
00211 //_____________________________________________________________________________
00212 const mdSpillData_t& RawSpillServerMonitorBlock::GetSpillData() const
00213 {
00214    // get the mdSpillData_t structure
00215   static mdSpillData_t dummySpillData; // = {0,0,0,0,0,0,0,0,0,0,0};
00216 
00217   if ((unsigned int)fSize > indx_response+sizeof(mdSpillRequest_t)) {
00218     return *(mdSpillData_t*)(fRawBlock+indx_spilldata);
00219   }
00220   else return dummySpillData;
00221 }
00222 
00223 //_____________________________________________________________________________
00224 VldContext RawSpillServerMonitorBlock::GetVldContext() const
00225 {
00226    // build validity context
00227    RawBlockId rbid = GetBlockId();
00228    return VldContext(rbid.GetDetector(),rbid.GetSimFlag(),GetTimeStamp());
00229 }
00230 
00231 //_____________________________________________________________________________
00232 std::ostream& RawSpillServerMonitorBlock::FormatToOStream(ostream& os, 
00233                                                  Option_t *option) const
00234 {
00235    RawDataBlock::FormatToOStream(os,option);
00236    if (option[0] == 'X') return os;
00237 
00238    //Int_t minor = GetMinorId();
00239 
00240    os << " [ " 
00241       << GetFrameStartTime().AsString("c") 
00242       << " : "
00243       << GetFrameEndTime().AsString("c") 
00244       << " ]"
00245       << endl;
00246    os << " Run " << GetRun()
00247       << " SubRun " << GetSubRun() 
00248       << " RunType " << GetRunType()
00249       << " TimeFrame " << GetTimeFrameNum()
00250       << endl; 
00251 
00252    Int_t response = GetResponse();
00253    os << " Response";
00254    if (response >= 0) os << " in " << response << "usec" << endl;
00255    else               os << ": " << ResponseAsString(response) << endl;
00256   
00257    // interpret mdSpillData_t info
00258 
00259    const mdSpillData_t& spillData = GetSpillData();
00260    long request_sec = spillData.request_sec;
00261    VldTimeStamp requestTimeStamp((time_t)request_sec,0);
00262    os << " Queried time: " << request_sec 
00263       << " [ " << requestTimeStamp.AsString("s") << "]" << endl;
00264    os << " isKnown " << spillData.isKnown
00265       << " " << SpillTypeAsString(spillData.isSpill)
00266       << " DAQ-ID " << spillData.spillId
00267       << endl;
00268    VldTimeStamp nearTimeStamp(spillData.spillTimeND.sec,
00269                               spillData.spillTimeND.nsec);
00270    VldTimeStamp farTimeStamp(spillData.spillTimeFD.sec,
00271                              spillData.spillTimeFD.nsec);
00272    os << " Near " << nearTimeStamp.AsString("c")
00273       << " Far " << farTimeStamp.AsString("c")
00274       << endl;
00275    os << " Est. worst error " 
00276       << spillData.spillTimeError_nsec << " ns"
00277       << endl;
00278    os << " Window open " << spillData.windowOpen_nsec
00279       << " close " << spillData.windowClose_nsec << " ns"
00280       << endl;
00281  
00282    return os;
00283 }
00284 
00285 //_____________________________________________________________________________
00286 const Char_t* RawSpillServerMonitorBlock::ResponseAsString(Int_t response)
00287 {
00288   // interpret response error codes -- tpSpillServerQueryErrors
00289  
00290   if (response>=0) return Form("in %d usec",response);
00291 
00292   switch (response) {
00293   case kSpillServerNotAsked:       return "No query to Spill Server ";                  break;
00294   case kSpillServerNoConnect:      return "Connection to Spill Server failed";          break;
00295   case kSpillServerCommsFailure:   return "Spill Server socket communications failure"; break;
00296   case kSpillServerHangUp:         return "Spill Server hung up before response";       break;
00297   case kSpillServerTimeout:        return "Timeout before Spill Server responded";      break;
00298   case kSpillServerIncompleteData: return "Incomplete Data received from Spill Server"; break;
00299   default: return "unknown tpSpillServerQueryError"; break;
00300   }
00301 }
00302 
00303 //_____________________________________________________________________________
00304 const Char_t* RawSpillServerMonitorBlock::SpillTypeAsString(Int_t spillType)
00305 {
00306   // interpret spill types -- mdSpillTypeEnum
00307 
00308   switch (spillType) {
00309   case kSpillType_None:      return "None";              break;
00310   case kSpillType_Reported:  return "Reported";          break;
00311   case kSpillType_Predicted: return "Predicted";         break;
00312   case kSpillType_Fake:      return "Fake";              break;
00313   case kSpillType_Local:     return "Local";             break;
00314   default:                   return "Unknown mdSpillTypeEnum"; break;
00315   }
00316 }
00317 
00318 //_____________________________________________________________________________

Generated on Sat Nov 21 22:47:31 2009 for loon by  doxygen 1.3.9.1