00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include <cassert>
00012
00013 #include "Algorithm/AlgConfig.h"
00014 #include "Algorithm/AlgFactory.h"
00015 #include "Algorithm/AlgHandle.h"
00016 #include "CandData/CandRecord.h"
00017 #include "CandDigit/AlgCaldetDigitList.h"
00018 #include "CandDigit/CandDigit.h"
00019 #include "CandDigit/CandDigitHandle.h"
00020 #include "CandDigit/CandDigitList.h"
00021 #include "CandDigit/CandDigitListHandle.h"
00022 #include "Candidate/CandContext.h"
00023 #include "Conventions/Munits.h"
00024 #include "MessageService/MsgService.h"
00025 #include "Plex/PlexSEIdAltL.h"
00026 #include "Plex/PlexSEIdAltLItem.h"
00027 #include "RawData/RawDigit.h"
00028 #include "RawData/RawRecord.h"
00029 #include "RawData/RawDigitDataBlock.h"
00030 #include "Validity/VldContext.h"
00031 #include "Validity/VldTimeStamp.h"
00032 #include "Plex/PlexHandle.h"
00033 #include "RawData/RawHeader.h"
00034 #include "CaldetRawDigitWrapper.h"
00035 ClassImp(AlgCaldetDigitList)
00036
00037
00038 CVSID("$Id: AlgCaldetDigitList.cxx,v 1.1 2003/09/01 15:51:30 tagg Exp $");
00039
00040
00041 AlgCaldetDigitList::AlgCaldetDigitList()
00042 {
00043 }
00044
00045
00046 AlgCaldetDigitList::~AlgCaldetDigitList()
00047 {
00048 }
00049
00050
00051 void AlgCaldetDigitList::RunAlg(AlgConfig &ac, CandHandle &ch,
00052 CandContext &cx)
00053 {
00054 assert(cx.GetDataIn());
00055
00056
00057 const VldContext &vldc = *(cx.GetCandRecord()->GetVldContext());
00058
00059
00060 if (cx.GetDataIn()->InheritsFrom("RawRecord")) {
00061
00062 PlexHandle ph(vldc);
00063
00064
00065
00066
00067 AlgFactory &af = AlgFactory::GetInstance();
00068
00069
00070 const char *tmpcs = 0;
00071 const char *digitalgorithm = 0;
00072 const char *digitalgconfig = 0;
00073
00074 if (ac.Get("DigitAlgorithm", tmpcs)) digitalgorithm = tmpcs;
00075 if (ac.Get("DigitAlgConfig", tmpcs)) digitalgconfig = tmpcs;
00076
00077
00078 AlgHandle ah = af.GetAlgHandle(digitalgorithm, digitalgconfig);
00079
00080 CandContext cxx(this, cx.GetMom());
00081
00082
00083 cxx.SetCandRecord(cx.GetCandRecord());
00084
00085 Bool_t isSparse = true;
00086
00087
00088 RawRecord *rr = (RawRecord *) (cx.GetDataIn());
00089 TIter rdbit = rr->GetRawBlockIter();
00090 TObject *tob;
00091 while ((tob = rdbit())) {
00092 if (tob->InheritsFrom("RawDigitDataBlock")) {
00093 RawDigitDataBlock *rdb = (RawDigitDataBlock *) tob;
00094 TIter rdit = rdb->GetDatumIter();
00095 RawDigit *rd;
00096 Int_t rawdigitindex = -1;
00097
00098 Int_t ndigits = rdb->GetNumberOfDigits();
00099 Bool_t blkIsSparse =
00100 ( rdb->GetNumberOfCrates() == rdb->GetNSparsModeCrates());
00101 isSparse &= blkIsSparse;
00102 if (!blkIsSparse)
00103 MSG("AlgCaldetDigitList", Msg::kInfo)
00104 << "AlgCaldetDigitList finds RawDigitDataBlock is Unsparsified with "
00105 << ndigits << " digits " << endl << endl;
00106
00107
00108
00109 CaldetRawDigitWrapper wrapper;
00110
00111
00112 rdit.Reset();
00113 rawdigitindex = -1;
00114 while ((rd = (RawDigit *) rdit())) {
00115 ++rawdigitindex;
00116
00117 if (ph.GetReadoutType(rd->GetChannel()) == ReadoutType::kTimingFid) {
00118 wrapper.fFiducialDigit = rd;
00119 }
00120 }
00121
00122 if(wrapper.fFiducialDigit==0) {
00123 MSG("AlgCaldetDigitList",Msg::kInfo)
00124 << "Event has no fiducial digit." << endl;
00125 }
00126
00127
00128
00129 rdit.Reset();
00130 rawdigitindex = -1;
00131 while ((rd = (RawDigit *) rdit())) {
00132 ++rawdigitindex;
00133
00134
00135
00136
00137
00138 wrapper.fDigit = rd;
00139
00140 cxx.SetDataIn(&wrapper);
00141 CandDigitHandle cdh = CandDigit::MakeCandidate(ah, cxx);
00142 cdh.SetRawDigitIndex(rawdigitindex);
00143
00144 ch.AddDaughterLink(cdh, kFALSE);
00145 }
00146 }
00147 }
00148
00149
00150
00151 CandDigitListHandle &cdlh =
00152 dynamic_cast<CandDigitListHandle &>(ch);
00153 cdlh.SetAbsTime(((Double_t) vldc.GetTimeStamp().GetNanoSec()) *
00154 Munits::nanosecond);
00155
00156
00157 cdlh.SetIsSparse(isSparse);
00158 }
00159
00160 else if (cx.GetDataIn()->InheritsFrom("TCollection")) {
00161 TCollection *cdl = (TCollection *) cx.GetDataIn();
00162 TIter cdit(cdl);
00163 CandDigitHandle *cdh;
00164 while ((cdh = (CandDigitHandle *) cdit())) {
00165 ch.AddDaughterLink(*cdh, kFALSE);
00166 }
00167 }
00168 }
00169
00170
00171 void AlgCaldetDigitList::Trace(const char * ) const
00172 {
00173 }