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

RawLIAdcSummaryBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawLIAdcSummaryBlock.cxx,v 1.16 2004/09/02 21:21:23 rhatcher Exp $
00003 // 
00004 // RawLIAdcSummaryBlock 
00005 // 
00006 // RawLIAdcSummaryBlock holds a block of raw light injection summaries
00007 //  and knows how to unpack it into individual RawLIAdcSummary's
00008 //
00009 // Author:  R. Hatcher 2001.05.10
00010 //
00012 
00013 #include "RawData/RawLIAdcSummaryBlock.h"
00014 
00015 enum EDebugLIAdcSummaryBlock {
00016    dbg_DumpHeaderOnUnpack = 0x0001,
00017    dbg_DumpCrateOnUnpack  = 0x0002,
00018    dbg_DumpAdcSumOnUnpack = 0x0004
00019 };
00020 
00021 UInt_t RawLIAdcSummaryBlock::fgDebugFlags = 0;
00022 //  dbg_DumpCrateOnUnpack | dbg_DumpAdcSumOnUnpack;
00023 
00024 #include "RawData/RawLIHeader.h"
00025 #include "RawData/RawLIAdcSummary.h"
00026 
00027 #include "MessageService/MsgStream.h"
00028 #include "MessageService/MsgService.h"
00029 CVSID("$Id: RawLIAdcSummaryBlock.cxx,v 1.16 2004/09/02 21:21:23 rhatcher Exp $");
00030 
00031 #include "RawData/RawBlockRegistry.h"
00032 REGISTERRAWBLOCK(RawLIAdcSummaryBlock,kMdBlockLiSummaryAdc,0);
00033 
00034 ClassImp(RawLIAdcSummaryBlock)
00035 
00036 //_____________________________________________________________________________
00037 RawLIAdcSummaryBlock::RawLIAdcSummaryBlock() :
00038   RawDataBlock(), fRawLIHeader(0), fRawCrateStatuses(0), fRawAdcSums(0)
00039 {
00040    // Default constructor
00041 }
00042 
00043 //_____________________________________________________________________________
00044 RawLIAdcSummaryBlock::RawLIAdcSummaryBlock(const Int_t *block)
00045   : RawDataBlock(block), 
00046     fRawLIHeader(0), fRawCrateStatuses(0), fRawAdcSums(0)
00047 {
00048    //  stored block format is:
00049    //---------------------
00050    //  0   # words in block
00051    //  1   checksum
00052    //  2   Block Id
00053    //-----
00054    //  3   CalibType   | CalibPoint#
00055    //  4   PulserBox # | LED #
00056    //  5   PulseHeight | PulseWidth
00057    //  6   # pulses    | flashing period
00058    //  7   T0 (1st ROP) sec
00059    //  8   T0 (1st ROP) nsec
00060    //  9   spare field 0 (v0,v1) : # pulses used in this summary (v2)
00061    // 10   spare field 1 (v0,v1) : spare field 0  (v2)
00062    //-----
00063    // 11   Crate # i (+extra)
00064    // 12   # of crate entries (N_i)
00065    //-----
00066    // 13   ChAdd 1_i  | # of entries
00067    // 14   Mean*4     | RMS*4
00068    // 15   ChAdd 2_i  | # of entries
00069    // 16   Mean*4     | RMS*4
00070    //  ...
00071    //      ChAdd N_i  | # of entries
00072    //      Mean*4     | RMS*4
00073    //-----
00074    //  x   Crate # j (+extra)
00075    //      # of crate entries (N_j)
00076    //-----
00077    //      ChAdd 1_j  | # of entries
00078    //      Mean*4     | RMS*4
00079    //      ChAdd 2_j  | # of entries
00080    //      Mean*4     | RMS*4
00081    //  ...
00082    //      ChAdd N_j  | # of entries
00083    //      Mean*4     | RMS*4
00084 
00085    // version 0:
00086    // 1st 32-bit word: no of entries (16); Chadd (16)
00087    // 2nd 32-bit word: RMS (16); Mean (16)
00088    // Mean and RMS are both scaled by a factor of 4, so that they have a
00089    // two-binal resolution.
00090 
00091    // version 1:
00092    // 1st 32-bit word: Chadd (16); no of entries (16)
00093    // 2nd 32-bit word: Mean (16);  RMS (16)
00094    // Mean and RMS are both scaled by a factor of 4, so that they have a
00095    // two-binal resolution.
00096 
00097    // version 2:
00098    // 1st 32-bit word: Chadd (16); no of entries (16)
00099    // 2nd 32-bit word: Mean (17);  RMS (15)
00100    // Mean is scaled by a factor of 4 and RMS scaled by 2.
00101    // Mean is a 2's complement # (ie. when unpacking high order bit
00102    // of the field must be sign extended).
00103 
00104    // We're now up to v4 - look in RawLIAdcSummary.cxx
00105 
00106 }
00107 
00108 //_____________________________________________________________________________
00109 RawLIAdcSummaryBlock::~RawLIAdcSummaryBlock()
00110 {
00111 
00112    if (fRawLIHeader) {
00113       delete fRawLIHeader;
00114       fRawLIHeader = 0;
00115    }
00116 
00117    if (fRawAdcSums) {
00118       fRawAdcSums->Delete();
00119       delete fRawAdcSums;
00120       fRawAdcSums = 0;
00121    }
00122    if (fRawCrateStatuses) {
00123       fRawCrateStatuses->Delete();
00124       delete fRawCrateStatuses;
00125       fRawCrateStatuses = 0;
00126    }
00127    return;
00128 }
00129 
00130 
00131 //_____________________________________________________________________________
00132 RawLIAdcSummaryBlock& RawLIAdcSummaryBlock::operator=(const RawLIAdcSummaryBlock& rhs)
00133 {
00134 
00135    // deep copy assignment
00136    if (this != &rhs) {
00137      RawDataBlock::operator=(rhs);
00138 
00139      if (fRawLIHeader) {
00140        delete fRawLIHeader;
00141        fRawLIHeader = 0;
00142      }
00143      
00144      if (fRawAdcSums) {
00145        fRawAdcSums->Delete();
00146        delete fRawAdcSums;
00147        fRawAdcSums = 0;
00148      }
00149      if (fRawCrateStatuses) {
00150        fRawCrateStatuses->Delete();
00151        delete fRawCrateStatuses;
00152        fRawCrateStatuses = 0;
00153      }
00154    }
00155    return *this;
00156 }
00157 
00158 //_____________________________________________________________________________
00159 Int_t RawLIAdcSummaryBlock::GetNumberOfSummaries(void) const
00160 {
00161    // create/fill the TObjArray of RawAdcSummarys (if it doesn't exist)
00162    // return the number of entries
00163 
00164    if ( ! fRawAdcSums ) FillRawAdcSums();
00165    return fRawAdcSums->GetEntriesFast(); // known not to have gaps
00166 }
00167 
00168 //_____________________________________________________________________________
00169 const RawLIAdcSummary* RawLIAdcSummaryBlock::At(Int_t idx) const
00170 {
00171    // create/fill the TObjArray of RawAdcSummarys (if it doesn't exist)
00172    // return pointer to the i-th element
00173 
00174    if ( ! fRawAdcSums ) FillRawAdcSums();
00175    return (RawLIAdcSummary*) fRawAdcSums->At(idx);
00176 }
00177 
00178 //_____________________________________________________________________________
00179 TIter RawLIAdcSummaryBlock::GetDatumIter(Bool_t dir) const
00180 {
00181    // create/fill the TObjArray of RawAdcSummarys (if it doesn't exist)
00182    // return an iterator to look over them
00183 
00184    if ( ! fRawAdcSums ) FillRawAdcSums();
00185    return TIter(fRawAdcSums,dir);
00186 }
00187 
00188 //_____________________________________________________________________________
00189 Int_t RawLIAdcSummaryBlock::IndexOf(RawLIAdcSummary *rawAdcSum) const
00190 {
00191    // create/fill the TObjArray of RawAdcSummarys (if it doesn't exist)
00192    // return the index for this object (if contained in the list)
00193 
00194    if ( ! fRawAdcSums ) FillRawAdcSums();
00195    return fRawAdcSums->IndexOf(rawAdcSum);
00196 }
00197 
00198 //_____________________________________________________________________________
00199 void RawLIAdcSummaryBlock::FillRawAdcSums() const
00200 {
00201    // create the TObjArray of RawAdcSum (if it doesn't exist)
00202 
00203    if ( fRawAdcSums ) return;   // already filled
00204    if ( fSize <= 0 || fRawBlock == 0) {
00205       MSG("RawData",Msg::kWarning)
00206          << "RawLIAdcSummaryBlock::FillRawAdcSums empty block? "
00207          << fSize << " " << fRawBlock << endl;
00208       // build a dummy header at least
00209       fRawLIHeader = new RawLIHeader;
00210       return;
00211    }
00212 
00213    fRawCrateStatuses = new TObjArray();
00214    fRawAdcSums       = new TObjArray();
00215    RawCrateStatus  *cratestatus = 0;
00216    RawLIAdcSummary *rawAdcSum   = 0;
00217    const Int_t    *p   = fRawBlock;
00218    const Int_t    *end = fRawBlock + fSize; // 1 beyond end
00219 
00220    RawBlockId rbid = GetBlockId();
00221    Int_t minor = rbid.GetMinor();
00222 
00223    p += 3; // skip #words, blockid and checksum
00224 
00225    // eat up the common header info
00226    fRawLIHeader = new RawLIHeader(rbid,p);
00227 
00228    if (fgDebugFlags&dbg_DumpHeaderOnUnpack) fRawLIHeader->Print();
00229 
00230    while (p<end) {
00231       // start a new crate (pointer advanced by RawCrateStatus ctor
00232       cratestatus = new RawCrateStatus(rbid,p);
00233       fRawCrateStatuses->Add(cratestatus);
00234       Int_t npairs = cratestatus->GetEntries(); 
00235 
00236       if (fgDebugFlags&dbg_DumpCrateOnUnpack) cratestatus->Print();
00237 
00238       for (Int_t ipair = 0; ipair < npairs; ipair++) {
00239          rawAdcSum = new RawLIAdcSummary(p,cratestatus,minor);
00240          fRawAdcSums->Add(rawAdcSum);
00241 
00242          if (fgDebugFlags&dbg_DumpAdcSumOnUnpack) {
00243            std::cout << " i=" << ipair << " ";
00244            rawAdcSum->Print();
00245          }
00246          if (p>end) {
00247             MSG("RawData",Msg::kWarning)
00248                << "RawLIAdcSummaryBlock::FillRawAdcSums crate info seems trashed"
00249                << endl << " SimFlag " << SimFlag::AsString(rbid.GetSimFlag())
00250                << endl;
00251             break;
00252          }
00253       }
00254    }
00255 
00256 }
00257 
00258 //_____________________________________________________________________________
00259 std::ostream& RawLIAdcSummaryBlock::FormatToOStream(std::ostream& os, 
00260                                                     Option_t *option) const
00261 {
00262    RawDataBlock::FormatToOStream(os,option);
00263    if (option[0] == 'X') return os;
00264 
00265    TIter iter = GetDatumIter();
00266 
00267    const RawLIHeader* header = GetHeader();
00268    os << (*header);
00269 
00270    os << " " << "Channel         " 
00271       << "entries"
00272       << " " << "      Mean" << "          "
00273       << " " << "       RMS" << "          "
00274       << endl;
00275 
00276    TObject *tobj;
00277    RawLIAdcSummary *usum;
00278    while ( ( tobj = iter.Next() ) ) {
00279       usum = dynamic_cast<RawLIAdcSummary *>(tobj);
00280       if (usum)  os << (*usum);
00281    }
00282    os << endl;
00283 
00284    return os;   
00285 
00286 }
00287 
00288 //_____________________________________________________________________________

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