X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TPC%2FTPCCEda.cxx;h=cd1f38b401bf3c1cffb70ac462b786d89a341c74;hb=9a83d4afe29d48b9b3cb75b3fde10d47939c7be8;hp=cb1958513d05888f6f03b1001d5dabb7569978b8;hpb=db7038d0b8bba52cc4282c7c03291bbebc2745f1;p=u%2Fmrichter%2FAliRoot.git diff --git a/TPC/TPCCEda.cxx b/TPC/TPCCEda.cxx index cb1958513d0..cd1f38b401b 100644 --- a/TPC/TPCCEda.cxx +++ b/TPC/TPCCEda.cxx @@ -39,7 +39,6 @@ and save results in a file (named from RESULT_FILE define - see below). #include "monitor.h" #include #include -#include #include // //Root includes @@ -51,6 +50,7 @@ and save results in a file (named from RESULT_FILE define - see below). #include "TString.h" #include "TObjString.h" #include "TDatime.h" +#include "TStopwatch.h" #include "TMap.h" #include "TGraph.h" #include "TMath.h" @@ -81,14 +81,6 @@ and save results in a file (named from RESULT_FILE define - see below). //functios, implementation below void SendToAmoreDB(AliTPCCalibCE &calibCE, unsigned long32 runNb); //for threaded processing -void *processEventBuffer(void *arg); - -//common event processing variables for threaded processing -std::vector eventBuffer; -volatile int bStop = false; -struct timespec duree_nanosleep; -Int_t forceNevents=-1; -Bool_t forceBufferEnds=kFALSE; /* Main routine @@ -96,10 +88,10 @@ Bool_t forceBufferEnds=kFALSE; */ int main(int argc, char **argv) { /* log start of process */ - printf("TPC CE DA started - %s\n",__FILE__); + printf("TPCCEda: DA started - %s\n",__FILE__); if (argc<2) { - printf("Wrong number of arguments\n"); + printf("TPCCEda: Wrong number of arguments\n"); return -1; } @@ -118,7 +110,7 @@ int main(int argc, char **argv) { int i,status; status=monitorDeclareMp( __FILE__ ); if (status!=0) { - printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); + printf("TPCCEda: monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); return -1; } monitorSetNowait(); @@ -129,12 +121,7 @@ int main(int argc, char **argv) { char localfile[255]; unsigned long32 runNb=0; //run number - // - // thread wait time - // - duree_nanosleep.tv_sec=0; - duree_nanosleep.tv_nsec=1000000; //1 ms - + // // DA configuration from configuration file // @@ -142,64 +129,57 @@ int main(int argc, char **argv) { sprintf(localfile,"./%s",CONFIG_FILE); status = daqDA_DB_getFile(CONFIG_FILE,localfile); if (status) { - printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status); + printf("TPCCEda: Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status); return -1; } AliTPCConfigDA config(CONFIG_FILE); // check configuration options TString laserTriggerName("C0LSR-ABCE-NOPF-CENT"); - size_t bufferSize=30; + TString monitoringType("YES"); Int_t forceTriggerId=-1; - Int_t forceNeventsStandalone=-1; - Bool_t forceBufferEndsGlobal=kTRUE; -// Bool_t forceBufferEndsGlobalDummy=kFALSE; + if ( config.GetConfigurationMap()->GetValue("LaserTriggerName") ) { laserTriggerName=config.GetConfigurationMap()->GetValue("LaserTriggerName")->GetName(); - printf("Laser trigger class name set to: %s.\n",laserTriggerName.Data()); + printf("TPCCEda: Laser trigger class name set to: %s.\n",laserTriggerName.Data()); } - - if ( config.GetConfigurationMap()->GetValue("BufferSize") ) { - bufferSize=(size_t)config.GetValue("BufferSize"); - printf("Setting event buffer size to: %d.\n",bufferSize); - } - - if ( config.GetConfigurationMap()->GetValue("ForceTriggerId") ) { - forceTriggerId=TMath::Nint(config.GetValue("ForceTriggerId")); - printf("Only processing triggers with Id: %d.\n",forceTriggerId); + + if ( config.GetConfigurationMap()->GetValue("MonitoringType") ) { + monitoringType=config.GetConfigurationMap()->GetValue("MonitoringType")->GetName(); + printf("TPCCEda: Monitoring type set to: %s.\n",monitoringType.Data()); } - - if ( config.GetConfigurationMap()->GetValue("ForceBufferEndsGlobal") ) { - forceBufferEndsGlobal=config.GetValue("ForceBufferEndsGlobal")!=0.; - printf("Process all buffered events in global partition: %s.\n",forceBufferEndsGlobal?"yes":"no"); + + if ( config.GetConfigurationMap()->GetValue("ForceLaserTriggerId") ) { + forceTriggerId=TMath::Nint(config.GetValue("ForceLaserTriggerId")); + printf("TPCCEda: Only processing triggers with Id: %d.\n",forceTriggerId); } - if ( config.GetConfigurationMap()->GetValue("ForceNMaxEvents") ) { - forceNevents=TMath::Nint(config.GetValue("ForceNMaxEvents")); - printf("Forcing maximum number of %d events.\n",forceNeventsStandalone); - } //subsribe to laser triggers only in physics partition //if the trigger class is not available the return value is -1 //in this case we are most probably running as a standalone // laser run and should request all events - unsigned char *classIdptr=0; - int retClassId=daqDA_getClassIdFromName(laserTriggerName.Data(),classIdptr); + unsigned char classIdptr=0; + int retClassId=daqDA_getClassIdFromName(laserTriggerName.Data(),&classIdptr); if (retClassId==0){ //interleaved laser in physics runs + //select proper trigger class id char c[5]; - sprintf(c,"%u",*classIdptr); - char *table[5] = {"PHY","Y","*",c,NULL}; + snprintf(c,sizeof(c),"%u",(unsigned int)classIdptr); + char *table[5] = {"PHY",const_cast(monitoringType.Data()),"*",c,NULL}; monitorDeclareTableExtended(table); - printf("Using trigger class Id: %s\n",c); -// forceBufferEndsGlobal=forceBufferEndsGlobalDummy; + printf("TPCCEda: Using monitoring table: (PHY, %s, *, %s)\n",monitoringType.Data(),c); } else if (retClassId==-1){ - //defaul case, accept all physics events - char *table[3] = {"PHY","Y",NULL}; + //global partition without laser triggered events + //the DA should exit properly without processing + printf("TPCCEda: Laser trigger class '%s' was not found among trigger class names. Will stop processing.\n",laserTriggerName.Data()); + return 0; + } else if (retClassId==-2){ + //standalone case, accept all physics events + char *table[5] = {"PHY","Y","*","*",NULL}; monitorDeclareTableExtended(table); - printf("Using all trigger class Ids\n"); -// forceNevents=forceNeventsStandalone; + printf("TPCCEda: Using all trigger class Ids\n"); } else { - printf("Unknown return value of 'daqDA_getClassIdFromName': %d\n",retClassId); + printf("TPCCEda: Unknown return value of 'daqDA_getClassIdFromName': %d\n",retClassId); return -2; } @@ -209,7 +189,6 @@ int main(int argc, char **argv) { sprintf(c,"%d",forceTriggerId); char *table[5] = {"PHY","Y","*",c,NULL}; monitorDeclareTableExtended(table); -// forceBufferEndsGlobal=forceBufferEndsGlobalDummy; } @@ -219,7 +198,7 @@ int main(int argc, char **argv) { sprintf(localfile,"./%s",MAPPING_FILE); status = daqDA_DB_getFile(MAPPING_FILE,localfile); if (status) { - printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status); + printf("TPCCEda: Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status); return -1; } @@ -230,10 +209,10 @@ int main(int argc, char **argv) { } if (mapping == 0) { - printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE); + printf("TPCCEda: Failed to get mapping object from %s. ...\n", MAPPING_FILE); return -1; } else { - printf("Got mapping object from %s\n", MAPPING_FILE); + printf("TPCCEda: Got mapping object from %s\n", MAPPING_FILE); } @@ -241,27 +220,26 @@ int main(int argc, char **argv) { AliTPCCalibCE calibCE(config.GetConfigurationMap()); // central electrode calibration calibCE.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb - // - // start thread - // -// sleep(5); - pthread_t threadId=0; - int threadStatus=0; - threadStatus = pthread_create( &threadId, NULL, processEventBuffer, (void*)(&calibCE)); - eventBuffer.resize(bufferSize); - struct timespec duree_out; + //amore update interval + Double_t updateInterval=300; //seconds + Double_t valConf=config.GetValue("AmoreUpdateInterval"); + if ( valConf>0 ) updateInterval=valConf; + //timer + TStopwatch stopWatch; + //===========================// // loop over RAW data files // //==========================// int nevents=0; + int neventsOld=0; size_t counter=0; for ( i=1; i0 && calibCE.GetNeventsProcessed()>=forceNevents) { - printf("Requested number of events reached (%d).\n",forceNevents); + + /* get next event (blocking call until timeout) */ + status=monitorGetEventDynamic((void **)&event); + if (status==MON_ERR_EOF) { + printf ("TPCCEda: End of File %d detected\n",i); + break; /* end of monitoring file has been reached */ + } + + if (status!=0) { + printf("TPCCEda: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); break; } - //buffer events, only read them if a buffer position is free - if (eventBuffer[counter]==0) { - - /* get next event (blocking call until timeout) */ - status=monitorGetEventDynamic((void **)&event); - if (status==MON_ERR_EOF) { - printf ("End of File %d detected\n",i); - break; /* end of monitoring file has been reached */ + /* retry if got no event */ + if (event==NULL){ + //use time in between bursts to + // send the data to AMOREdb + if (stopWatch.RealTime()>updateInterval){ + calibCE.Analyse(); + SendToAmoreDB(calibCE,runNb); + stopWatch.Start(); + } else { + stopWatch.Continue(); } - - if (status!=0) { - printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); - break; + //debug output + if (nevents>neventsOld){ + printf ("TPCCEda: %d events processed, %d used\n",nevents,calibCE.GetNeventsProcessed()); + neventsOld=nevents; } - - /* retry if got no event */ - if (event==NULL) - continue; + + continue; + } /* skip start/end of run events */ - if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) ){ - free(event); - continue; - } - - - // get the run number - runNb = event->eventRunNb; - -// printf(" trigger (%05d-%03d) = %8.8x %8.8x - %02u\n",nevents, calibCE.GetNeventsProcessed(), -// event->eventTriggerPattern[1], event->eventTriggerPattern[0],event->eventType); - -// printf("filling buffer %d\n",counter); - eventBuffer[counter]=event; - - ++nevents; - ++counter; - if (counter >= eventBuffer.size()) {counter=0;} - }else{ -// printf("buffer already used: %d\n",counter); - nanosleep(&duree_nanosleep,&duree_out); + if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) ){ + free(event); + continue; } + + + // get the run number + runNb = event->eventRunNb; + + // CE calibration + calibCE.ProcessEvent(event); + + /* free resources */ + free(event); + ++nevents; } } - - // - // wait for thread to end - // - if (!forceBufferEndsGlobal) bStop = true; - else forceBufferEnds=forceBufferEndsGlobal; - pthread_join( threadId, NULL); -// printf("Event Processing Thread ended with: %d\n",threadStatus); - - // - // free unprocessed events - // - for (size_t i=0;ieventRunNb; -// printf("processing buffer: %d\n",counter); - eventBuffer[counter]=0; - calibCE.ProcessEvent(event); - free(event); - published=kFALSE; - } else { - //in case of empty buffer publish the results it this was not done - if (!published) { - SendToAmoreDB(calibCE,runNb); - published=kTRUE; - } - nanosleep(&duree_nanosleep,&duree_out); - } - ++counter; - if (counter >= eventBuffer.size()) { - counter=0; - if (forceBufferEnds) break; - } - } -} void SendToAmoreDB(AliTPCCalibCE &calibCE, unsigned long32 runNb) { //AMORE - printf ("AMORE part\n"); +// printf ("AMORE part\n"); const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME"); //cheet a little -- temporary solution (hopefully) // @@ -441,7 +354,7 @@ void SendToAmoreDB(AliTPCCalibCE &calibCE, unsigned long32 runNb) statusDA+=amoreDA.Send("DriftC",grC); statusDA+=amoreDA.Send("Info",&info); if ( statusDA!=0 ) - printf("Waring: Failed to write one of the calib objects to the AMORE database\n"); + printf("TPCCEda: Waring: Failed to write one of the calib objects to the AMORE database\n"); // reset env var if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig); if (grA) delete grA;