EmcPutDCM.cc

Go to the documentation of this file.
00001 #include "dEmcDCMDataWrapper.h"
00002 //INCLUDECHECKER: Removed this line: #include "EmcPutDCM.h"
00003 
00004 #include "encodeString.h"
00005 
00006 //INCLUDECHECKER: Removed this line: #include "phool.h"
00007 #include "Event.h"
00008 #include "PHIODataNode.h"
00009 //INCLUDECHECKER: Removed this line: #include "PHCompositeNode.h"
00010 //INCLUDECHECKER: Removed this line: #include "PHNodeIterator.h"
00011 //INCLUDECHECKER: Removed this line: #include "PHRawOManager.h"
00012 #include "PHRawDataNode.h"
00013 
00014 //INCLUDECHECKER: Removed this line: #include <packetConstants.h>
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 EmcPutDCM(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; // used to initialize the rawdata pointers 
00032 
00033   // Find the DCM Node.
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   //Find the PRDF node
00044   n1 = iter.findFirst("PHCompositeNode", "SIMPRDF");
00045   static int iWarn = 1;
00046   if(!n1) {
00047     if(iWarn) {
00048       cout << "\n EmcPutDCM <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   }  // maintaining backward compatibility
00053   if (!n1) {
00054     cout << "\n EmcPutDCM <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   // Extract the data from the dEmcDCMdata in DCM Node.
00062   dEmcDCMDataWrapper *w;
00063   j = new PHNodeIterator(DCMNode);
00064   d = static_cast<TableNode_t*>(j->findFirst("PHIODataNode","dEmcDCMData"));
00065   if (!d) {
00066     cout << "\n EmcPutDCM <E>: Unable to find STAF Table dEmcDCMData, exiting \n\n" << endl;
00067     exit(1);
00068   }
00069   else {
00070     w = static_cast<dEmcDCMDataWrapper*>(d->getData());
00071     if (!w) {
00072       cout << "\n EmcPutDCM <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   DEMCDCMDATA_ST* dEmcDCMData = w->TableData();
00083 
00084   Int_t numberOfWords = dEmcDCMData[0].nWords;
00085   Int_t dataID = dEmcDCMData[0].packetID;
00086   Int_t bytesPerWord = 4;
00087   Int_t hitFormat = dEmcDCMData[0].scheme;
00088   
00089   if( dcmRows>1500 || numberOfWords>450 ) {
00090     cout << "\n EmcPutDCM <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   }  // initialization of rawDataArray pointers
00103   iCall++;
00104 
00105   char emcPRDF[11] = "emcPRDF000";  // assumes maximum of 999 rows
00106 
00107   for (Int_t iRow=0; iRow<dcmRows; iRow++){
00108     numberOfWords = dEmcDCMData[iRow].nWords;
00109     encodeString(emcPRDF, iRow);
00110     dataID = dEmcDCMData[iRow].packetID;
00111     hitFormat = dEmcDCMData[iRow].scheme;
00112 
00113     DWORD *dPtr = (DWORD*)&dEmcDCMData[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   } // loop over dcmRows
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     }  // zero out excess rows
00135   }
00136 
00137   dcmRowsLast = dcmRows;  // save for next event
00138   return 0;
00139 }
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149