#define readData_cxx #include "readData.h" #include "string.h" #include #include #include #include #include void readData::readDataFile(int maxNumEvts){ // put maxNumEvts ==0 for all evts cout<<" ....making tree for a max of "< eof() && (NumEvtsDone readEvent();//do this for N events!! NumEvtsDone ++; } catch(string msg){ cout<<"caught error message::"<>>>>>"<>>>>>"< readEventHeaders(); ///*********** here fill tree with header words.. //nb maybe not all of the data is stored, look in the rootTree class!! rootTree_ -> fillEventHeader(HD1a_map, HD1b_map, HD1c_map, HD1d_map, HD2a_map, HD2b_map, HD2c_map, HD2d_map); int SP_ERSV = HD2b_map["SP_ERSV"];//tells us f/w version. Old ones don't have block of counters if(SP_ERSV>0){// we expect a block of counters after the header this -> readBlockCounters(); rootTree_ -> fillBlockCounter(BCa_map, BCb_map, BCc_map, BCd_map); } TBIN = HD2d_map["TBIN"]; //loop over the event data for 'TBIN' bunch crossings: for (int bx = 0; bx < TBIN; bx++){//loop over number of bx read in this trigger //read Data block header (8 words, always present) this -> readDataBlockHeaders(); ///******* here fill tree with this front LCT (bx) event header data //nb maybe not all of the data is stored, look in the rootTree:: class below!! rootTree_ -> fillDataBlockHeader(BH1a_map, BH1b_map, BH1c_map, BH1d_map, BH2a_map, BH2b_map, BH2c_map, BH2d_map, bx); //read data for each front end link that was active _and_ either ZS==0 or ZS==1 && VP==1 for (int LINK = 1; LINK < 16; LINK++){ //was this FFPGA active? ostringstream FFPGA; FFPGA << (LINK+2)/3; string activeKey = "F" ;activeKey += FFPGA.str();activeKey += "A";//construct the key for the HD2d map if (HD2d_map[activeKey]){// if this FFPGA active if ( (HD2d_map["ZS"] == 0) ||( (( BH1a_map["hexwd"]>>(LINK-1)) &0x1 ) ) ){ //read ME data for this link on this evt: // 4 ME data words: this -> readMEDataRecords(); ///******* here fill tree with this front LCT (bx)(link) data //nb maybe not all of the data is stored, look in the rootTree:: class below!! rootTree_ -> fillMEDataRecord(MEa_map, MEb_map, MEc_map, MEd_map, bx, LINK); }//end if zs==0 or }//end if FFPGA active }//end loop over active FFPGA //read 4 frames of data for each DT stub (ZS=0 _or_ ZS=1 and qual=1) if (HD2d_map["DTA"]){//if DT is active if (BH1b_map["VQa"] == 1 || HD2d_map["ZS"] == 0 ){//if muon in DT-a has quality or ZS=0 int whichMB = 1; //MBa this -> readMBDataRecords(); ///******* here fill tree with this MB(bx)(ma==1) data //nb maybe not all of the data is stored, look in the rootTree:: class below!! rootTree_ -> fillMBDataRecord(MBa_map, MBb_map, MBc_map, MBd_map, bx, whichMB); }//end if muon in DT-a if (BH1b_map["VQd"] || HD2d_map["ZS"] == 0){//if muon in DT-d has quality or ZS=0 int whichMB = 2; //MBd this -> readMBDataRecords(); ///******* here fill tree with this MB(bx)(md==2) data rootTree_ -> fillMBDataRecord(MBa_map, MBb_map, MBc_map, MBd_map, bx, whichMB); }//end if muon in DT-d }//end if DTA is active //read SP data if SP bit active and ZS=0 or ZS=1 and modeZ>0 if (HD2d_map["SPA"]){//if SP is active //loop over 3 posible SP modes for (int mode = 1; mode < 4; mode++){//loop over 3 SP 'modes' ostringstream mode_ss; mode_ss << mode; string modeKey = "MODE" ;modeKey += mode_ss.str();//construct the key for the BH1b map if (HD2d_map["ZS"] == 0 || BH1b_map[modeKey]>0){ this -> readSPDataRecords(); ///******* here fill tree with this SP(bx)(mode) data //nb maybe not all of the data is stored, look in the rootTree:: class below!! rootTree_ -> fillSPDataRecord(SPa_map, SPb_map, SPc_map, SPd_map, bx, mode); }//end if zs =0 or modez>0 }//end loop over 3 SP modes }//end if SP active }//end loop over TBIN BX //read event trailer this -> readEventTrailers(); ///******* here fill tree with event trailer data you want rootTree_ -> fillEventTrailer(TR1a_map, TR1b_map, TR1c_map, TR1d_map, TR2a_map, TR2b_map, TR2c_map, TR2d_map); // fill tree at end of evt: rootTree_ -> getTree() -> Fill(); return; } inline void readData::readEventHeaders(){ this -> readHexWord(); HD1a_map = dictionary_ -> readEventHeader_HD1a(hexwd); this -> readHexWord(); HD1b_map = dictionary_ -> readEventHeader_HD1b(hexwd); this -> readHexWord(); HD1c_map = dictionary_ -> readEventHeader_HD1c(hexwd); this -> readHexWord(); HD1d_map = dictionary_ -> readEventHeader_HD1d(hexwd); this -> readHexWord(); HD2a_map = dictionary_ -> readEventHeader_HD2a(hexwd); this -> readHexWord(); HD2b_map = dictionary_ -> readEventHeader_HD2b(hexwd); this -> readHexWord(); HD2c_map = dictionary_ -> readEventHeader_HD2c(hexwd); this -> readHexWord(); HD2d_map = dictionary_ -> readEventHeader_HD2d(hexwd); return; } inline void readData::readBlockCounters(){ this -> readHexWord(); BCa_map = dictionary_ -> readBlockCounter_BCa(hexwd); this -> readHexWord(); BCb_map = dictionary_ -> readBlockCounter_BCb(hexwd); this -> readHexWord(); BCc_map = dictionary_ -> readBlockCounter_BCc(hexwd); this -> readHexWord(); BCd_map = dictionary_ -> readBlockCounter_BCd(hexwd); return; } inline void readData::readDataBlockHeaders(){ this -> readHexWord(); BH1a_map = dictionary_ -> readDataBlockHeader_BH1a(hexwd); this -> readHexWord(); BH1b_map = dictionary_ -> readDataBlockHeader_BH1b(hexwd); this -> readHexWord(); BH1c_map = dictionary_ -> readDataBlockHeader_BH1c(hexwd); this -> readHexWord(); BH1d_map = dictionary_ -> readDataBlockHeader_BH1d(hexwd); this -> readHexWord(); BH2a_map = dictionary_ -> readDataBlockHeader_BH2a(hexwd); this -> readHexWord(); BH2b_map = dictionary_ -> readDataBlockHeader_BH2b(hexwd); this -> readHexWord(); BH2c_map = dictionary_ -> readDataBlockHeader_BH2c(hexwd); this -> readHexWord(); BH2d_map = dictionary_ -> readDataBlockHeader_BH2d(hexwd); return; } inline void readData::readMEDataRecords(){ this -> readHexWord(); MEa_map = dictionary_ -> readMEDataRecord_MEa(hexwd); this -> readHexWord(); MEb_map = dictionary_ -> readMEDataRecord_MEb(hexwd); this -> readHexWord(); MEc_map = dictionary_ -> readMEDataRecord_MEc(hexwd); this -> readHexWord(); MEd_map = dictionary_ -> readMEDataRecord_MEd(hexwd); return; } inline void readData::readMBDataRecords(){ this -> readHexWord(); MBa_map = dictionary_ -> readMBDataRecord_MBa(hexwd); this -> readHexWord(); MBb_map = dictionary_ -> readMBDataRecord_MBb(hexwd); this -> readHexWord(); MBc_map = dictionary_ -> readMBDataRecord_MBc(hexwd); this -> readHexWord(); MBd_map = dictionary_ -> readMBDataRecord_MBd(hexwd); return; } inline void readData::readSPDataRecords(){ this -> readHexWord(); SPa_map = dictionary_ -> readSPDataRecord_SPa(hexwd); this -> readHexWord(); SPb_map = dictionary_ -> readSPDataRecord_SPb(hexwd); this -> readHexWord(); SPc_map = dictionary_ -> readSPDataRecord_SPc(hexwd); this -> readHexWord(); SPd_map = dictionary_ -> readSPDataRecord_SPd(hexwd); return; } inline void readData::readEventTrailers(){ this -> readHexWord(); TR1a_map = dictionary_ -> readEventTrailer_TR1a(hexwd); this -> readHexWord(); TR1b_map = dictionary_ -> readEventTrailer_TR1b(hexwd); this -> readHexWord(); TR1c_map = dictionary_ -> readEventTrailer_TR1c(hexwd); this -> readHexWord(); TR1d_map = dictionary_ -> readEventTrailer_TR1d(hexwd); this -> readHexWord(); TR2a_map = dictionary_ -> readEventTrailer_TR2a(hexwd); this -> readHexWord(); TR2b_map = dictionary_ -> readEventTrailer_TR2b(hexwd); this -> readHexWord(); TR2c_map = dictionary_ -> readEventTrailer_TR2c(hexwd); this -> readHexWord(); TR2d_map = dictionary_ -> readEventTrailer_TR2d(hexwd); return; } readData::readData(string* pathToFile){ dictionary_ = new dictionary(); dataStream = this -> openFileStream(pathToFile); hexwd=0x0; rootTree_ = new rootTree(); } readData::~readData(){ dataStream -> close(); delete rootTree_; delete dataStream; delete dictionary_; } inline void readData::readHexWord(){ //read the next 16-bit hex word in the file and assign it to 'hexwd' //we return booltrue if we are not at eof and have read word ok! string tempString; getline(*dataStream,tempString); stringstream ss(tempString); ss >> hex >> hexwd; std::cout<<"-------------------->> read word ::0x"< eof()){ string msg ("end of data file reached"); throw(msg); } return ; } inline std::ifstream* readData::openFileStream(std::string* FileName){//danger function, you have to delete the pointer it returns std::ifstream* fileStream = new std::ifstream();//please delete me, let me go, for i don't love you anymore... fileStream->open(FileName->c_str(),std::ios::in); if (fileStream->is_open() ){ std::cout<<" ** Opening Data File ::"<c_str()<<" ---> input data"<c_str(); std::cout<