// mc2coda_dumphits.cc // dumps hits for new mc2coda test program // to link: // g++ -I/group/da/ejw/coda/include -Wall -fPIC -D_GNU_SOURCE -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -o mc2coda_dumphits -L/group/da/ejw/coda/Linux-x86_64/lib -levioxx -levio -lexpat -lieee -lrt -lpthread -lz -lm -lnsl -lresolv -ldl mc2coda_dumphits.cc #include #include #include #include #include using namespace std; using namespace evio; static int evtcount = 0; static string crateFile = "crateMap.txt"; // holds module type for each crate, uses defs from mc2coda.h #define NOMOD 0 #define VMECPU 1 #define TID 2 #define FADC250 3 #define FADC125 4 #define F1TDC32 5 #define F1TDC48 6 #define JLDISC 10 #define USERMOD 14 static vector crateMap(128); // output file ofstream *out = NULL; // prototypes void getCrateMap(string &fileName); void dumphits(evioDOMTree &eventTree); //-------------------------------------------------------------- //-------------------------------------------------------------- int main(int argc, char **argv) { try { // get crate map from file getCrateMap(crateFile); // create and open evio file evioFileChannel in(argv[1],"r"); in.open(); cout << "opened input file " << argv[1] <2) { out = new ofstream(); out->open(argv[2], ios::out | ios::binary); } // loop over events while(in.read()) { // create event tree and dump hits evtcount++; evioDOMTree eventTree(in); dumphits(eventTree); } // reached eof, close all files in.close(); if(out!=NULL)out->close(); cout << endl << " *** dumphits processed " << evtcount << " events ***" << endl << endl; } catch (evioException *e) { cerr << endl << e->toString() << endl << endl; exit(EXIT_FAILURE); } // done exit(EXIT_SUCCESS); } //------------------------------------------------------------------------------- void getCrateMap(string &fileName) { string line; int crate,itype; string type; ifstream in(fileName.c_str(),ifstream::in); if (in.is_open()) { while(in.good()) { getline(in,line); if(line.size()>10) { crate=atoi(line.c_str()); type=line.substr(4); if(type=="FADC250") { itype=FADC250; } else if(type=="FADC125") { itype=FADC125; } else if(type=="F1TDC32") { itype=F1TDC32; } else if(type=="F1TDC48") { itype=F1TDC48; } else if(type=="JLDISC") { itype=JLDISC; } else if(type=="USERMOD") { itype=USERMOD; } else { itype=NOMOD; } if((crate>0)&&(crate<=128))crateMap[crate]=itype; } } in.close(); } else { cerr << "Unable to open file"; } } //------------------------------------------------------------------------------- void dumphits(evioDOMTree &eventTree) { uint32_t type,crate,slot,channel,E,t; int nhitwords; uint32_t buf[6]; // get list of all data (uint32_t) banks in event evioDOMNodeListP dataList = eventTree.getNodeList(typeIs()); // dump hits from all data banks evioDOMNodeList::iterator iter; for(iter=dataList->begin(); iter!=dataList->end(); iter++) { crate = (*iter)->getParent()->tag; if((crate<0)||(crate>127))continue; type = crateMap[crate]; buf[0]=type; buf[1]=crate; vector *vec = (*iter)->getVector(); if((vec!=NULL)&&(vec->size()>0)) { vector::iterator iter2 = vec->begin(); do { if((*iter2)>>27==0x1c) { // slot header slot=(*iter2)>>22&0x1f; nhitwords=(*iter2)&0xffff; buf[2]=slot; if(type==FADC250) { for(int i=0; i>23&0xf; E=*(iter2+i+1)&0x7ffff; t=*(iter2+i+2)&0xffff; buf[3]=channel; buf[4]=E; buf[5]=t; if(out==NULL) { cout << "FADC250 crate,slot,channel,E,t are: " << crate << ", " << slot << ", " << channel << ", " << E << ", " << t << dec << endl; } else { out->write((char*)buf,sizeof(buf)); } } } else if(type==FADC125) { for(int i=0; i>23&0xf; E=*(iter2+i+1)&0x7ffff; t=*(iter2+i+2)&0xffff; buf[3]=channel; buf[4]=E; buf[5]=t; if(out==NULL) { cout << "FADC125 crate,slot,channel,E,t are: " << crate << ", " << slot << ", " << channel << ", " << E << ", " << t << dec << endl; } else { out->write((char*)buf,sizeof(buf)); } } } else if(type==F1TDC32) { for(int i=0; i>23&0xf; t=*(iter2+i+1)&0xffff; buf[3]=channel; buf[4]=0; buf[5]=t; if(out==NULL) { cout << "F1TDC32 crate,slot,channel,t are: " << crate << ", " << slot << ", " << channel << ", " << t << dec << endl; } else { out->write((char*)buf,sizeof(buf)); } } } else if(type==F1TDC48) { for(int i=0; i>23&0xf; t=*(iter2+i+1)&0xffff; buf[3]=channel; buf[4]=0; buf[5]=t; if(out==NULL) { cout << "F1TDC48 crate,slot,channel,t are: " << crate << ", " << slot << ", " << channel << ", " << t << dec << endl; } else { out->write((char*)buf,sizeof(buf)); } } } else { cerr << "?unexpected crate type " << type << endl; } iter2+=nhitwords+1; } else { cerr << "?not slot header: 0x" << hex << *iter2 << dec << endl; ++iter2; } } while (iter2!=vec->end()); } else { cerr << "?bad vector" << endl; } } // event trailer if(out!=NULL) { for(unsigned int i=0; iwrite((char*)buf,sizeof(buf)); } } //------------------------------------------------------------------------------- //-------------------------------------------------------------------------------