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 EmcPutDCMLong(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", "SIMPRDF");
00045 static int iWarn = 1;
00046 if(!n1) {
00047 if(iWarn) {
00048 cout << "\n EmcPutDCMLong <E>: Unable to find SIMPRDF subnode, trying PRDF name from Run2 PRECO usage \n\n" << endl;
00049 iWarn = 0;
00050 }
00051 n1 = iter.findFirst("PHCompositeNode", "PRDF");
00052 }
00053 if (!n1) {
00054 cout << "\n EmcPutDCMLong <E>: Unable to find SIMPRDF or PRDF subnode, exiting \n\n" << endl;
00055 exit(1);
00056 }
00057 else {
00058 prdfNode = static_cast<PHCompositeNode*>(n1);
00059 }
00060
00061
00062 dEmcDCMLongDataWrapper *w;
00063 j = new PHNodeIterator(DCMNode);
00064 d = static_cast<TableNode_t*>(j->findFirst("PHIODataNode","dEmcDCMLongData"));
00065 if (!d) {
00066 cout << "\n EmcPutDCM <E>: Unable to find STAF Table dEmcDCMDataLong, exiting \n\n" << endl;
00067 exit(1);
00068 }
00069 else {
00070 w = static_cast<dEmcDCMLongDataWrapper*>(d->getData());
00071 if (!w) {
00072 cout << "\n EmcPutDCMLong <E>: Unable to get pointer for wrapped table, exiting \n\n" << endl;
00073 exit(1);
00074 }
00075 }
00076 delete j;
00077
00078 TABLE_HEAD_ST fTableHeader = w->TableHeader();
00079 Int_t dcmRows = fTableHeader.nok;
00080 static Int_t dcmRowsLast = 0;
00081
00082 DEMCDCMLONGDATA_ST* dEmcDCMDataLong = w->TableData();
00083
00084 Int_t numberOfWords = dEmcDCMDataLong[0].nWords;
00085 Int_t dataID = dEmcDCMDataLong[0].packetID;
00086 Int_t bytesPerWord = 4;
00087 Int_t hitFormat = dEmcDCMDataLong[0].scheme;
00088
00089 if( dcmRows>1500 || numberOfWords>979 ) {
00090 cout << "\n EmcPutDCMLong <E>: dcmRows = " << dcmRows;
00091 cout << ", numberOfWords = " << numberOfWords << endl;
00092 cout << "; Limits are 1500 and 450; exiting" << endl;
00093 exit(1);
00094 }
00095
00096 static PHRawDataNode **rawDataArray;
00097 if(iCall == 0) {
00098 rawDataArray = new PHRawDataNode *[1500];
00099 for(Int_t iRow=0; iRow<1500; iRow++) {
00100 rawDataArray[iRow] = 0;
00101 }
00102 }
00103 iCall++;
00104
00105 char emcPRDF[11] = "emcPRDF000";
00106
00107 for (Int_t iRow=0; iRow<dcmRows; iRow++){
00108 numberOfWords = dEmcDCMDataLong[iRow].nWords;
00109 encodeString(emcPRDF, iRow);
00110 dataID = dEmcDCMDataLong[iRow].packetID;
00111 hitFormat = dEmcDCMDataLong[iRow].scheme;
00112
00113 DWORD *dPtr = (DWORD*)&dEmcDCMDataLong[iRow].DCM[0];
00114 if(rawDataArray[iRow] == 0) {
00115 rawDataArray[iRow] = new PHRawDataNode(dPtr, emcPRDF, numberOfWords, dataID, bytesPerWord, hitFormat);
00116 prdfNode->addNode(rawDataArray[iRow]);
00117 }
00118 else {
00119 PHRawDataNode *rPtr = rawDataArray[iRow];
00120 rPtr->setData(dPtr);
00121 rPtr->setLength(numberOfWords);
00122 rPtr->setID(dataID);
00123 rPtr->setWordLength(bytesPerWord);
00124 rPtr->setHitFormat(hitFormat);
00125 }
00126
00127 }
00128
00129 if(iCall > 1 && dcmRows < dcmRowsLast){
00130 for(Int_t iRow=dcmRows; iRow<dcmRowsLast; iRow++) {
00131 PHRawDataNode *rPtr = rawDataArray[iRow];
00132 rPtr->setLength(0);
00133 rPtr->setID(0);
00134 }
00135 }
00136
00137 dcmRowsLast = dcmRows;
00138 return 0;
00139 }
00140