emcOFTowerContainer.C

Go to the documentation of this file.
00001 #include "emcOFTowerContainer.h"
00002 #include "dEmcCalibTowerWrapper.h"
00003 #include "PHTypedNodeIterator.h"
00004 #include "PHIODataNode.h"
00005 #include "emcTowerContainerv1.h"
00006 #include <cassert>
00007 #include <cmath>
00008 #include "EmcIndexer.h"
00009 
00010 namespace
00011 {
00012   template<class T>
00013   T*
00014   objectHandle(PHCompositeNode* node, const char* name)
00015   {
00016     PHTypedNodeIterator<T> iter(node);
00017     PHIODataNode<T>* objectNode = iter.find(name);
00018     if (!objectNode) 
00019       {
00020         return 0;
00021       }
00022     else
00023       {
00024         T* rv = objectNode->getData();
00025         return rv;
00026       }
00027   }
00028 
00029   emcOFTowerContainer gemcOFTowerContainer;
00030 }
00031 
00032 using namespace std;
00033 
00034 //_____________________________________________________________________________
00035 emcOFTowerContainer::emcOFTowerContainer() : emcObjectFiller()
00036 {
00037 }
00038 
00039 //_____________________________________________________________________________
00040 emcOFTowerContainer::~emcOFTowerContainer()
00041 {
00042 }
00043 
00044 //_____________________________________________________________________________
00045 bool 
00046 emcOFTowerContainer::canFill(PHObject& destination, int verbose) const
00047 {
00048   emcTowerContainerv1* tc = 
00049     dynamic_cast<emcTowerContainerv1*>(&destination);
00050   if ( tc ) 
00051     {
00052       return true;
00053     }
00054   else
00055     {
00056       if ( verbose ) 
00057         {
00058           std::cerr << "emcOFTowerContainer::canFill : destination "
00059                     << "is not an emcTowerContainerv1" << std::endl;
00060         }
00061       return false;
00062     } 
00063 }
00064 
00065 //_____________________________________________________________________________
00066 bool 
00067 emcOFTowerContainer::canFill(PHCompositeNode* topNode, 
00068                              PHObject& destination,
00069                              int verbose) const
00070 {
00071   bool rv = canFill(destination);
00072   if ( rv ) 
00073     {
00074       dEmcCalibTowerWrapper* ct = objectHandle<dEmcCalibTowerWrapper>
00075         (topNode,"dEmcCalibTower");
00076       if ( ct ) 
00077         {
00078           rv = true;
00079         }
00080       else
00081         {
00082           rv = false;
00083         }
00084     }
00085   return rv;
00086 }
00087 
00088 //_____________________________________________________________________________
00089 bool 
00090 emcOFTowerContainer::fill(PHCompositeNode* topNode, 
00091                           PHObject& destination,
00092                           int verbose)
00093 {
00094   assert(canFill(topNode,destination,false)==true);
00095   dEmcCalibTowerWrapper* ct = objectHandle<dEmcCalibTowerWrapper>
00096     (topNode,"dEmcCalibTower");
00097   emcTowerContainerv1& tc = static_cast<emcTowerContainerv1&>(destination);
00098 
00099   size_t ntowers = ct->RowCount();
00100 
00101   tc.Reset();
00102 
00103   for ( size_t i = 0; i < ntowers; ++i ) 
00104     {
00105       emcTowerContent* t = tc.addTower(i);
00106 
00107       int towerID = EmcIndexer::TowerID(ct->get_swkey(i));
00108       int ifem, ichannel;
00109       EmcIndexer::PXPXSM144CH(towerID,ifem,ichannel);
00110       t->SetID(ifem,ichannel);
00111 
00112       t->SetCalibrated(ct->get_ecal(i),ct->get_tof(i));
00113       t->SetNeighbours(ct->get_deadmap(i),ct->get_warnmap(i));
00114       t->SetADCTDC(static_cast<int>(rint(ct->get_adc(i))),
00115                    static_cast<int>(rint(ct->get_tac(i))));
00116     }
00117   return true;
00118 }
00119   
00120 //_____________________________________________________________________________
00121 void 
00122 emcOFTowerContainer::identify(std::ostream& os) const
00123 {
00124   os << "emcOFTowerContainer" << std::endl;
00125 }
00126 
00127 //_____________________________________________________________________________
00128 int 
00129 emcOFTowerContainer::isValid() const
00130 {
00131   return 1;
00132 }
00133 
00134 //_____________________________________________________________________________
00135 void 
00136 emcOFTowerContainer::Reset()
00137 {
00138 }