Changeset 92


Ignore:
Timestamp:
07/28/09 09:13:41 (15 years ago)
Author:
ogrimm
Message:
Added some configuration parameters. Log file written outside of repository.
Location:
drsdaq
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • drsdaq/DAQReadout.cc

    r89 r92  
    1212#include "SlowData.h"
    1313
    14 #define TMPNAME "/tmp/__tmp__drsdaq__"
     14#define TMPNAME "/tmp/__tmp__drsdaq__"  // ..for log file truncation
    1515
    1616static const char* daq_state_str[] = {"active", "stopped"};
     
    2626   {"status", &DAQReadout::cmd_status, false, "[daq|drs]", "Show DAQ/DRS status information"},
    2727   {"freq", &DAQReadout::cmd_freq, true, "<GHz> [reg]", "Set DRS sampling frequency (regulated)"},
    28    {"calib", &DAQReadout::cmd_calib, true, "<t_f> <c_f> [dir]", "Response calibration"},
     28   {"calib", &DAQReadout::cmd_calib, true, "<t_f> <c_f>", "Response calibration"},
    2929   {"trigger", &DAQReadout::cmd_trigger, true, "<on|off>", "Hardware trigger on or off"},
    3030   {"delayed", &DAQReadout::cmd_delayed, true, "<on|off>", "Switch delayed start on or off"},
     
    7676  LastBoard          = -1;
    7777  CmdFromSocket      = false;
    78      
    79   // Read configuration file
     78  ConfigOK           = true;
     79 
     80  // Read configuration file (if any item missing, program will be terminated in main() routine)
    8081  FILE *File;
    8182  if ((File = fopen(Configfile,"r")) == NULL) {
    8283    printf("Error: Could not open drsdaq configuration file '%s'\n", Configfile);
     84    ConfigOK = false;
     85    return;
    8386  }
    8487  else {
    8588    printf("Reading drsdaq configuration file %s\n", Configfile);
    86     ReadCard("LogFile",             fLogFile,           's', File);
    87     ReadCard("MaxLogLines",        &fMaxLogLines,       'U', File);
    88     ReadCard("RawDataPath",         fRawDataPath,       's', File);
    89     ReadCard("FirstSample",        &fFirstSample,       'I', File);
    90     ReadCard("Samples",            &fSamples,           'U', File);
    91     ReadCard("MinDiskSpaceMB",     &fMinDiskSpaceMB,    'U', File);
    92     ReadCard("MaxFileSizeMB",      &fMaxFileSizeMB,     'I', File);
    93     ReadCard("CCPort",             &fCCPort,            'I', File);
    94     ReadCard("FirstVMESlot",       &fFirstVMESlot,      'I', File);
    95     ReadCard("LastVMESlot",        &fLastVMESlot,       'I', File);
    96     ReadCard("HVFeedbackConfig",    fHVFeedbackConfig,  's', File);
     89    ConfigOK &= ReadCard("LogFile",             fLogFile,           's', File);
     90    ConfigOK &= ReadCard("SlowDataPath",        fSlowDataPath,      's', File);
     91    ConfigOK &= ReadCard("MaxLogLines",        &fMaxLogLines,       'U', File);
     92    ConfigOK &= ReadCard("RawDataPath",         fRawDataPath,       's', File);
     93    ConfigOK &= ReadCard("FirstSample",        &fFirstSample,       'I', File);
     94    ConfigOK &= ReadCard("Samples",            &fSamples,           'U', File);
     95    ConfigOK &= ReadCard("MinDiskSpaceMB",     &fMinDiskSpaceMB,    'U', File);
     96    ConfigOK &= ReadCard("MaxFileSizeMB",      &fMaxFileSizeMB,     'I', File);
     97    ConfigOK &= ReadCard("CCPort",             &fCCPort,            'I', File);
     98    ConfigOK &= ReadCard("FirstVMESlot",       &fFirstVMESlot,      'I', File);
     99    ConfigOK &= ReadCard("LastVMESlot",        &fLastVMESlot,       'I', File);
     100    ConfigOK &= ReadCard("HVFeedbackConfig",    fHVFeedbackConfig,  's', File);
     101    ConfigOK &= ReadCard("DefaultFrequency",   &fDefaultFrequency , 'd', File);
    97102    fclose(File);
     103    if (!ConfigOK) return;
    98104  }
    99105  if (fFirstSample < 0 || fFirstSample > kNumberOfBins || fSamples > kNumberOfBins) {
     
    108114  if (system(ShellCmd) != 0) printf("Warning: Could not truncate log file '%s' to %u lines\n", fLogFile, fMaxLogLines);
    109115
    110   // Open log file
     116  // Open log file and log configuration
    111117  if ((Logfile = fopen(fLogFile, "a")) == NULL) printf("Warning: Could not open log file '%s'\n", fLogFile);
    112118  PrintMessage(MsgToLog,"********** Logging started **********\n");
    113  
    114   // Print configuration
    115   cmd_config();
     119  PrintConfig(MsgToLog);
    116120
    117121  // Create DRS instance and perform initial scan
     
    151155 
    152156  // Create instance of slow data class for DAQ
    153   char Filename[MAX_PATH];
    154   snprintf(Filename,sizeof(Filename),"%s/SlowData/", fRawDataPath);
    155   SlowDataClass = new SlowData("DAQ", Filename);
     157  SlowDataClass = new SlowData("DAQ", fSlowDataPath);
    156158  if(SlowDataClass->ErrorCode != 0) {
    157159   PrintMessage("Warning: Could not open DAQ slowdata file (%s)\n", strerror(SlowDataClass->ErrorCode));
    158160  }
     161  SlowDataClass->NewEntry("Runinfo-Info", "Run information written after completion or termination of run (Status can be OK or Error): Runnumber Status Runtype Events Files Description ");
    159162}
    160163
     
    170173  delete[] WaveForm;  delete[] TriggerCell;
    171174 
    172   PrintMessage(MsgToLog,"********** Logging ended **********\n\n");
    173175  if(Logfile) {
    174176    if(!fclose(Logfile)) printf("Closing logfile\n");
     
    224226// Print DAQ configuration
    225227void DAQReadout::cmd_config() {
    226   PrintMessage("LogFile: %s\tMaxLogLines: %u\tRawDataPath: %s\n"
    227                "FirstSample: %d\tSamples: %u\n"
    228                "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\tCCPort: %d\n"
    229                "FirstVMESlot: %d\t\tLastVMESlot: %d\n"
    230                "HVFeedbackConfig: %s\n",
    231     fLogFile,fMaxLogLines,fRawDataPath,fFirstSample,fSamples,fMinDiskSpaceMB,
    232     fMaxFileSizeMB,fCCPort,fFirstVMESlot,fLastVMESlot,fHVFeedbackConfig);
     228  PrintConfig(CmdFromSocket ? MsgToSocket : MsgToConsole);
    233229}
    234230
     
    241237      return;
    242238    }
    243     if (!IsDRSFreqSet()) return;
     239    if (!IsDRSFreqSet()) {
     240      PrintMessage("Setting default frequency\n");
     241      SetDRSFrequency(fDefaultFrequency, false);
     242      CalibrationRead = false;
     243    }
     244   
    244245    if (!CalibrationRead && !ReadCalibration()) {
    245246      PrintMessage("Cannot start run if response calibration not read.\n");
     
    445446// Do internal calibration
    446447void DAQReadout::cmd_calib() {
    447   if (NParam==4 && atof(Param[1]) && atof(Param[2]))
    448     CalibrateDRS((char *) Param[3],atof(Param[1]),atof(Param[2]));
    449   else if (NParam==3 && atof(Param[1]) && atof(Param[2]))
    450     CalibrateDRS(NULL,atof(Param[1]),atof(Param[2]));
    451   else PrintUsage();
     448  char str[MAX_COM_SIZE];
     449
     450  if (NParam!=3 || !atof(Param[1]) || !atof(Param[2])) {
     451    PrintUsage();
     452    return;
     453  }
     454     
     455  getcwd(str, sizeof(str));
     456  strcat(str,"/calib");
     457  PrintMessage("Writing calibration data to directory '%s'\n",str);
     458
     459  for (int i=FirstBoard; i<=LastBoard; i++) {
     460    drs->GetBoard(i)->Init();
     461    drs->GetBoard(i)->SetFrequency(atof(Param[2]));
     462    drs->GetBoard(i)->SoftTrigger();
     463
     464    PrintMessage("Creating calibration of board %d (%d)\n", i, drs->GetBoard(i)->GetCMCSerialNumber());
     465
     466    drs->GetBoard(i)->EnableTcal(1);
     467    PrintMessage("Tcal enabled\n");
     468
     469    if (drs->GetBoard(i)->GetChipVersion() == 3) drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,21,0,20,0,0,0,0,0);
     470    else drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,36,110,20,19,40,15,atof(Param[1]),0);
     471    drs->GetBoard(i)->SetCalibrationDirectory(str);
     472
     473    for (int j=0; j<2; j++) {
     474      drs->GetBoard(i)->GetResponseCalibration()->ResetCalibration();
     475      PrintMessage("Calibration reset done.\n");
     476
     477      while (!drs->GetBoard(i)->GetResponseCalibration()->RecordCalibrationPoints(j)) {}
     478      PrintMessage("Record calibration points done.\n");
     479      while (!drs->GetBoard(i)->GetResponseCalibration()->FitCalibrationPoints(j)) {}
     480      PrintMessage("Calibration points fitted.\n");
     481      while (!drs->GetBoard(i)->GetResponseCalibration()->OffsetCalibration(j)) {}
     482      PrintMessage("Offset calibration done.\n");
     483
     484      if (!drs->GetBoard(i)->GetResponseCalibration()->WriteCalibration(j)) break;
     485    }       
     486    drs->GetBoard(i)->Init(); // Reset linear range -0.2 ... 0.8 V
     487  } // Loop over boards
    452488}
    453489
     
    650686// Print feedback configuration
    651687void DAQReadout::cmd_fconfig() {
    652   HVFB->PrintConfig();
     688  HVFB->PrintConfig(CmdFromSocket ? MsgToSocket : MsgToConsole);
    653689}
    654690
     
    799835}
    800836
    801 // Do internal calibration
    802 void DAQReadout::CalibrateDRS(char *dir, double trigfreq, double calibfreq) {
    803 
    804   int i,j;
    805   char str[MAX_COM_SIZE];
    806   DIR *pdir;
    807      
    808   if (NumBoards) {
    809     if(dir!=NULL) {
    810       if ((pdir=opendir(str))==0){
    811         PrintMessage("Error: target directory \"%s\" does not exist!\n",str);
    812         return;
    813       }
    814       closedir(pdir);
    815       snprintf(str,sizeof(str),"%s",dir);
    816       PrintMessage("Target: \"%s\"\n",str);
    817     }
    818     else {
    819       getcwd(str, sizeof(str));
    820       strcat(str,"/calib");
    821       PrintMessage("Taking default target: \"%s/\"\n",str);
    822     }
    823        
    824     for (i=FirstBoard; i<=LastBoard; i++) {
    825       drs->GetBoard(i)->Init();
    826       drs->GetBoard(i)->SetFrequency(calibfreq);
    827       drs->GetBoard(i)->SoftTrigger();
    828            
    829       PrintMessage("Creating calibration of board %d\n", drs->GetBoard(i)->GetCMCSerialNumber());
    830 
    831       drs->GetBoard(i)->EnableTcal(1);
    832       PrintMessage("Tcal enabled");
    833 
    834       if (drs->GetBoard(i)->GetChipVersion() == 3)
    835         drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,21,0,20,0,0,0,0,0);
    836       else
    837         drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,36,110,20,19,40,15,trigfreq,0);
    838            
    839       drs->GetBoard(i)->SetCalibrationDirectory(str);
    840       PrintMessage("Storage directory \"%s\"\n",str);
    841 
    842       for (j=0;j<2;j++) {
    843         drs->GetBoard(i)->GetResponseCalibration()->ResetCalibration();
    844         PrintMessage("Calibration reset done.\n");
    845 
    846         while (!drs->GetBoard(i)->GetResponseCalibration()->RecordCalibrationPoints(j)) {}
    847         PrintMessage("Record calibration points done.\n");
    848         while (!drs->GetBoard(i)->GetResponseCalibration()->FitCalibrationPoints(j)) {}
    849         PrintMessage("Calibration points fitted.\n");
    850         while (!drs->GetBoard(i)->GetResponseCalibration()->OffsetCalibration(j)) {}
    851         PrintMessage("Offset calibration done.\n");
    852 
    853         if (!drs->GetBoard(i)->GetResponseCalibration()->WriteCalibration(j))
    854           break;
    855       }       
    856       drs->GetBoard(i)->Init(); // Reset linear range -0.2 ... 0.8 V
    857     } // Loop over boards   
    858   }
    859   else PrintMessage("No DRS boards available\n");
    860 }
    861 
    862837// Check if DRS is sampling
    863838bool DAQReadout::IsDRSBusy() {
     
    871846bool DAQReadout::IsDRSFreqSet() {
    872847
    873   for (int i=FirstBoard;i<=LastBoard;i++)
     848  for (int i=FirstBoard; i<=LastBoard; i++)
    874849    if (DRSFreq[i]==0) {
    875850      PrintMessage("DRS sampling frequency of board %d not set!\n",i);
     
    992967}
    993968
    994 // Write event header
    995 bool DAQReadout::WriteEventHeader() {
    996 
     969// Write event
     970bool DAQReadout::WriteEvent() {
     971
     972  // Event header
    997973  struct timeval Time;
    998974
     
    1000976 
    1001977  EHeader->EventNumber = NumEvents;
    1002   EHeader->TriggerType = (daq_runtype == data) ? 1 : 0;
     978  EHeader->TriggerType = daq_runtype==data ? 0 : 1;
    1003979  EHeader->Second = Time.tv_sec;
    1004980  EHeader->Microsecond = Time.tv_usec;
     
    1010986    return false;
    1011987  }
    1012   return true;
    1013 }
    1014 
    1015 // Write event data (It is required that at least three chunks can be written with writev(), therefore
    1016 // IOV_MAX>=3 is checked at startup
    1017 bool DAQReadout::WriteEventData() {
    1018 
     988 
     989  // Event data (It is required that at least three chunks can be written with writev(), therefore
     990  // IOV_MAX>=3 is checked at startup
     991 
    1019992  unsigned int Start, Count = 0;
    1020993  ssize_t WriteResult, Size = 0;
     
    1022995
    1023996  // First chunk: trigger cells
    1024   DataPart[Count].iov_base = TriggerCell + FirstBoard*kNumberOfChips;
     997  DataPart[Count].iov_base = (char *) TriggerCell + FirstBoard*kNumberOfChips*sizeof(int); // TriggerCell is without cast a pointer to an 8-byte unit (two ints) !
    1025998  DataPart[Count++].iov_len = RHeader->NBoards * kNumberOfChips * sizeof(int);
    1026999  Size += DataPart[Count-1].iov_len;
     
    10541027    } // Chips
    10551028  } // Boards
     1029 
    10561030  return true;
     1031}
     1032
     1033// Print configuration to target
     1034void DAQReadout::PrintConfig(int Target) {
     1035  PrintMessage(Target, "LogFile: %s\tMaxLogLines: %u\tRawDataPath: %s\n"
     1036               "DefaultFrequency: %.2f\tFirstSample: %d\tSamples: %u\n"
     1037               "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\tCCPort: %d\n"
     1038               "FirstVMESlot: %d\t\tLastVMESlot: %d\n"
     1039               "SlowDataPath: %s\tHVFeedbackConfig: %s\n",
     1040    fLogFile,fMaxLogLines,fRawDataPath,fDefaultFrequency,fFirstSample,fSamples,fMinDiskSpaceMB,
     1041    fMaxFileSizeMB,fCCPort,fFirstVMESlot,fLastVMESlot,fSlowDataPath,fHVFeedbackConfig);
    10571042}
    10581043
     
    12381223      else if (m->daq_runtype == pedestal) m->StopDRS();   // ..or for software trigger
    12391224
    1240       EventsInFile++;      m->NumEvents++;     
    1241       WriteError |= !m->WriteEventHeader();
    1242 
    12431225      // Read event data via VME or generate test data (for one board if no boards available)
    12441226      if (m->daq_runtype != test) {
     
    12521234      }
    12531235
    1254       // Write data to disk and update file size
    1255       WriteError |= !m->WriteEventData();
     1236      // Write event to disk and update file size
     1237      EventsInFile++;      m->NumEvents++;     
     1238      WriteError |= !m->WriteEvent();
    12561239
    12571240      if((FileSize = lseek(m->Rawfile, 0, SEEK_CUR)) == -1) {
     
    12731256  } while((m->NumEvents<m->NumEventsRequested || m->NumEventsRequested==0) && !m->Stop && !WriteError);
    12741257
    1275   // Print run summary to slow data file and to screen
    12761258  m->StopDRS();
    1277   if(!WriteError) {
    1278     m->PrintMessage("\rRun #%d (%s) %s, %d events\n",m->RunNumber,daq_runtype_str[m->daq_runtype],(m->NumEvents == m->NumEventsRequested) ? "completed":"stopped",m->NumEvents);
    1279     m->SlowDataClass->NewEntry("Runinfo");
    1280     m->SlowDataClass->AddToEntry("%d %s %s %d %d", m->RunNumber, daq_runtype_str[m->daq_runtype], m->RHeader->Description, m->NumEvents, m->FileNumber);
    1281     if(m->SlowDataClass->ErrorCode != 0) {
    1282       m->PrintMessage("Error, could not write DAQ data to file (%s), file closed\n", strerror(m->SlowDataClass->ErrorCode));
    1283     }
    1284 
    1285   }
     1259 
     1260  // Print run summary to screen
     1261  if(!WriteError) m->PrintMessage("\rRun #%d (%s) %s, %d events\n",m->RunNumber,daq_runtype_str[m->daq_runtype],(m->NumEvents == m->NumEventsRequested) ? "completed":"stopped",m->NumEvents);
    12861262  else m->PrintMessage("\rRun #%d (%s) aborted due to error after %d events\n",m->RunNumber,daq_runtype_str[m->daq_runtype],m->NumEvents);
     1263
     1264  // Write run summary to slow data file
     1265  m->SlowDataClass->NewEntry("Runinfo");
     1266  m->SlowDataClass->AddToEntry("%d %s %s %d %d %s", m->RunNumber, WriteError?"Error":"OK", daq_runtype_str[m->daq_runtype], m->NumEvents, m->FileNumber, m->RHeader->Description);
     1267  if(m->SlowDataClass->ErrorCode != 0) {
     1268    m->PrintMessage("Error, could not write DAQ data to file (%s), file closed\n", strerror(m->SlowDataClass->ErrorCode));
     1269  }
    12871270
    12881271  // Print run statistics
  • drsdaq/DAQReadout.h

    r68 r92  
    5454    // Configuration data
    5555    char fLogFile[MAX_PATH];
     56    char fSlowDataPath[MAX_PATH];
    5657    unsigned int fMaxLogLines;
    5758    char fRawDataPath[MAX_PATH];
     
    6465    int fFirstVMESlot;
    6566    char fHVFeedbackConfig[MAX_PATH];
     67    double fDefaultFrequency;
    6668   
    6769    // Status variables   
     
    8587    char FileName[MAX_PATH];
    8688    char Prompt[MAX_COM_SIZE];
    87    
     89    bool ConfigOK;
     90       
    8891    // Public functions
    8992    DAQReadout(const char*);
     
    114117    bool IsDRSFreqSet();
    115118    void SetDRSFrequency(double, bool);
    116     void CalibrateDRS(char*, double, double);
    117119    void SetDOMINOMode(int);
    118120    void SetDOMINOReadMode(int);
     
    123125    bool IsCalibrationRead();
    124126    void ReadCalibratedDRSData();
     127    void PrintConfig(int);
    125128    void PrintMessage(int, const char*, ...);
    126129    void PrintMessage(const char*, ...);
     
    129132    bool WriteRunHeader();
    130133    bool UpdateRunHeader(unsigned int, bool);
    131     bool WriteEventHeader();
    132     bool WriteEventData();
     134    bool WriteEvent();
    133135};
    134136
  • drsdaq/HVFeedback.cc

    r89 r92  
    2424HVFeedback::HVFeedback(DAQReadout* DAQClass, char* Configfile) {
    2525  struct sockaddr_in SocketAddress;
    26   char Filename[MAX_PATH];
    2726
    2827  m = DAQClass;
     
    3029
    3130  // Create instance of slow data class for feedback
    32   snprintf(Filename,sizeof(Filename),"%s/SlowData/", m->fRawDataPath);
    33   SlowDataClass = new SlowData("HVFB", Filename);
     31  SlowDataClass = new SlowData("HVFB", m->fSlowDataPath);
    3432  if (SlowDataClass->ErrorCode != 0) {
    3533    m->PrintMessage("Warning: Could not open feedback slowdata file (%s)\n", strerror(SlowDataClass->ErrorCode));
    3634  }
     35  SlowDataClass->NewEntry("Average-Info", "Feedback regulation occurred: Board Chip Channel Average Sigma Correction-Value");
     36  SlowDataClass->NewEntry("Target-Info", "New Target values acquired: Board Chip Channel Target Sigma");
     37  SlowDataClass->NewEntry("Response-Info", "New response measurement: Board Chip Channel Response");
    3738
    3839  // Initialise with zero content
     
    6566    fclose(File);
    6667  }
    67   PrintConfig();
     68  PrintConfig(MsgToLog);
    6869 
    6970  // Initial state
     
    373374// Print feedback configuration
    374375//
    375 void HVFeedback::PrintConfig() {
    376   m->PrintMessage("LedTrigBoard: %d\t\tLedTrigChip: %d\t\tLedTrigChannel: %d\n"
     376void HVFeedback::PrintConfig(int Target) {
     377  m->PrintMessage(Target, "LedTrigBoard: %d\t\tLedTrigChip: %d\t\tLedTrigChannel: %d\n"
    377378        "LedTrigSample: %d\tLedTrigThreshold: %.2f\n"
    378379        "LedSignalSample: %d\tLedBaselineSample: %d\tDefaultNumAverage: %d\n"
  • drsdaq/HVFeedback.h

    r36 r92  
    6464    void ClearAverages();
    6565    bool WriteHVCommand(const char *, ...);
    66     void PrintConfig();
     66    void PrintConfig(int);
    6767};
    6868
  • drsdaq/History.txt

    r86 r92  
    414118/6/2009   Run date is now calculated with a change to the next date on 13:00 UTC.
    42429/7/2009    SlowData class is now independet of PrintMessage() method, thus more
    43             universal       
     43            universal
     4414/7/2009   Fixed assignment of trigger type in event header (now 0  is hardware
     45            trigger, 1 software trigger). Fixed pointer-arithmetic for trigger cell
     46            writing if first board written to disk is not physically first board.           
     4728/7/2009   Added configuration parameters SlowDataPath and DefaultFrequency. All
     48            configuration parameters are now mandatory: if one is not found, the
     49            program terminates.
  • drsdaq/SlowData.cc

    r87 r92  
    33  SlowData.cc
    44
    5   Class handling the writing of slow data. String to be written in the
     5  Class handling the writing of slow data. Strings to be written in the
    66  slow data file are checked that they do not contain control characters.
     7 
     8  1. Call constructor with desired identification and directory
     9     for slow data file. The public ErrorCode variable will be zero
     10     if successful, otherwise contain the relevant errno.
     11  2. Use NewEntry() to start a new entry with given variable name. A text
     12     as second argument is optional.
     13  3. If text should be added to an open entry, use AddToEntry(). It can
     14     process printf()-style formatting.
     15  4. The slow data file will be closed upon destruction of the instance. 
    716   
    817  Oliver Grimm
     
    4554// Add a new entry to slow data file
    4655//
    47 bool SlowData::NewEntry(const char *Variable) {
     56bool SlowData::NewEntry(const char *Variable, const char *Text) {
    4857
    4958  time_t RawTime;
     
    5766  NewEntryCalled = AddToEntry("\n%s %s %d %d %d %d %d %d %d %lu ", Issuer, Variable, TM->tm_year+1900,TM->tm_mon+1,TM->tm_mday,TM->tm_hour,TM->tm_min,TM->tm_sec, Time.tv_usec/1000, Time.tv_sec);
    5867  InternalCall = false;
     68  if(Text != NULL && NewEntryCalled == true) NewEntryCalled = AddToEntry("%s", Text);
     69
    5970  return NewEntryCalled;
    6071}
     
    6576bool SlowData::AddToEntry(const char *Format, ...) {
    6677
    67   char Textbuffer[MAX_COM_SIZE];
     78  char Textbuffer[MAX_ENTRY_SIZE];
    6879  va_list ArgumentPointer;
    6980
  • drsdaq/SlowData.h

    r87 r92  
    1212
    1313#define MAX_PATH 256
    14 #define MAX_COM_SIZE 10000
     14#define MAX_ENTRY_SIZE 10000
    1515
    1616class SlowData {
     
    2626
    2727    int ErrorCode;      // Set to errno if an error occured, zero otherwise
    28     bool NewEntry(const char*);
     28    bool NewEntry(const char*, const char* = NULL);
    2929    bool AddToEntry(const char*, ...);
    3030};
  • drsdaq/drsdaq.cpp

    r63 r92  
    8585  signal(SIGHUP, &CrashHandler);
    8686   
    87   // Construct main instance
     87  // Construct main instance and create mutex for thread synchronization
    8888  DAQReadout dreadout(argc==3 ? argv[2] : DEFAULT_CONFIG);
    89 
    90   // Create threads and mutex for thread synchronization
    9189  if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) {
    9290    perror("pthread_mutex_init failed");
    9391    throw;
    9492  }
    95   if ((pthread_create(&thread_ConsoleCommand, NULL, (void * (*)(void *)) ConsoleCommand,(void *) &dreadout)) != 0) {
    96     perror("pthread_create failed with console thread");
    97     throw;
    98   }
    99   if ((pthread_create(&thread_CCCommand, NULL, (void * (*)(void *)) CCCommand,(void *) &dreadout)) != 0) {
    100     perror("pthread_create failed with socket thread");
    101     dreadout.SocketThread = NULL;
    102   }
    103   else dreadout.SocketThread = &thread_CCCommand;  // Thread should be accessible for sending signals 
    104  
    105   // Wait for threads to quit
    106   pthread_join(thread_ConsoleCommand, NULL);
    107   if(dreadout.SocketThread != NULL) pthread_join(thread_CCCommand, NULL);
    108 
     93
     94  if (dreadout.ConfigOK) { // Normal program execution only if configuration was complete
     95    // Create threads
     96    if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) {
     97      perror("pthread_mutex_init failed");
     98      throw;
     99    }
     100    if ((pthread_create(&thread_ConsoleCommand, NULL, (void * (*)(void *)) ConsoleCommand,(void *) &dreadout)) != 0) {
     101      perror("pthread_create failed with console thread");
     102      throw;
     103    }
     104    if ((pthread_create(&thread_CCCommand, NULL, (void * (*)(void *)) CCCommand,(void *) &dreadout)) != 0) {
     105      perror("pthread_create failed with socket thread");
     106      dreadout.SocketThread = NULL;
     107    }
     108    else dreadout.SocketThread = &thread_CCCommand;  // Thread should be accessible for sending signals 
     109
     110    // Wait for threads to quit
     111    pthread_join(thread_ConsoleCommand, NULL);
     112    if(dreadout.SocketThread != NULL) pthread_join(thread_CCCommand, NULL);
     113  }
     114  else printf("Error: Configuration parameter missing in %s, terminating.\n", argc==3 ? argv[2] : DEFAULT_CONFIG);
     115 
    109116  // Destruct mutex and main instance
    110117  pthread_mutex_destroy (&dreadout.control_mutex);
     
    135142 
    136143  while (!m->Exit) {
     144 
     145    // Assemble prompt
    137146    if (m->NumBoards == 0) snprintf(m->Prompt,sizeof(m->Prompt),"\rDAQ> ");
    138147    else if (m->FirstBoard == m->LastBoard) snprintf(m->Prompt,sizeof(m->Prompt),"\rDAQ|B%d> ",m->FirstBoard);
    139148    else snprintf(m->Prompt,sizeof(m->Prompt),"\rDAQ|B%d-%d> ",m->FirstBoard,m->LastBoard);
    140149
     150    // Read Command
    141151    Command = readline(m->Prompt);
    142152    if (Command==NULL) {
     
    144154      continue;
    145155    }
    146 
    147156    if(strlen(Command)>0) add_history(Command);
    148157
     158    // Log command
    149159    strftime(Buf,MAX_COM_SIZE, "%d/%m/%y %X", localtime(&(Time=time(NULL))));
    150160    m->PrintMessage(MsgToLog, "CONSOLE(%s)> %s\n", Buf, Command);
     
    199209  SocketAddress.sin_port = htons((unsigned short) m->fCCPort);
    200210  SocketAddress.sin_addr.s_addr = INADDR_ANY;
     211
    201212  if (bind(ServerSocket, (struct sockaddr *) &SocketAddress, sizeof(SocketAddress)) == -1)
    202213  {
     
    223234    m->Socket = ConnectionSocket;
    224235
    225     while (!m->Exit) { // Looping as long as client exists
     236    // Looping as long as client exists and program not terminated
     237    while (!m->Exit) {
     238
     239      // Try to read command from socket
    226240      memset(Command,0,sizeof(Command));
    227241      ReadResult = read(ConnectionSocket, Command, MAX_COM_SIZE);
     
    233247      if (Command[strlen(Command)-1]=='\n') Command[strlen(Command)-1]='\0';  // Remove trailing newline
    234248     
     249      // Log command
    235250      strftime(Buf, MAX_COM_SIZE, "%d/%m/%y %X", localtime(&(Time=time(NULL))));
    236251      m->PrintMessage(MsgToConsole|MsgToLog, "SOCKET(%s)> %s\n", Buf, Command);
     
    238253      // Process command     
    239254      pthread_mutex_lock(&m->control_mutex);
    240       m->CmdFromSocket = true;       
     255      m->CmdFromSocket = true;
    241256      m->CommandControl(Command);
    242       m->CmdFromSocket = false; 
     257      m->CmdFromSocket = false;
    243258      pthread_mutex_unlock(&m->control_mutex);
    244259    }
     260
    245261    m->Socket = -1;
    246262    m->PrintMessage("Disconnected from client.\n");
Note: See TracChangeset for help on using the changeset viewer.