00001 #include "mEmcCalibratorModulev1.h"
00002
00003 #include "emcDataProcessorv2.h"
00004 #include "emcTowerContainer.h"
00005 #include "emcTowerContent.h"
00006 #include "emcNodeHelper.h"
00007 #include "emcBadModulesv1.h"
00008 #include "emcDataError.h"
00009
00010 #include "PHNodeIterator.h"
00011 #include "PHDataNode.h"
00012 #include "PHCompositeNode.h"
00013 #include "PHTimeStamp.h"
00014 #include "Event.h"
00015
00016 #include <memory>
00017 #include <cassert>
00018
00019 using namespace std;
00020
00021
00022 namespace
00023 {
00024 Event* getEvent(PHCompositeNode* topNode)
00025 {
00026 PHNodeIterator it(topNode);
00027 PHDataNode<Event>* eventNode =
00028 static_cast<PHDataNode<Event>*>(it.findFirst("PHDataNode","PRDF"));
00029 if (eventNode)
00030 {
00031 return eventNode->getData();
00032 }
00033 return 0;
00034 }
00035 }
00036
00037
00038 mEmcCalibratorModulev1::mEmcCalibratorModulev1(int runnumber,
00039 const PHTimeStamp& ts,
00040 bool constantGains,
00041 emcManageable::EStorage source,
00042 const char* sectors)
00043 {
00044 name = "mEmcCalibratorModulev1";
00045 fSectors = sectors;
00046 fDataProcessor = new emcDataProcessorv2(runnumber,ts,true,
00047 source,fSectors.c_str());
00048 fTimeStamp = new PHTimeStamp(ts);
00049 fBadModules = new emcBadModulesv1(*fTimeStamp,
00050 emcBadModules::kAll,
00051 source,
00052 true,
00053 fSectors.c_str());
00054 fConstantGains = constantGains;
00055 fRunNumber = runnumber;
00056 }
00057
00058
00059 mEmcCalibratorModulev1::~mEmcCalibratorModulev1()
00060 {
00061 delete fDataProcessor;
00062 delete fTimeStamp;
00063 delete fBadModules;
00064 }
00065
00066
00067 PHBoolean
00068 mEmcCalibratorModulev1::event(PHCompositeNode* topNode)
00069 {
00070 Event* event = getEvent(topNode);
00071
00072 if ( !event )
00073 {
00074 cerr << name << "::event : cannot get Event node/object" << endl;
00075 return false;
00076 }
00077
00078 emcTowerContainer* tc = emcNodeHelper::getObject<emcTowerContainer>
00079 ("emcTowerContainer",topNode);
00080
00081 tc->Reset();
00082
00083 auto_ptr<emcTowerContainer> pbsc(tc->clone());
00084 auto_ptr<emcTowerContainer> pbgl(tc->clone());
00085
00086 bool ok = fDataProcessor->decode(*event,pbsc.get(),pbgl.get());
00087
00088 if ( !fBadModules)
00089 {
00090 fBadModules = new emcBadModulesv1(*fTimeStamp);
00091 }
00092
00093 if (ok)
00094 {
00095 ok = fDataProcessor->toADCandTDC(pbsc.get(),pbgl.get(),*fBadModules);
00096 }
00097
00098 if (ok)
00099 {
00100 time_t thetime;
00101 if ( fConstantGains )
00102 {
00103 thetime = fTimeStamp->getTics();
00104 }
00105 else
00106 {
00107
00108 thetime = event->getTime();
00109 }
00110 ok = fDataProcessor->calibrate(pbsc.get(),pbgl.get(),thetime);
00111 }
00112
00113 if (ok)
00114 {
00115
00116 int out=0;
00117 for ( size_t i = 0; i < pbsc->size(); ++i )
00118 {
00119 emcTowerContent* tin = pbsc->getTower(i);
00120 if ( tin->ADC() > 10 &&
00121 !(tin->DataError() & emcDataError::CHANNEL_DISABLED()) )
00122 {
00123 emcTowerContent* tout = tc->addTower(out,*tin);
00124 assert(tout!=0);
00125 ++out;
00126 }
00127 }
00128
00129 for ( size_t i = 0; i < pbgl->size(); ++i )
00130 {
00131 emcTowerContent* tin = pbgl->getTower(i);
00132 if ( tin->ADC() > 10 &&
00133 !(tin->DataError() & emcDataError::CHANNEL_DISABLED()) )
00134 {
00135 emcTowerContent* tout = tc->addTower(out,*tin);
00136 assert(tout!=0);
00137 ++out;
00138 }
00139 }
00140 return true;
00141 }
00142 else
00143 {
00144 tc->Reset();
00145 return false;
00146 }
00147 }