00001 #include "PulserTimeDrift.h"
00002
00003 #include "DatabaseInterface/DbiResultSet.h"
00004 #include "MessageService/MsgService.h"
00005 #include <cassert>
00006 #include <math.h>
00007
00008 ClassImp(PulserTimeDrift)
00009 CVSID("$Id: PulserTimeDrift.cxx,v 1.10 2007/03/01 17:06:40 rhatcher Exp $");
00010
00011 #include "DatabaseInterface/DbiResultPtr.tpl"
00012 template class DbiResultPtr<PulserTimeDrift>;
00013
00014 #include "DatabaseInterface/DbiWriter.tpl"
00015 template class DbiWriter<PulserTimeDrift>;
00016
00017
00018
00019
00021
00023 PulserTimeDrift::PulserTimeDrift(
00024 Int_t aggregate,
00025 Int_t index,
00026 Float_t entries,
00027 Float_t mean,
00028 Float_t rms) :
00029 fAggregate(aggregate),
00030 fChannelIndex(index),
00031 fEntries(entries),
00032 fMean(mean),
00033 fRms(rms)
00034 {
00035 LEA_CTOR;
00036 }
00037
00039
00041 Int_t PulserTimeDrift::GetIndex(const RawChannelId& rcid)
00042 {
00043 if(rcid.GetDetector()==Detector::kFar) {
00044 Int_t index = rcid.GetCrate()*108
00045 + rcid.GetVarcId()*36
00046 + rcid.GetVmm()*6
00047 + rcid.GetVaAdcSel()*3
00048 + rcid.GetVaChip();
00049 return index;
00050 } else if(rcid.IsNull()) {
00051 return -1;
00052 } else {
00053
00054 assert(0);
00055 }
00056 return -1;
00057 }
00058
00059 RawChannelId PulserTimeDrift::GetRawChannelId(Int_t index)
00060 {
00061 Int_t temp = index;
00062 Int_t crate = index/108;
00063 temp -= crate*108;
00064 Int_t varc = temp/36;
00065 temp -= varc*36;
00066 Int_t vmm = temp/6;
00067 temp -= vmm*6;
00068 Int_t vaadc = temp/3;
00069 temp -= vaadc*3;
00070 Int_t vachip = temp;
00071
00072 return RawChannelId(Detector::kFar,
00073 ElecType::kVA,
00074 crate,
00075 varc,
00076 vmm,
00077 vaadc,
00078 vachip,
00079 0
00080 );
00081 }
00082
00084
00086 void PulserTimeDrift::Add( Float_t ent, Float_t mean, Float_t rms )
00087 {
00092
00093
00094 double newEntries = fEntries + ent;
00095 double newMean = (fMean*fEntries + ent*mean)/newEntries;
00096
00097 double oldx2 = (fRms*fRms + fMean*fMean)*fEntries;
00098 double addx2 = (rms*rms + mean*mean)*ent;
00099 double newx2 = oldx2 + addx2;
00100 double newRms = sqrt(fabs(newx2/newEntries - newMean*newMean));
00101
00102 fEntries = newEntries;
00103 fMean = newMean;
00104 fRms = newRms;
00105 }
00106
00107
00109
00111 void PulserTimeDrift::Fill(DbiResultSet& rs,
00112 const DbiValidityRec* ) {
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 if ( rs.TableName() == "PULSERTIMEDRIFT" ) {
00124
00125 rs >> fAggregate >> fChannelIndex >> fEntries >> fMean >> fRms;
00126 }
00127 else {
00128
00129 Int_t numCol = rs.NumCols();
00130
00131 for (Int_t curCol = rs.HasRowCounter() ? 3 : 2; curCol <= numCol; ++curCol) {
00132 string colName = rs.CurColName();
00133 if ( colName == "AGGREGATENO" ) rs >> fAggregate;
00134 else if( colName == "CHANNELINDEX" ) rs >> fChannelIndex;
00135 else if( colName == "ENTRIES" ) rs >> fEntries;
00136 else if( colName == "MEAN" ) rs >> fMean;
00137 else if( colName == "RMS" ) rs >> fRms;
00138 else {
00139 MSG("Dbi",Msg::kDebug) << "Ignoring column " << curCol
00140 << "(" << colName << ")"
00141 << "; not part of PulserTimeDrift"
00142 << endl;
00143 rs.IncrementCurCol();
00144 }
00145 }
00146 }
00147
00148 }
00149
00150
00151 void PulserTimeDrift::Store(DbiOutRowStream& ors,
00152 const DbiValidityRec* ) const
00153 {
00154
00155
00156
00157
00158
00159 ors << fAggregate << fChannelIndex << fEntries << fMean << fRms;
00160 }
00161