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

RawTOFBlock.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RawTOFBlock.cxx,v 1.9 2004/09/02 21:47:34 rhatcher Exp $
00003 // 
00004 // RawTOFBlock 
00005 // 
00006 // RawTOFBlock 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/RawTOFBlock.h"
00014 
00015 enum EDebugDigitDataBlock {
00016    dbg_DumpHeaderOnUnpack = 0x0001,
00017    dbg_DumpCrateOnUnpack  = 0x0002,
00018    dbg_DumpDigitOnUnpack  = 0x0004
00019 };
00020 
00021 UInt_t RawTOFBlock::fgDebugFlags = 0;
00022 //  dbg_DumpCrateOnUnpack | dbg_DumpDigitOnUnpack;
00023 
00024 #include "RawData/RawTOFDigit.h"
00025 
00026 #include "MessageService/MsgStream.h"
00027 #include "MessageService/MsgService.h"
00028 CVSID("$Id: RawTOFBlock.cxx,v 1.9 2004/09/02 21:47:34 rhatcher Exp $");
00029 
00030 #include "RawData/RawBlockRegistry.h"
00031 REGISTERRAWBLOCK(RawTOFBlock,kMdBlockTofReadout,0);
00032 
00033 ClassImp(RawTOFBlock)
00034 
00035 //_____________________________________________________________________________
00036 RawTOFBlock::RawTOFBlock() :
00037    fRawCrateStatuses(0), fRawTOFDigits(0)
00038 {
00039    // Default constructor
00040 }
00041 
00042 //_____________________________________________________________________________
00043 RawTOFBlock::RawTOFBlock(const Int_t *block)
00044    : RawDataBlock(block), 
00045      fRawCrateStatuses(0), fRawTOFDigits(0)
00046 {
00047    //  stored block format is:
00048    //---------------------
00049    //  0   # words in block
00050    //  1   checksum
00051    //  2   Block Id
00052    //-----
00053    //  3   Crate # i (+extra)
00054    //  4   # of crate entries (N_i)
00055    //  5   Crate T0_i sec
00056    //  6   Crate T0_i nsec
00057    //-----
00058    //  7   readout 1_i word 1
00059    //  8   readout 1_i word 2
00060    //      < truth PlexStripEndId if Reroot data>
00061    //      tdc header (inc count)
00062    //      tdc data word 0
00063    //      ...
00064    //      tdc trailer
00065    //      readout 2_i word 1
00066    //      readout 2_i word 2
00067    //      ...
00068 
00069 }
00070 
00071 //_____________________________________________________________________________
00072 RawTOFBlock::~RawTOFBlock()
00073 {
00074    if (fRawTOFDigits) {
00075       fRawTOFDigits->Delete();
00076       delete fRawTOFDigits;
00077       fRawTOFDigits = 0;
00078    }
00079    if (fRawCrateStatuses) {
00080       fRawCrateStatuses->Delete();
00081       delete fRawCrateStatuses;
00082       fRawCrateStatuses = 0;
00083    }
00084    return;
00085 }
00086 
00087 //_____________________________________________________________________________
00088 RawTOFBlock& RawTOFBlock::operator=(const RawTOFBlock& rhs)
00089 {
00090    // deep copy assignment
00091    if (this != &rhs) {
00092      RawDataBlock::operator=(rhs);
00093      if (fRawTOFDigits) {
00094        fRawTOFDigits->Delete();
00095        delete fRawTOFDigits;
00096        fRawTOFDigits = 0;
00097      }
00098      if (fRawCrateStatuses) {
00099        fRawCrateStatuses->Delete();
00100        delete fRawCrateStatuses;
00101        fRawCrateStatuses = 0;
00102      }
00103    }
00104    return *this;
00105 }
00106 
00107 //_____________________________________________________________________________
00108 Int_t RawTOFBlock::GetNumberOfDigits() const
00109 {
00110    // create/fill the TObjArray of RawTOFDigit (if it doesn't exist)
00111    // return number of entries
00112    
00113    if ( ! fRawTOFDigits ) FillRawTOFDigits();
00114    return fRawTOFDigits->GetEntriesFast(); // known not to have gaps
00115 }
00116 
00117 //_____________________________________________________________________________
00118 const RawTOFDigit* RawTOFBlock::At(Int_t idx) const
00119 {
00120    // create/fill the TObjArray of RawTOFDigit (if it doesn't exist)
00121    // return pointer to the i-th element
00122    
00123    if ( ! fRawTOFDigits ) FillRawTOFDigits();
00124    return (RawTOFDigit*) fRawTOFDigits->At(idx);
00125 }
00126 
00127 //_____________________________________________________________________________
00128 TIter RawTOFBlock::GetDatumIter(Bool_t dir) const
00129 {
00130    // create/fill the TObjArray of RawTOFDigit (if it doesn't exist)
00131    // return an iterator to look over them
00132    
00133    if ( ! fRawTOFDigits ) FillRawTOFDigits();
00134    return TIter(fRawTOFDigits,dir);
00135 }
00136 
00137 //_____________________________________________________________________________
00138 Int_t RawTOFBlock::IndexOf(RawTOFDigit *rawdigit) const
00139 {
00140    // create/fill the TObjArray of RawTOFDigit (if it doesn't exist)
00141    // return the index for this object (if contained in the list)
00142 
00143    if ( ! fRawTOFDigits ) FillRawTOFDigits();
00144    return fRawTOFDigits->IndexOf(rawdigit);
00145 }
00146 
00147 //_____________________________________________________________________________
00148 void RawTOFBlock::FillRawTOFDigits() const
00149 {
00150    // create the TObjArray of RawTOFDigit (if it doesn't exist)
00151    
00152    if ( fRawTOFDigits ) return;   // already filled
00153    if ( fSize <= 0 || fRawBlock == 0) {
00154       MSG("RawData",Msg::kWarning)
00155          << "RawTOFBlock::FillRawTOFDigits empty block? "
00156          << fSize << " " << fRawBlock << endl;
00157       return;
00158    }
00159 
00160    fRawCrateStatuses = new TObjArray();
00161    fRawTOFDigits     = new TObjArray();
00162    RawDigitCrateStatus *cratestatus = 0;
00163    RawTOFDigit         *rawdigit    = 0;
00164    const Int_t    *p   = fRawBlock;
00165    const Int_t    *end = fRawBlock + fSize; // 1 beyond end
00166 
00167    RawBlockId rbid = GetBlockId();
00168    p += 3; // skip #words, blockid and checksum
00169 
00170    if (fgDebugFlags&dbg_DumpHeaderOnUnpack) {
00171       MSG("RawData",Msg::kInfo) 
00172          << "RawTOFBlock::FillRawTOFDigits "
00173          << " fSize " << fSize 
00174          << " id " << rbid.AsString()
00175          << endl;
00176    }
00177 
00178    while (p<end) {
00179       // start a new crate (pointer advanced by RawCrateStatus ctor
00180       cratestatus = new RawDigitCrateStatus(rbid,p);
00181       fRawCrateStatuses->Add(cratestatus);
00182       Int_t npairs = cratestatus->GetEntries(); 
00183 
00184       if (fgDebugFlags&dbg_DumpCrateOnUnpack) cratestatus->Print();
00185 
00186       for (Int_t ipair = 0; ipair < npairs; ipair++) {
00187          // assume that the readout type is consistent for whole crate
00188          // and that the status block knows what it is
00189          ElecType::Elec_t etype = cratestatus->GetElecType();
00190 
00191          // pointer is advanced by RawTOFDigit ctor
00192          // knowing how many words it needed to eat
00193          switch (rbid.GetSimFlag()) {
00194          case SimFlag::kData:
00195          case SimFlag::kDaqFakeData:
00196             rawdigit = new RawTOFDigit(p,cratestatus);
00197             break;
00198          case SimFlag::kMC:
00199          case SimFlag::kReroot:
00200             rawdigit = new RawTOFDigit(p,cratestatus);
00201             break;
00202          default:
00203             MSG("RawData",Msg::kWarning)
00204                << "RawTOFBlock::FillRawTOFDigits simflag was: \""
00205                << SimFlag::AsString(rbid.GetSimFlag()) << "\" ("
00206                << (int)rbid.GetSimFlag() << ")" << endl;
00207             break;
00208          }
00209 
00210          fRawTOFDigits->Add(rawdigit);
00211 
00212          if (fgDebugFlags&dbg_DumpDigitOnUnpack) rawdigit->Print();
00213          if (p>end) {
00214             MSG("RawData",Msg::kWarning)
00215                << "RawTOFBlock::FillRawTOFDigits crate info seems trashed"
00216                << endl << " SimFlag " << SimFlag::AsString(rbid.GetSimFlag())
00217                << " ElecType " << ElecType::AsString(etype)
00218                << endl;
00219             break;
00220          }
00221       }
00222    }
00223 
00224 }
00225 
00226 //_____________________________________________________________________________
00227 std::ostream& RawTOFBlock::FormatToOStream(std::ostream& os, 
00228                                            Option_t *option) const
00229 {
00230    RawDataBlock::FormatToOStream(os,option);
00231    if (option[0] == 'X') return os;
00232    
00233    // additional block specific formatted output is done here
00234 
00235    const RawDigitCrateStatus *lastcrate = 0;
00236 
00237    TIter iter = GetDatumIter();
00238    TObject *tobj;
00239    RawTOFDigit *udigit;
00240    while ( ( tobj = iter.Next() ) ) {
00241       udigit = dynamic_cast<RawTOFDigit *>(tobj);
00242       if (udigit->GetCrateStatus() != lastcrate) {
00243          lastcrate = udigit->GetCrateStatus();
00244          os << " " << *lastcrate << endl;
00245       }
00246       if (udigit)  os << (*udigit);
00247    }
00248    os << endl;
00249    return os;
00250 }
00251 
00252 //_____________________________________________________________________________

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