00001 #include "dEmcDCMLongDataWrapper.h"
00002
00003
00004 #include "encodeString.h"
00005
00006
00007 #include "Event.h"
00008 #include "PHIODataNode.h"
00009
00010
00011
00012 #include "PHRawDataNode.h"
00013
00014
00015
00016 #include <iostream>
00017 using namespace std;
00018
00019 typedef PHDataNode<Event> EventNode_t;
00020 typedef PHIODataNode<PHTable> TableNode_t;
00021
00022 long
00023 EmcPutDCMLongReCal(PHCompositeNode* topNode)
00024 {
00025 PHNodeIterator iter(topNode), *j;
00026 PHCompositeNode* DCMNode;
00027 PHCompositeNode* prdfNode;
00028 PHNode *n1;
00029 TableNode_t *d;
00030
00031 static Int_t iCall = 0;
00032
00033
00034 n1 = iter.findFirst("PHCompositeNode", "DCM");
00035 if (!n1) {
00036 cout << "\n EmcPutDCM <E>: Unable to find DCM subnode, exiting \n\n" << endl;
00037 exit(1);
00038 }
00039 else {
00040 DCMNode = static_cast<PHCompositeNode*>(n1);
00041 }
00042
00043
00044 n1 = iter.findFirst("PHCompositeNode", "PRDFRECAL");
00045 if (!n1) {
00046 cout << "\n EmcPutDCMLongReCal <E>: Unable to find subnode PRDFRECAL, exiting \n\n" << endl;
00047 exit(1);
00048 }
00049 else {
00050 prdfNode = static_cast<PHCompositeNode*>(n1);
00051 }
00052
00053
00054 dEmcDCMLongDataWrapper *w;
00055 j = new PHNodeIterator(DCMNode);
00056 d = static_cast<TableNode_t*>(j->findFirst("PHIODataNode","dEmcDCMLongDataReCal"));
00057 if (!d) {
00058 cout << "\n EmcPutDCM <E>: Unable to find STAF Table dEmcDCMLongDataReCal, exiting \n\n" << endl;
00059 exit(1);
00060 }
00061 else {
00062 w = static_cast<dEmcDCMLongDataWrapper*>(d->getData());
00063 if (!w) {
00064 cout << "\n EmcPutDCMLong <E>: Unable to get pointer for wrapped table, exiting \n\n" << endl;
00065 exit(1);
00066 }
00067 }
00068 delete j;
00069
00070 TABLE_HEAD_ST fTableHeader = w->TableHeader();
00071 Int_t dcmRows = fTableHeader.nok;
00072 static Int_t dcmRowsLast = 0;
00073
00074 DEMCDCMLONGDATA_ST* dEmcDCMDataLong = w->TableData();
00075
00076 Int_t numberOfWords = dEmcDCMDataLong[0].nWords;
00077 Int_t dataID = dEmcDCMDataLong[0].packetID;
00078 Int_t bytesPerWord = 4;
00079 Int_t hitFormat = dEmcDCMDataLong[0].scheme;
00080
00081 if( dcmRows>1500 || numberOfWords>979 ) {
00082 cout << "\n EmcPutDCMLong <E>: dcmRows = " << dcmRows;
00083 cout << ", numberOfWords = " << numberOfWords << endl;
00084 cout << "; Limits are 1500 and 450; exiting" << endl;
00085 exit(1);
00086 }
00087
00088 static PHRawDataNode **rawDataArray;
00089 if(iCall == 0) {
00090 rawDataArray = new PHRawDataNode *[1500];
00091 for(Int_t iRow=0; iRow<1500; iRow++) {
00092 rawDataArray[iRow] = 0;
00093 }
00094 }
00095 iCall++;
00096
00097 char emcPRDF[11] = "emcPRDF000";
00098
00099 for (Int_t iRow=0; iRow<dcmRows; iRow++){
00100 numberOfWords = dEmcDCMDataLong[iRow].nWords;
00101 encodeString(emcPRDF, iRow);
00102 dataID = dEmcDCMDataLong[iRow].packetID;
00103 hitFormat = dEmcDCMDataLong[iRow].scheme;
00104
00105 DWORD *dPtr = (DWORD*)&dEmcDCMDataLong[iRow].DCM[0];
00106 if(rawDataArray[iRow] == 0) {
00107 rawDataArray[iRow] = new PHRawDataNode(dPtr, emcPRDF, numberOfWords, dataID, bytesPerWord, hitFormat);
00108 prdfNode->addNode(rawDataArray[iRow]);
00109 }
00110 else {
00111 PHRawDataNode *rPtr = rawDataArray[iRow];
00112 rPtr->setData(dPtr);
00113 rPtr->setLength(numberOfWords);
00114 rPtr->setID(dataID);
00115 rPtr->setWordLength(bytesPerWord);
00116 rPtr->setHitFormat(hitFormat);
00117 }
00118
00119 }
00120
00121 if(iCall > 1 && dcmRows < dcmRowsLast){
00122 for(Int_t iRow=dcmRows; iRow<dcmRowsLast; iRow++) {
00123 PHRawDataNode *rPtr = rawDataArray[iRow];
00124 rPtr->setLength(0);
00125 rPtr->setID(0);
00126 }
00127 }
00128
00129 dcmRowsLast = dcmRows;
00130 return 0;
00131 }
00132