00001
00002 #include "dEmcDCMDataWrapper.h"
00003
00004 #include "PHIODataNode.h"
00005
00006
00007 #include "Event.h"
00008
00009
00010
00011 #include <iostream>
00012
00013 using namespace std;
00014
00015 typedef PHDataNode<Event> EventNode_t;
00016 typedef PHIODataNode<PHTable> TableNode_t;
00017
00018 long
00019 EmcGetDCM(PHCompositeNode* topNode)
00020 {
00021 PHNodeIterator iter(topNode), *j;
00022 PHCompositeNode* dcmNode;
00023 PHNode *n1,*n2;
00024 TableNode_t *d;
00025
00026
00027 n1 = iter.findFirst("PHDataNode", "PRDF");
00028 if (!n1) {
00029 return 1;
00030 }
00031
00032
00033 n2 = iter.findFirst("PHCompositeNode", "DCM");
00034 if (!n2) {
00035 dcmNode = new PHCompositeNode("DCM");
00036 topNode->addNode(dcmNode);
00037 }
00038 else {
00039 dcmNode = static_cast<PHCompositeNode*>(n2);
00040 }
00041
00042
00043 EventNode_t* node = static_cast<EventNode_t*>(n1);
00044 Event* event = node->getData();
00045 if (!event) {
00046 return 1;
00047 }
00048
00049
00050
00051 dEmcDCMDataWrapper* w;
00052 j = new PHNodeIterator(dcmNode);
00053 d = static_cast<TableNode_t*>(j->findFirst("PHIODataNode","dEmcDCMData"));
00054 if (!d) {
00055 w = new dEmcDCMDataWrapper("dEmcDCMData", 500);
00056 if (!w) {
00057 return 1;
00058 }
00059 d = new TableNode_t(w,"dEmcDCMData");
00060 dcmNode->addNode(d);
00061 }
00062 else {
00063 w = static_cast<dEmcDCMDataWrapper*>(d->getData());
00064 if (!w) {
00065 return 1;
00066 }
00067 }
00068 delete j;
00069
00070 DEMCDCMDATA_ST* dEmcDCMData = w->TableData();
00071
00072
00073
00074 Packet* p;
00075 static const int id_base = 8001;
00076 static const int max_packets = 192;
00077 static const int length = 450;
00078 int id, words;
00079 long i = 0;
00080
00081 for (int k = 0; k < max_packets; k++) {
00082 id = id_base + k;
00083
00084 if ( (p = event->getPacket(id)) != 0) {
00085
00086 int status
00087 = p->fillIntArray(
00088 (int *) &dEmcDCMData[i].DCM[0],
00089 length,
00090 &words,
00091 "DATA");
00092
00093 if (status != 0) {
00094 cout << "EmcGetDCM-E1 fillIntArray status = " << status << endl;
00095 delete p;
00096 return 1;
00097 }
00098
00099 dEmcDCMData[i].nWords = words;
00100 dEmcDCMData[i].packetID = id;
00101 dEmcDCMData[i].scheme = p->getHitFormat();
00102
00103 delete p;
00104
00105 i++;
00106 }
00107 }
00108 w->SetRowCount(i);
00109
00110 return 0;
00111 }