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

RawLiTpmtDigitsBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawLiTpmtDigitsBlock.cxx,v 1.5 2005/08/26 19:04:53 rhatcher Exp $
00003 // 
00004 // RawLiTpmtDigitsBlock 
00005 // 
00006 // RawLiTpmtDigitsBlock holds LightInjection TriggerPMT hits
00007 //
00008 // Author:  R. Hatcher 2003.06.30
00009 //
00011 
00012 #include "RawData/RawLiTpmtDigitsBlock.h"
00013 
00014 enum EDebugDigitDataBlock {
00015    dbg_DumpHeaderOnUnpack = 0x0001,
00016    dbg_DumpCrateOnUnpack  = 0x0002,
00017    dbg_DumpDigitOnUnpack  = 0x0004
00018 };
00019 UInt_t RawLiTpmtDigitsBlock::fgDebugFlags = 0;
00020 
00021 #include "RawData/RawCrateStatus.h"
00022 #include "RawData/RawVaMCDigit.h"
00023 #include "RawData/RawQieMCDigit.h"
00024 
00025 #include "MessageService/MsgStream.h"
00026 #include "MessageService/MsgFormat.h"
00027 
00028 #include "MessageService/MsgService.h"
00029 CVSID("$Id: RawLiTpmtDigitsBlock.cxx,v 1.5 2005/08/26 19:04:53 rhatcher Exp $");
00030 
00031 #include "RawData/RawBlockRegistry.h"
00032 REGISTERRAWBLOCK(RawLiTpmtDigitsBlock,kMdBlockLiTpmtDigits,0);
00033 
00034 ClassImp(RawLiTpmtDigitsBlock)
00035 
00036 enum ELiTpmtDigitsBlkPos {
00037    indx_size       =  0,
00038    indx_checksum   =  1,
00039    indx_blockid    =  2,
00040    indx_run        =  3,
00041    indx_subrun     =  4,
00042    indx_runtype    =  indx_subrun,
00043    indx_loadsec    =  5,
00044    indx_loadnsec   =  6,
00045    indx_tf_v1      =  7,
00046    indx_crateid_v1 =  8,
00047    indx_crateid    =  7,
00048    indx_tf         =  8,
00049    indx_ndigits    =  9,
00050    zzzz_last       = 10
00051 };
00052 
00053 //_____________________________________________________________________________
00054 RawLiTpmtDigitsBlock::RawLiTpmtDigitsBlock()
00055   : fRawCrateStatus(0), fRawDigits(0)
00056 {
00057    // Default constructor
00058 }
00059 
00060 //_____________________________________________________________________________
00061 RawLiTpmtDigitsBlock::RawLiTpmtDigitsBlock(const Int_t *block)
00062   : RawDataBlock(block), fRawCrateStatus(0), fRawDigits(0)
00063 {
00064    //  stored block format is:
00065    //---------------------
00066    //  0   # words in block           
00067    //  1   checksum                   
00068    //  2   Block Id                   
00069    //-----                                                      
00070    //  3   Run Number                 
00071    //  4   SubRun | RunType           
00072    //  5   Time (sec)                 
00073    //  6   Time (ns)                  
00074    //  7   CrateId (+ special bits)   TimeFrame # (v1)
00075    //  8   TimeFrame #                CrateId     (v1)
00076    //  8   # of digits to follow      
00077    //  ... packed two 32-bit words per digit
00078 
00079 }
00080 
00081 //_____________________________________________________________________________
00082 RawLiTpmtDigitsBlock::~RawLiTpmtDigitsBlock()
00083 {
00084    // dtor
00085    if ( fRawDigits ) {
00086      fRawDigits->Delete();
00087      delete fRawDigits;
00088      fRawDigits = 0;
00089    }
00090    if ( fRawCrateStatus ) {
00091      delete fRawCrateStatus;
00092      fRawCrateStatus = 0;
00093    }
00094 
00095 }
00096 
00097 //____________________________________________________________________________
00098 RawLiTpmtDigitsBlock& RawLiTpmtDigitsBlock::operator=(const RawLiTpmtDigitsBlock& rhs)
00099 {
00100    // deep copy assignment 
00101   if (this != &rhs) {
00102     RawDataBlock::operator=(rhs);
00103     if (fRawCrateStatus) { delete fRawCrateStatus; fRawCrateStatus = 0; }
00104     if (fRawDigits) { 
00105       fRawDigits->Delete(); 
00106       delete fRawDigits; 
00107       fRawDigits = 0;
00108     }
00109   }
00110   return *this;
00111 }
00112 
00113 //_____________________________________________________________________________
00114 std::ostream& RawLiTpmtDigitsBlock::FormatToOStream(std::ostream& os, 
00115                                                     Option_t *option) const
00116 {
00117    RawDataBlock::FormatToOStream(os,option);
00118    if (option[0] == 'X') return os;
00119    
00120    // additional block specific formatted output is done here
00121 
00122    os << " TimeStamp " << GetTimeStamp().AsString("c") << endl;
00123    os << " Run " << GetRun() 
00124       << " SubRun " << GetSubRun() 
00125       << " RunType " << GetRunType() 
00126       << " TimeFrame " << GetTimeFrameNum()
00127       << " with " << GetNumberOfDigits() << " digits "
00128       << endl; 
00129    os << " " << *GetCrateStatus() << endl;
00130 
00131    if (strchr(option,'q') != 0) return os;
00132 
00133    TIter iter = GetDatumIter();
00134    TObject *tobj;
00135    RawDigit *udigit;
00136    while ( ( tobj = iter.Next() ) ) {
00137      udigit = dynamic_cast<RawDigit *>(tobj);
00138      if (udigit) os << " " << (*udigit) << endl;
00139    }
00140    os << endl;
00141    return os;
00142 }
00143 
00144 //_____________________________________________________________________________
00145 Int_t RawLiTpmtDigitsBlock::GetRun() const
00146 {
00147    // get the run number
00148    if (fSize > indx_run) return fRawBlock[indx_run];
00149    return -1;
00150 }
00151 
00152 //_____________________________________________________________________________
00153 Short_t RawLiTpmtDigitsBlock::GetSubRun() const
00154 {
00155    // get the subrun number
00156    if (fSize > indx_subrun) return (fRawBlock[indx_subrun]>>16)&0xffff;
00157    return -1;
00158 }
00159 
00160 //_____________________________________________________________________________
00161 Short_t RawLiTpmtDigitsBlock::GetRunType() const
00162 {
00163    // get the run type
00164    if (fSize > indx_runtype) return fRawBlock[indx_runtype]&0xffff;
00165    return -1;
00166 }
00167 
00168 //_____________________________________________________________________________
00169 VldTimeStamp RawLiTpmtDigitsBlock::GetTimeStamp() const
00170 {
00171    // get the start time
00172    if (fSize >= zzzz_last) 
00173       return VldTimeStamp(fRawBlock[indx_loadsec],fRawBlock[indx_loadnsec]);
00174 
00175    return VldTimeStamp((time_t)0,(Int_t)0);
00176 }
00177 
00178 //_____________________________________________________________________________
00179 VldContext RawLiTpmtDigitsBlock::GetVldContext() const
00180 {
00181    // get a VldContext
00182 
00183    RawBlockId rbid = GetBlockId();
00184    return VldContext(rbid.GetDetector(),rbid.GetSimFlag(),GetTimeStamp());
00185 }
00186 
00187 //_____________________________________________________________________________
00188 Int_t RawLiTpmtDigitsBlock::GetTimeFrameNum() const
00189 {
00190    // get the time frame #
00191    int indx_tf_v = indx_tf;
00192    if (GetMinorId() <= 1) indx_tf_v = indx_tf_v1;
00193    if (fSize >= indx_tf_v) return fRawBlock[indx_tf_v];
00194    return -1;
00195 }
00196 
00197 //_____________________________________________________________________________
00198 const RawDigitCrateStatus* RawLiTpmtDigitsBlock::GetCrateStatus() const
00199 {
00200    // get the crate id --> status
00201    if ( ! fRawDigits ) FillRawDigits();
00202    return fRawCrateStatus;
00203 
00204 }
00205 
00206 //_____________________________________________________________________________
00207 Int_t RawLiTpmtDigitsBlock::GetNumberOfDigits() const
00208 {
00209    // get the number of digits
00210    if ( ! fRawDigits ) FillRawDigits();
00211    return fRawDigits->GetEntriesFast();  // known not to have gaps
00212 }
00213 
00214 //_____________________________________________________________________________
00215 const RawDigit* RawLiTpmtDigitsBlock::At(Int_t idx) const
00216 {
00217    // create/fill the TObjArray of RawDigits (if it doesn't exist)
00218    // return pointer to the i-th element
00219 
00220    if ( ! fRawDigits ) FillRawDigits();
00221    return (RawDigit*) fRawDigits->At(idx);
00222 }
00223 
00224 //_____________________________________________________________________________
00225 TIter RawLiTpmtDigitsBlock::GetDatumIter(Bool_t dir) const
00226 {
00227    // create/fill the TObjArray of RawDigits (if it doesn't exist)
00228    // return an iterator to look over them
00229 
00230    if ( ! fRawDigits ) FillRawDigits();
00231    return TIter(fRawDigits,dir);
00232 }
00233 
00234 //_____________________________________________________________________________
00235 Int_t RawLiTpmtDigitsBlock::IndexOf(RawDigit *rawdigit) const
00236 {
00237    // create/fill the TObjArray of RawDigits (if it doesn't exist)
00238    // return the index for this object (if contained in the list)
00239 
00240    if ( ! fRawDigits ) FillRawDigits();
00241    return fRawDigits->IndexOf(rawdigit);
00242 }
00243 
00244 //_____________________________________________________________________________
00245 void RawLiTpmtDigitsBlock::FillRawDigits() const
00246 {
00247    // create the TObjArray of RawDigit (if it doesn't exist)
00248    
00249    if ( fRawDigits ) return;   // already filled
00250    if ( fSize <= 0 || fRawBlock == 0) {
00251       MSG("RawData",Msg::kWarning)
00252          << "RawLiTpmtDigitsBlock::FillRawDigits empty block? "
00253          << fSize << " " << fRawBlock << endl;
00254       return;
00255    }
00256 
00257    fRawDigits          = new TObjArray();
00258    RawDigit  *rawdigit = 0;
00259    const Int_t    *p   = fRawBlock;
00260    const Int_t    *end = fRawBlock + fSize; // 1 beyond end
00261 
00262    int minorId = GetMinorId();
00263    RawBlockId rbid = GetBlockId();
00264    // skip #words, blockid and checksum, etc
00265    p += ( (minorId<=1) ? indx_crateid_v1 : indx_crateid ); 
00266 
00267    if (fgDebugFlags&dbg_DumpHeaderOnUnpack) {
00268       MSG("RawData",Msg::kInfo) 
00269          << "RawLiTpmtDigitsBlock::FillRawDigits "
00270          << " fSize " << fSize 
00271          << " id " << rbid.AsString()
00272          << endl;
00273    }
00274 
00275    // unpack crate info
00276    // version >1 has TF word between crateId and # of entries
00277    Bool_t skipTFword = ( minorId > 1 );  
00278    fRawCrateStatus = 
00279      new RawDigitCrateStatus(rbid,p,GetTimeStamp(),skipTFword);
00280    Int_t npairs = fRawCrateStatus->GetEntries(); 
00281    if (fgDebugFlags&dbg_DumpCrateOnUnpack) fRawCrateStatus->Print();
00282 
00283    while (p<end) {
00284 
00285       for (Int_t ipair = 0; ipair < npairs; ipair++) {
00286          // assume that the readout type is consistent for whole crate
00287          // and that the status block knows what it is
00288          ElecType::Elec_t etype = fRawCrateStatus->GetElecType();
00289 
00290          // pointer is advanced by RawDigit ctor
00291          // knowing how many words it needed to eat
00292          switch (rbid.GetSimFlag()) {
00293          case SimFlag::kData:
00294          case SimFlag::kDaqFakeData:
00295             switch (etype) {
00296             case ElecType::kVA:
00297                rawdigit = new RawVaDigit(p,fRawCrateStatus);
00298                break;
00299             case ElecType::kQIE:
00300                rawdigit = new RawQieDigit(p,fRawCrateStatus);
00301                break;
00302             default:
00303                rawdigit = new RawDigit(p,fRawCrateStatus);
00304                break;
00305             }
00306             break;
00307          case SimFlag::kMC:
00308          case SimFlag::kReroot:
00309             switch (etype) {
00310             case ElecType::kVA:
00311                rawdigit = new RawVaMCDigit(p,fRawCrateStatus);
00312                break;
00313             case ElecType::kQIE:
00314                rawdigit = new RawQieMCDigit(p,fRawCrateStatus);
00315                break;
00316             case ElecType::kReroot:
00317               {
00318                 if (rbid.GetDetector() == Detector::kNear) {
00319                   static int nmsg = 10;
00320                   if (nmsg) {
00321                     MSG("RawData",Msg::kWarning)
00322                       << "RawLiTpmtDigitsBlock::FillRawDigits SimFlag "
00323                       << SimFlag::AsString(rbid.GetSimFlag())
00324                       << " ElecType " << ElecType::AsString(etype)
00325                       << " in Detector " 
00326                       << Detector::AsString(rbid.GetDetector())
00327                       << endl
00328                       << " treat as kQIE for RawQieMCDigit creation"
00329                       << endl;
00330                     if (nmsg) {
00331                       if (--nmsg == 0)
00332                         MSG("RawData",Msg::kWarning)
00333                           << " ... last warning of this type" << endl;
00334                     }
00335                   }
00336                   rawdigit = new RawQieMCDigit(p,fRawCrateStatus);
00337                   break;
00338                 }
00339                 else 
00340                   MSG("RawData",Msg::kError) 
00341                     << "RawLiTpmtDigitsBlock::FillRawDigits SimFlag "
00342                     << SimFlag::AsString(rbid.GetSimFlag())
00343                     << " ElecType " << ElecType::AsString(etype)
00344                     << endl << "  attempt to move past problem " << endl;
00345                 p += 3;
00346                 break;
00347               }
00348             default:
00349                MSG("RawData",Msg::kError) 
00350                   << "RawLiTpmtDigitsBlock::FillRawDigits SimFlag "
00351                   << SimFlag::AsString(rbid.GetSimFlag())
00352                   << " ElecType " << ElecType::AsString(etype)
00353                   << endl << "  attempt to move past problem " << endl;
00354                p += 3;
00355                break;
00356             }
00357             break;
00358          case SimFlag::kUnknown:
00359                MSG("RawData",Msg::kError) 
00360                   << "RawLiTpmtDigitsBlock::FillRawDigits SimFlag "
00361                   << SimFlag::AsString(rbid.GetSimFlag())
00362                   << endl << "  attempt to move past problem " << endl;
00363                p += 2;
00364                break;
00365          }
00366 
00367          fRawDigits->Add(rawdigit);
00368 
00369          if (fgDebugFlags&dbg_DumpDigitOnUnpack) {
00370            rawdigit->Print(); cout << endl;
00371          }
00372          if (p>end) {
00373             MSG("RawData",Msg::kWarning)
00374                << "RawLiTpmtDigitsBlock::FillRawDigits crate info seems trashed"
00375                << endl << " SimFlag " << SimFlag::AsString(rbid.GetSimFlag())
00376                << " ElecType " << ElecType::AsString(etype)
00377                << endl;
00378             break;
00379          }
00380       }
00381    }
00382 
00383 }
00384 
00385 //_____________________________________________________________________________
00386 

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