#define __WORDSIZE 64 #include #include #include #include #include #include #include #include using namespace std; using namespace evio; // root include files #include "TApplication.h" // needed to display canvas #include "TSystem.h" #include "TFile.h" #include "TMath.h" #include "TTree.h" #include "TCanvas.h" #include "TText.h" #include "TSpectrum.h" #include "TPad.h" #define RANDOMTRIG 100. void analyzeEvent(evioDOMTree &evT); void ConnectToET(const char* snam); void mkpad(TPad **Pads) { Pads[0] = new TPad("Pads0","Title Pad", 0.05, 0.9, 0.97, 0.95, 4); Pads[1] = new TPad("Pads1","Left Pad", 0.02, 0.02, 0.50, 0.89, 21); Pads[2] = new TPad("Pads2","Right Pad", 0.52, 0.02, .98, 0.89, 21); } void RateMonitor(void); int EventCounter = 0; unsigned long EVENTCounter; int CDCOnly; int ISCANCDC = 0; int ISCANFDC = 0; int evtCount = 0; int DEBUG = 0; int DEBUGG = 0; int DEBUGGER = 0; int VERBOSE = 0; int RunNumber = 0; int FInput=0; int FAInput=0; int FVInput=0; int FNInput=0; int TS3 = 0; int Version = 0; long TheEventNum; uint64_t TRIGGERTIMES; uint32_t TRIGGERTYPES; uint32_t TRIGGER_MASK_GT; uint32_t TRIGGER_MASK_FP; uint64_t TOLDFP[100]; uint64_t TNEWFP[100]; uint64_t TOLDFP_INST[100]; uint64_t TNEWFP_INST[100]; double TCNTFP[100]; double TrateFP[100]; double TrateFP_INST[100]; double TrateFPSUM[100]; double TrateFPSUMCnt[100]; uint64_t TOLDGTP[100]; uint64_t TNEWGTP[100]; double TCNTGTP[100]; double TrateGTP[100]; double TrateGTP_INST[100]; double TrateGTPSUM[100]; double TrateGTPSUMCnt[100]; uint64_t TOLDGTP_S[100]; uint64_t TNEWGTP_S[100]; double TCNTGTP_S[100]; double TrateGTP_S[100]; double TrateGTPSUM_S[100]; double TrateGTPSUMCnt_S[100]; double TrateGTP_INST_S[100]; TCanvas *mymon; int NEventsInBlock; uint64_t EVENTNUMBER; uint64_t EVTCounts; int NTLines = 18; // Number of Trigger lines (GTP and FP) uint64_t TIMER[3]; int ETSYSTEM; uint32_t BUFFER_SIZE; et_sys_id sys_id; et_att_id att_id; et_stat_id sta_id; bool et_connected; int ET_STATION_NEVENTS; bool ET_STATION_CREATE_BLOCKING; int FROM_RAID = 1; uint32_t ETBUFF[20000000]; void mangleData(uint32_t *ibuff, long int *TrigTim, uint32_t *TrigTyp); void plotTheData(); void CountTriggers(); int TheRunNumber; TPad *ThePads[3]; TText *List1[20]; TText *List2[20]; TText *List11[20]; TText *List22[20]; TText *List3[20]; TText *RunTitle; int FIRST = 1; int RMFIRST = 1; void initText(){ for (int k=0;k<20;k++){ List1[k] = new TText(0.5,.5, "dummy"); List11[k] = new TText(0.5,.5, "dummy"); List2[k] = new TText(0.5,.5, "dummy"); List22[k] = new TText(0.5,.5, "dummy"); List3[k] = new TText(0.5,.5, "dummy"); } RunTitle = new TText(0.1, 0.5, "dummy"); List1[0]->SetText(0.1,0.95,"GTP TRIGGER RATES (Bit):"); List2[0]->SetText(0.1,0.95,"FP TRIGGER RATES (Bit):"); List1[0]->SetTextSize(0.07); List2[0]->SetTextSize(0.07); List1[0]->SetTextColor(4); List2[0]->SetTextColor(4); List1[1]->SetText(0.1,0.91," (bit # start counting from 1!)"); List1[1]->SetTextSize(0.045); List2[1]->SetText(0.1,0.91," (bit # start counting from 1!)"); List2[1]->SetTextSize(0.045); } int main(int argc, char **argv) { if (argc<2){ cout<<"useage: trigmon [options]"<SetFillColor(18); mymon->Draw(); mymon->cd(); if (FIRST) { mkpad(ThePads); FIRST = 0; } for (int k=0; k<3; k++){ ThePads[k]->Draw(); } if (ETSYSTEM){ int ET_NOTOK = 1; int confail = 0; while (ET_NOTOK) { if (FROM_RAID) { sprintf(ETSystemSource,"ET:/tmp/et_hdops_ERsoftROC:MON_TRIGMON:%s-ib:23921",RaidDisk); } else { sprintf(ETSystemSource,"ET:/tmp/et_hdops_SEB0:MON_TRIGMON:%s-ib:23921",RaidDisk); //sprintf(ETSystemSource,"ET:/tmp/et_sys_monitoring:MON_TRIGMON:172.19.5.47:11122"); } cout<<"Attempt to connect to ET system with: "<10){ return 100; } sleep(10); } else{ ET_NOTOK = 0; } } long int TrigTim[10000]; uint32_t TrigTyp[10000]; et_event *pe=NULL; struct timespec timeout; uint32_t *et_buff=NULL; while (OK){ timeout.tv_sec = 10; timeout.tv_nsec = 1; int err = et_event_get(sys_id, att_id, &pe, ET_TIMED , &timeout); if( err == ET_OK && pe==NULL){ cout << " !!! ET returned no error, but event pointer is NULL!!!" << endl; OK = 0; } else if (err != ET_OK){ OK = 0; } et_event_getdata(pe, (void**)&et_buff); if (et_buff == NULL){ cout<<"No DATA quit!"<()); evioDOMNodeList::iterator iter = bankList2->begin(); // const uint64_t *run_number_and_type = NULL; for(; iter!=bankList2->end(); iter++){ //cout<<"uint64_t loop"<getParent(); if(physics_event_built_trigger_bank == NULL) continue; uint32_t tag = physics_event_built_trigger_bank->tag; const vector *vec; switch(tag){ case 0xFF22: case 0xFF23: case 0xFF26: case 0xFF27: vec = bankPtr->getVector(); if(!vec) continue; if(vec->size()<1) continue; run_number_and_type = &((*vec)[vec->size()-1]); break; } if(run_number_and_type != NULL){ TheRunNumber = ((*vec)[vec->size()-1])>>32; EVENTNUMBER = ((*vec)[0]); int MEVENTS = vec->size()-2; NEventsInBlock = MEVENTS ; TheEventNum = EVENTNUMBER; EVTCounts += MEVENTS; //cout<< TheRunNumber<<" "<()); evioDOMNodeList::iterator iterX = bankList->begin(); for(; iterX!=bankList->end(); iterX++){ //cout<<"uint32_t loop"<getParent(); if(physics_event_built_trigger_bank == NULL) continue; if (bankPtr->tag==1){ const vector *vec; vec = bankPtr->getVector(); int NEV = vec->size()/4; if (NEventsInBlock != NEV){ cout<<"Error Event Number Miss Match In Block "<SetText(0.05,0.88-(float)k*0.04, str1); List1[k+2]->SetTextSize(0.08); List1[k+2]->SetTextColor(15); if ( TrateGTP[k]>0 ){ List1[k+2]->SetTextColor(1); } sprintf(str1,"(%6.2f kHz)",TrateGTP_S[k]); if (ETSYSTEM) sprintf(str1,"%02d %6.2f kHz ",k+1,TrateGTP_INST_S[k]); List11[k+2]->SetText(0.65,0.88-(float)k*0.04, str1); List11[k+2]->SetTextSize(0.05); List11[k+2]->SetTextColor(15); if ( TrateGTP_S[k]>0 ){ List11[k+2]->SetTextColor(1); } //cout<SetText(0.05,0.88-(float)k*0.04, str1); List2[k+2]->SetTextSize(0.08); List2[k+2]->SetTextColor(15); if ( TrateFP[k]>0 ){ List2[k+2]->SetTextColor(1); } List22[k+2]->SetText(0.65,0.88-(float)k*0.04, str1); List22[k+2]->SetTextSize(0.05); List22[k+2]->SetTextColor(15); if ( TrateFP_INST[k]>0 ){ List22[k+2]->SetTextColor(1); } } sprintf(str1,"FULL: %6.2f kHz ",TrateGTP[99]); List3[0]->SetText(0.15,0.78-(float)NT*0.04, str1); List3[0]->SetTextSize(0.08); List3[0]->SetTextColor(15); if ( TrateGTP[99]>0 ){ List3[0]->SetTextColor(1); } char a[128]="%"; sprintf(str1,"LT: %6.1f %s ",TrateFP_INST[11]/RANDOMTRIG*100000.,a); List3[1]->SetText(0.15,0.78-(float)(NT+1)*0.04, str1); List3[1]->SetTextSize(0.08); List3[1]->SetTextColor(15); if ( TrateFP_INST[11]>0 ){ List3[1]->SetTextColor(1); } char tit[128]; sprintf(tit,"Run Number %d",TheRunNumber); RunTitle->SetText(0.3, 0.255,tit); RunTitle->SetTextColor(5); RunTitle->SetTextSize(0.6); mymon->cd(); ThePads[0]->cd(); ThePads[0]->Clear(); RunTitle->Draw(); ThePads[1]->cd(); ThePads[1]->Clear(); List1[0]->Draw(); List1[1]->Draw(); for (int k=0;kDraw(); List11[k+2]->Draw(); } List3[0]->Draw(); List3[1]->Draw(); gPad->Update(); ThePads[2]->cd(); ThePads[2]->Clear(); List2[0]->Draw(); List2[1]->Draw(); for (int k=0;kDraw(); List22[k+2]->Draw(); } gPad->Update(); } void ConnectToET(const char* snam){ vector fields; string str(snam); size_t startpos=0, endpos=0; while((endpos = str.find(":", startpos)) != str.npos){ size_t len = endpos-startpos; fields.push_back(len==0 ? "":str.substr(startpos, len)); startpos = endpos+1; } if(startpos1 ? fields[1]:""; string station = fields.size()>2 ? fields[2]:""; string host = fields.size()>3 ? fields[3]:"localhost"; int port = fields.size()>4 ? atoi(fields[4].c_str()):ET_SERVER_PORT; if(session == "") session = "none"; if(station == "") station = "DANA"; if(host == "") host = "localhost"; string fname = session.at(0)=='/' ? session:(string("/tmp/et_sys_") + session); // Report to user what we're doing cout << " Opening ET system:" << endl; if(session!=fname) cout << " session: " << session << endl; cout << " station: " << station << endl; cout << " system file: " << fname << endl; cout << " host: " << host << endl; if(port !=0) cout << " port: " << port << endl; // connect to the ET system et_openconfig openconfig; et_open_config_init(&openconfig); et_open_config_setcast(openconfig, ET_DIRECT); et_open_config_setmode(openconfig, ET_HOST_AS_LOCAL); // ET_HOST_AS_LOCAL or ET_HOST_AS_REMOTE et_open_config_sethost(openconfig, host.c_str()); et_open_config_setport(openconfig, ET_BROADCAST_PORT); if(port != 0)et_open_config_setserverport(openconfig, port); int err = et_open(&sys_id,fname.c_str(),openconfig); if(err != ET_OK){ cerr << __FILE__<<":"<<__LINE__<<" Problem opening ET system"<= " << Nevents << endl; cerr << endl; cerr << "Try re-running with: " << endl; cerr << endl; cerr << " -PEVIO:ET_STATION_NEVENTS=" << (Nevents+1)/2 << endl; cerr << endl; } return; } if(status==ET_ERROR_EXISTS){ cout << " Using existing ET station " << station << endl; }else{ cout << " ET station " << station << " created\n"; } // Attach to the ET station status=et_station_attach(sys_id,sta_id,&att_id); if(status!=ET_OK) { et_close(sys_id); cerr << "Unable to attach to station " << station << endl; return; } cout << "...now connected to ET system: " << fname << ", station: " << station << " (station id=" << sta_id << ", attach id=" << att_id <<")" << endl; et_connected = true; // chan = new evioETChannel(sys_id, att_id); // Make sure the size of event buffers we will allocate are at least as big // as the event size used in the ET system size_t eventsize; et_system_geteventsize(sys_id, &eventsize); if((uint32_t)eventsize > BUFFER_SIZE){ cout<<" Events in ET system are larger than currently set buffer size:"< "<>20) == 0xFF2){ NROCS = Ns[2] & 0xFF; } if (NROCS>64){ cout<<"FUCK! NROCS!!!! "<>24) & 0xFF; if (ROCID[n] == 1){ break; } } if (ROCID[n] == 1){ // this is the trigger supervisor ROC int NEVENTS = LEN[n]/4; uint32_t w[4]; int idx = 9+RecLenOffset + Len1 + Len0 + Len2 + off + 1; for (int i=0; i0){ unsigned int val = TRIGGER_MASK_GT; for (int nn=0; nn<32; nn++){ bit1[nn] = -1; if (val & (1<0){ unsigned int val = TRIGGER_MASK_FP; for (int nn=0; nn<32; nn++){ bit2[nn] = -1; if (val & (1<0){ TrateFPSUM[bit2[nn]] += 1./dt; TrateFPSUMCnt[bit2[nn]] += 1.; TOLDFP_INST[bit2[nn]] = TNEWFP_INST[bit2[nn]]; } } } if (NBits1==0){ TNEWGTP[99] = TRIGGERTIMES; // COUNT All TRIGGERS TCNTGTP[99] += 1.; if (TOLDGTP[99] == 0){ TOLDGTP[99] = TNEWGTP[99]; } } } if (!ETSYSTEM){ plotTheData(); } } void plotTheData(){ double DT = ((double)(TIMER[1] - TIMER[0])) *4./1000000. ; // Time laps in ms //if (!(int(DT)%2000)){ // a little more than 1 s //if (DT>2000.){ // a little more than 1 s if ((ETSYSTEM) || (DT>2000.)) { // a little more than 1 s EVTCounts = 0; int NT = NTLines; for (int n=0;n0) { double dt = (TNEWGTP[n]-TOLDGTP[n])*4./1000000.; if (dt>0){ TrateGTP[n] = TCNTGTP[n]/DT; TrateGTPSUM[n] += TCNTGTP[n]/DT; TrateGTPSUMCnt[n] += 1.; TrateGTP_INST[n] = TrateGTPSUM[n]/TrateGTPSUMCnt[n]; //TrateGTP[n] = TCNTGTP[n]/dt; } } else { TrateGTP[n] = 0; } //cout<0) { double dt = (TNEWGTP[99]-TOLDGTP[99])*4./1000000.; if (dt>0){ TrateGTP[99] = TCNTGTP[99]/DT; //TrateGTP[99] = TCNTGTP[99]/dt; } } else { TrateGTP[99] = 0; } for (int n=0;n0) { double dt = (TNEWGTP_S[n]-TOLDGTP_S[n])*4./1000000.; if (dt>0){ TrateGTP_S[n] = TCNTGTP_S[n]/DT; TrateGTPSUM_S[n] += TCNTGTP[n]/DT; TrateGTPSUMCnt_S[n] += 1.; TrateGTP_INST_S[n] = TrateGTPSUM_S[n]/TrateGTPSUMCnt_S[n]; //TrateGTP_S[n] = TCNTGTP_S[n]/dt; } } else { TrateGTP_S[n] = 0; } } for (int n=0;n0) { double dt = (TNEWFP[n]-TOLDFP[n])*4./1000000.; if (dt>0){ TrateFP[n] = TCNTFP[n]/DT; //TrateFP[n] = TCNTFP[n]/dt; } else { TrateFP[n] = 0.; } } if (TrateFPSUMCnt[n]>0){ TrateFP_INST[n] = TrateFPSUM[n] / TrateFPSUMCnt[n]; } else { TrateFP_INST[n] = 0.; } } RateMonitor(); TIMER[0] = 0; TIMER[1] = 0; for (int n=0;n<100;n++){ TOLDGTP[n] = 0; TNEWGTP[n] = 0; TCNTGTP[n] = 0.; TOLDGTP_S[n] = 0; TNEWGTP_S[n] = 0; TCNTGTP_S[n] = 0.; if (TrateGTPSUMCnt[n] > 10){ TrateGTPSUMCnt[n] = 0; TrateGTPSUM[n] = 0; } if (TrateGTPSUMCnt_S[n] > 10){ TrateGTPSUMCnt_S[n] = 0; TrateGTPSUM_S[n] = 0; } } for (int n=0;n<100;n++){ TOLDFP[n] = 0; TNEWFP[n] = 0; TCNTFP[n] = 0.; TrateFPSUMCnt[n] = 0; TrateFPSUM[n] = 0; } } return; }