00001 #include <iomanip>
00002 #include <iostream>
00003
00004 #include "PHNode.h"
00005 #include "PHCompositeNode.h"
00006 #include "PHDataNode.h"
00007 #include "PHIODataNode.h"
00008
00009 #include "TMuiAddressTable.hh"
00010 #include "mMuiRawUnpack.h"
00011
00012
00013 #include <MUIOO.h>
00014 #include <TMutNode.h>
00015 #include <TMuiHitMapO.h>
00016
00017 using namespace std;
00018
00019 mMuiRawUnpack::mMuiRawUnpack():
00020 _timer( PHTimeServer::get()->insert_new( "mMuiRawUnpack" ) )
00021 {}
00022
00023 mMuiRawUnpack::~mMuiRawUnpack(){}
00024
00025
00026 PHBoolean
00027 mMuiRawUnpack::event(PHCompositeNode* baseNode)
00028 {
00029
00030 _timer.get()->restart();
00031
00032 Event* evt = 0;
00033
00034
00035 try{
00036 evt = TMutNode<Event>::find_node(baseNode,"PRDF");
00037 } catch(std::exception& e){
00038 MUIOO::TRACE(e.what());
00039 return False;
00040 }
00041 PHBoolean out = event(evt, baseNode);
00042 _timer.get()->stop();
00043
00044 return out;
00045 }
00046
00047 PHBoolean
00048 mMuiRawUnpack::event(Event* evt, PHCompositeNode* baseNode)
00049 {
00050 if(evt == 0)
00051 {
00052 cout<<PHWHERE<<" Null event pointer.\n";
00053 return False;
00054 }
00055
00056
00057 _mod_par = TMutNode<mMuiRawUnpackPar>::find_node(baseNode,"mMuiRawUnpackPar");
00058
00059
00060 TMuiHitMapO* _muihitmap = 0;
00061 try{
00062 _muihitmap = TMutNode<TMuiHitMapO>::find_node(baseNode,"TMuiHitMapO");
00063 } catch(std::exception& e){
00064 MUIOO::TRACE(e.what());
00065 return False;
00066 }
00067
00068 TMuiAddressTable* pAddress = TMuiAddressTable::Table();
00069 if (!pAddress) return False;
00070
00071 int packetdata[MUIOO::kWordsPerFEM]={0};
00072
00073 unsigned int row = 0;
00074
00075
00076
00077
00078
00079
00080 for (int dcm=0; dcm<MUIOO::kFEMsTotal; dcm++) {
00081
00082 unsigned int packetid = _mod_par->get_id_base() + dcm;
00083 Packet* muipacket = evt->getPacket(packetid);
00084 int numwords = 0;
00085
00086
00087 if(muipacket<=0) continue;
00088
00089 TMuiReadoutID idHard;
00090 TMuiChannelId idSoft;
00091
00092 unsigned int moduleID = _mod_par->get_module_id(dcm);
00093
00094 short Arm = pAddress->Arm(moduleID);
00095 short orient = pAddress->Orient(moduleID);
00096
00097 muipacket->fillIntArray(packetdata,
00098 MUIOO::kWordsPerFEM,
00099 &numwords,
00100 "SPARSE");
00101 delete muipacket;
00102
00103
00104 if (numwords > MUIOO::kWordsPerFEM) {
00105 cout << PHWHERE << packetid
00106 << " has " << numwords
00107 << " words, maximum allowed is " << MUIOO::kWordsPerFEM << endl;
00108 continue;
00109 }
00110
00111 for (unsigned int j=0; j<(unsigned int)numwords; j++) {
00112 unsigned int pattern = packetdata[j];
00113
00114 short roc = getbits(pattern,30,7);
00115 short word = getbits(pattern,23,4);
00116
00117 if ( (roc < 0) || (roc >= TMuiReadoutID::kROCsPerFEM)
00118 || (word < 0) || (word >= TMuiReadoutID::kWordsPerROC) ) {
00119 cout << "mMuiDCMUnpack-E1 ROC id " << roc
00120 << " or word-in-ROC id " << word << " out of range" << endl;
00121 }
00122 else {
00123
00124 for (short bit=0; bit<16; bit++) {
00125 if (getbits(pattern,bit,1) == 1) {
00126 idHard.Set(moduleID,roc,word,bit);
00127 idSoft = pAddress->SoftwareAddress(idHard);
00128
00129 if ( (idSoft.Arm() != Arm) || (idSoft.Orient() != orient) ) {
00130 cout << "mMuiDCMUnpack-E3 DCM arm, orient = "
00131 << Arm << " " << orient
00132 << " Lookup arm, orient = "
00133 << idSoft.Arm() << " " << idSoft.Orient() << endl;
00134 }
00135 else {
00136 #ifdef MUIOO_DEBUG
00137 TMuiHitMapO::iterator hitIter =
00138 #endif
00139 _muihitmap->insert_new(
00140 idSoft.Arm(),
00141 idSoft.Plane(),
00142 idSoft.Panel(),
00143 idSoft.Orient(),
00144 idSoft.TwoPack()
00145 );
00146 #ifdef MUIOO_DEBUG
00147 hitIter->get()->print();
00148 #endif
00149
00150 row++;
00151 }
00152 }
00153
00154 }
00155 }
00156 }
00157 }
00158
00159 return True;
00160 }
00161
00162 unsigned int mMuiRawUnpack::getbits(unsigned int word, int start, int length){
00163 return (word >> (start+1-length)) & ~(~0 << length);
00164 }