Low-Energy Muon (LEM) Experiment  0.5.2
analyzer.cxx
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: analyzer.cxx
4  Created by: Thomas Prokscha, 14-May-2004
5  Andreas Suter, 08-March-2012 Adopted to MusrRoot
6  Zaher Salman 18-March-2012 Added LEM spin rotator
7  Andreas Suter, 17-Jan-2020 Moved from c to cxx and cleaned up
8 
9  Contents: System part of Analyzer code for LEM experiment.
10  Sep/2006: save histograms every
11  "HISTOGRAM_WRITE_PERIOD" s (300sec at the moment).
12 
13  The module creates the /Info structure in ODB that contains
14  important information for the LEM experiment.
15  Additional functions to write histogram files, histograms
16  file header generation:
17 
18  write_histogram_file();
19  get_sum_filename(char *filename);
20  extract_summary_data(); // from .summ files
21  update_info(); // update t0's, energy loss, B-field, LEM setup
22  update_run_header();
23  energy_loss(float moderator_hv); // calculate energy loss in C-foil according to a 3rd order polynomial
24  get_magnetic_field(float current); // calculate magnetic field at sample from ZeroFlux reading according
25  // to magnet chosen (WEW or Bpar)
26  get_t0(); // scale t0's with 1/sqrt(E), starting at t0(12kV) and with TOF(12kV)
27  get_t0L3RA(); // scale t0 as a function of L3 and TD potentials
28  receive_message(...) // receive alarm message; if enabled sent warning as SMS/EMail to user specified
29  // in /Info/Alarm Notification/Recipients
30  2009-06-20: disabled receive_message; sending SMS/e-mail nottifications now done
31  by extra Midas client send_message.
32  read_intel_log(INTEL_LOG *info) // read lem00 main board parameters (temperature, fan speed...) //as35, 2020-01-16 <- remove
33  update_t0shift() // update t0 shifts when changing from Bpar to WEW setup
34  beam_shutter_open(HNDLE hDB) // check beam shutter position on run start and run resume and give a
35  // warning if still closed
36  set_spin_rot_angle() // using the angle parameter and moderator energy calculate and set appropriate SR
37  // magnet current and plates potential
38 
39 
40 ********************************************************************/
41 
42 #include <vector>
43 
44 // standard includes
45 #include <cstdio>
46 #include <cstring>
47 #include <ctime>
48 #include <cstdlib>
49 #include <unistd.h>
50 
51 // midas includes
52 #include "midas.h"
53 #include "experim.h"
54 #include "nemu_experim.h"
55 
56 // root includes
57 #include <TROOT.h>
58 #include <TSystem.h>
59 #include <TMath.h>
60 #include <TH1F.h>
61 #include <TH2F.h>
62 #include <TTree.h>
63 #include <TDirectory.h>
64 #include <TFile.h>
65 //as #include <TLemRunHeader.h>
66 #include <TMusrRunHeader.h>
67 
68 //-- Globals -------------------------------------------------------
69 
70 // The analyzer name (client name) as seen by other MIDAS clients
71 const char *analyzer_name = "Analyzer";
72 
73 // analyzer_loop is called with this interval in ms (0 to disable)
75 
76 // default ODB size
77 INT odb_size = DEFAULT_ODB_SIZE;
78 
79 char runname[256];
83 RUNINFO runinfo;
88 RATE_BANK_STR(rate_bank_str);
90 SRAT_BANK_STR(srat_bank_str);
92 POSI_BANK_STR(posi_bank_str);
96 // SCS900_EVENT scs900_event;
98 
101 extern MEAN_BANK mean;
102 
105 
106 extern TFolder *gManaHistosFolder;
107 static TFolder *gRunHeader = NULL;
108 //as static TLemRunHeader *header = NULL;
109 static TMusrRunHeader *header = NULL;
110 static TObjArray Slist(0);
111 
112 static DWORD last_histogram_write;
114 #define HISTOGRAM_WRITE_PERIOD 300 // write histograms every 300s to file
115 #define UPDATE_INFO_PERIOD 5 // update info structure with eloss and B-field every 5sec
116 #define UPDATE_INFO_PERIOD_IPMI 300 // update lemXX ipmi log info structure every 300s
117 static INT write_flag;
118 static INT sum_count;
119 
120 static float rotation_angle; // spin rotation angle hotlink variable
121 
122 //-- Module declarations -------------------------------------------
126 extern ANA_MODULE decay_ana_module;
127 extern ANA_MODULE tof_ana_module;
128 extern ANA_MODULE pileup_ana_module;
129 extern ANA_MODULE mcp1_ana_module;
130 extern ANA_MODULE scaler_rate_sum;
131 extern ANA_MODULE sc_ana_module;
132 
133 ANA_MODULE *trigger_module[] = {
138  NULL
139 };
140 
141 ANA_MODULE *scaler_module[] = {
143  NULL
144 };
145 
146 ANA_MODULE *sc_module[] = {
147  &sc_ana_module,
148  NULL
149 };
150 
151 //-- Bank definitions ----------------------------------------------
158 BANK_LIST trigger_bank_list[] = {
159  // online banks
160  { "TDC0", TID_DWORD},
161 
162  // calculated banks
163  { "POSI", TID_STRUCT, sizeof(posi_bank), (char **)posi_bank_str },
164  { "" },
165 };
166 
167 BANK_LIST scaler_bank_list[] = {
168  // online banks
169  { "SCL0", TID_DWORD},
170 
171  // calculated banks
172  { "SSUM", TID_DOUBLE},
173  { "RATE", TID_STRUCT, sizeof(rate_bank), (char **)rate_bank_str },
174  { "SRAT", TID_STRUCT, sizeof(srat_bank), (char **)srat_bank_str },
175  { "RAAV", TID_INT},
176  { "" },
177 };
178 
179 BANK_LIST sc_bank_list[] = {
180  { "DBEA", TID_FLOAT},
181  { "MBEA", TID_FLOAT},
182  { "MVAC", TID_FLOAT},
183  { "MMOD", TID_FLOAT},
184  { "MSAM", TID_FLOAT},
185  { "M900", TID_FLOAT},
186  { "MHVT", TID_FLOAT},
187  { "MHVD", TID_FLOAT},
188  { "MWAV", TID_DOUBLE},
189  // calculated banks
190  //{ "MEAN", TID_STRUCT, sizeof(mean_bank), mean_bank_str },
191  { "" },
192 };
193 
194 //-- Event request list --------------------------------------------
195 ANALYZE_REQUEST analyze_request[] = {
196  { "Trigger",
197  {1,
198  TRIGGER_ALL,
199  GET_ALL,
200  "SYSTEM",
201  TRUE,
202  "", "",},
203  NULL,
206  1000,
207  TRUE,
208  },
209 
210  { "Scaler",
211  {2,
212  TRIGGER_ALL,
213  GET_ALL,
214  "SYSTEM",
215  TRUE,
216  "", "",},
217  NULL,
218  scaler_module,
220  100,
221  },
222 
223  { "SlowControl",
224  {3,
225  TRIGGER_ALL,
226  GET_ALL,
227  "SYSTEM",
228  TRUE,
229  "", "",},
230  NULL,
231  sc_module,
232  sc_bank_list,
233  100,
234  },
235 
236  { "" }
237 };
238 
239 //-- functions ---------------------------------------------------
245 void get_sum_filename(char *filename);
246 void extract_summary_data();
247 void update_info();
248 void update_run_header();
249 INT beam_shutter_open(HNDLE hDB);
250 float energy_loss(float moderator_hv);
251 float get_magnetic_field(float current);
252 void get_t0();
253 void get_t0L3RA();
256 INT read_microwave_log(MICROWAVE_LOG *microwave_info);
257 void update_t0shift(INT dummy1, INT dummy2, void *dummy3);
258 void set_spin_rot_angle(INT hDB, INT hKey, void *dummy);
259 extern void disp_scaler(INT n);
260 
261 //-- Analyzer Init -------------------------------------------------
263 {
264  HNDLE hDB, hKey;
265  char str[80];
266  char fname[256], exp_name[32];
267  char lazy_fname[128];
268  INT size, status;
269  struct tm *tms; // for getting the year from the binary date
270  time_t now;
271  char timestr[32];
272  BOOL flag_Bpar,flag_spinrot;
273 
274  RUNINFO_STR(runinfo_str);
275  EXP_PARAM_STR(exp_param_str);
276  EXP_EDIT_STR(exp_edit_str);
277  SCALER_SETTINGS_STR(scaler_settings_str);
278  T0SHIFT_PARAM_STR(t0shift_param_str);
279  TDSAMPLETOF_PARAM_STR(tdsampletof_param_str);
280  INFO_STR(info_str);
281  MEAN_BANK_STR(mean_bank_str);
282 
283  //----------------------------------------------------------------
284  // open ODB structures
285  //----------------------------------------------------------------
286 
287  cm_get_experiment_database(&hDB, NULL);
288 
289  db_create_record(hDB, 0, "/Runinfo", strcomb(runinfo_str));
290  db_find_key(hDB, 0, "/Runinfo", &hKey);
291  if (db_open_record(hDB, hKey, &runinfo, sizeof(runinfo), MODE_READ, NULL, NULL) != DB_SUCCESS) {
292  cm_msg(MERROR, "analyzer_init", "Cannot open \"/Runinfo\" tree in ODB");
293  return 0;
294  }
295 
296  db_create_record(hDB, 0, "/Experiment/Run Parameters", strcomb(exp_param_str));
297  db_find_key(hDB, 0, "/Experiment/Run Parameters", &hKey);
298  if (db_open_record(hDB, hKey, &exp_param, sizeof(exp_param), MODE_READ, NULL, NULL) != DB_SUCCESS) {
299  cm_msg(MERROR, "analyzer_init", "Cannot open \"/Experiment/Run Parameters\" tree in ODB");
300  return 0;
301  }
302 
303  sprintf(str, "/Experiment/Name");
304  size = sizeof(exp_name);
305  if (db_get_value(hDB, 0, str, exp_name, &size, TID_STRING, TRUE) != DB_SUCCESS ) {
306  sprintf(exp_name, "nemu");
307  }
308 
309  db_create_record(hDB, 0, "/Experiment/Edit on start", strcomb(exp_edit_str));
310  db_find_key(hDB, 0, "/Equipment/Trigger/Settings", &hKey);
311  if (db_open_record(hDB, hKey, &trigger_settings, sizeof(trigger_settings), MODE_READ,
312  NULL, NULL) != DB_SUCCESS) {
313  cm_msg(MERROR, "analyzer_init", "Cannot open \"/Equipment/Trigger/Settings\" tree in ODB");
314  return 0;
315  }
316 
317  db_create_record(hDB, 0, "/Equipment/Scaler/Settings", strcomb(scaler_settings_str));
318  db_find_key(hDB, 0, "/Equipment/Scaler/Settings", &hKey);
319  if (db_open_record(hDB, hKey, &scaler_settings, sizeof(scaler_settings), MODE_READ,
320  NULL, NULL) != DB_SUCCESS) {
321  cm_msg(MERROR, "analyzer_init", "Cannot open \"/Equipment/Scaler/Settings\" tree in ODB");
322  return 0;
323  }
324 
325  if (db_find_key(hDB, 0, "/Equipment/Trigger/Vme_Statistics", &hKey))
326  db_open_record(hDB, hKey, &vme_stats, sizeof(vme_stats), MODE_READ, NULL, NULL);
327 
328 
329  // create t0Shift structure
330  sprintf(str, "/%s/Parameters/t0Shift", analyzer_name);
331  db_create_record(hDB, 0, str, strcomb(t0shift_param_str));
332  db_find_key(hDB, 0, str, &hKey);
333  if (db_open_record(hDB, hKey, &t0shift_param, sizeof(t0shift_param),
334  MODE_READ, NULL, NULL) != DB_SUCCESS) {
335  cm_msg(MERROR, "analyzer_init", "Cannot open \"%s\" tree in ODB", str);
336  return 0;
337  }
338 
339  // create TDSampleTOF structure
340  sprintf(str, "/%s/Parameters/TDSampleTOF", analyzer_name);
341  db_create_record(hDB, 0, str, strcomb(tdsampletof_param_str));
342  db_find_key(hDB, 0, str, &hKey);
343  if (db_open_record(hDB, hKey, &tdsampletof_param, sizeof(tdsampletof_param),
344  MODE_READ, NULL, NULL) != DB_SUCCESS) {
345  cm_msg(MERROR, "analyzer_init", "Cannot open \"%s\" tree in ODB", str);
346  return 0;
347  }
348 
349  //create /Info structure
350  db_create_record(hDB, 0, "/Info", strcomb(info_str));
351  db_find_key(hDB, 0, "/Info", &hKey);
352  if (db_open_record(hDB, hKey, &info, sizeof(info), MODE_READ, NULL, NULL) != DB_SUCCESS) {
353  cm_msg(MERROR, "analyzer_init", "Cannot open \"/Info\" tree in ODB");
354  return 0;
355  }
356 
357  db_find_key(hDB, 0, "/Info/LEM_Setup_Parameter/Bpar", &hKey);
358  if (db_open_record(hDB, hKey, &flag_Bpar, sizeof(BOOL), MODE_READ, &update_t0shift, NULL) != DB_SUCCESS) {
359  cm_msg(MERROR, "analyzer_init", "Cannot open /Info/LEM_Setup_Parameter/Bpar tree in ODB");
360  return 0;
361  }
362 
363  // spin rotator hotlinks on angle
364  db_find_key(hDB, 0, "/Info/SpinRot_Parameter/RotationAngle", &hKey);
365  if (db_open_record(hDB, hKey, &rotation_angle, sizeof(float), MODE_READ, &set_spin_rot_angle, NULL) != DB_SUCCESS) {
366  cm_msg(MERROR, "analyzer_init", "Cannot open /Info/SpinRot_Parameter/RotationAngle tree in ODB");
367  return 0;
368  }
369 
370  // open ODB records for use in TLemRunHeader and energy loss/B-field calculation
371  db_find_key(hDB, 0, "/Equipment/HV/Variables", &hKey);
372  if (db_open_record(hDB, hKey, &hv_event, sizeof(hv_event), MODE_READ, NULL, NULL) != DB_SUCCESS) {
373  cm_msg(MERROR, "analyzer_init", "Cannot open \"/Equipment/HV/Variables\" tree in ODB");
374  return 0;
375  }
376 
377 /*
378  db_find_key(hDB, 0, "/Equipment/SampleCryo/Variables", &hKey);
379  if (db_open_record(hDB, hKey, &samplecryo_event, sizeof(samplecryo_event),
380  MODE_READ, NULL, NULL) != DB_SUCCESS) {
381  cm_msg(MERROR, "analyzer_init", "Cannot open \"/Equipment/SampleCryo/Variables\" tree in ODB");
382  return 0;
383  }
384 
385  db_find_key(hDB, 0, "/Equipment/SCS900/Variables", &hKey);
386  if (db_open_record(hDB, hKey, &scs900_event, sizeof(scs900_event),
387  MODE_READ, NULL, NULL) != DB_SUCCESS) {
388  cm_msg(MERROR, "analyzer_init", "Cannot open \"/Equipment/SCS900/Variables\" tree in ODB");
389  return 0;
390  }
391 */
392  db_find_key(hDB, 0, "/Equipment/SCS2001M/Variables", &hKey);
393  if (db_open_record(hDB, hKey, &scs2001m_event, sizeof(scs2001m_event),
394  MODE_READ, NULL, NULL) != DB_SUCCESS) {
395  cm_msg(MERROR, "analyzer_init", "Cannot open \"/Equipment/SCS2001M/Variables\" tree in ODB");
396  return 0;
397  }
398 
399  db_create_record(hDB, 0, "/Equipment/SlowControl/Variables/MEAN", strcomb(mean_bank_str));
400  db_find_key(hDB, 0, "/Equipment/SlowControl/Variables/MEAN", &hKey);
401  if (db_open_record(hDB, hKey, &mean, sizeof(mean), MODE_READ, NULL, NULL) != DB_SUCCESS) {
402  cm_msg(MERROR, "analyzer_init", "Cannot open \"/Equipment/SlowControl/Variables/MEAN\" tree in ODB");
403  return 0;
404  }
405 
406  //----------------------------------------------------------------------
407  // reset SRAT bank
408  //----------------------------------------------------------------------
409 
410  if ( db_find_key(hDB, 0, "/Equipment/Scaler/Variables/SRAT", &hKey) == DB_SUCCESS ) {
411  memset(&srat_bank, 0, sizeof(srat_bank));
412  db_set_record(hDB, hKey, &srat_bank, sizeof(srat_bank), 0);
413  }
414 
415  //---------------------------------------------------------------------
416  //
417  // change filenames to lem%02d_%04d where %02d is replaced by the year
418  // modulo 100 (2001 becomes 01, for example).
419  //
420  // File names are presently in odb keys
421  //
422  // /Analyzer/Output/Filename ascii dump ??
423  // /Analyzer/Output/Histo Dump Filename hsn file
424  // /Lazy/Tape0/Settings/Filename format for tape backup of mid,odb,hsn,summ,rz files
425  // /Lazy/Tape1/Settings/Filename format - " -
426  // /Logger/ODB Dump file odb file
427  // /Logger/Channels/0/Settings/Filename mid file
428  //
429  // summ and rz files are generated in programs ../util/write_summary.c and
430  // ../util/data2ntp.c. Filenames to be changed there.
431  //---------------------------------------------------------------------
432 
433  if ( runinfo.online_mode == 1) {
434  time(&now);
435  tms = localtime(&now);
436 
437  sprintf(str, "/%s/Output/Filename", analyzer_name);
438  size = sizeof(fname);
439  /* check if entry exists, if yes, change */
440  if ( db_get_value(hDB, 0, str, fname, &size, TID_STRING, TRUE) == DB_SUCCESS ) {
441  sprintf(fname, "lem%02d_%%04d.asc", tms->tm_year%100);
442  db_set_value(hDB, 0, str, &fname, sizeof(fname), 1, TID_STRING);
443  }
444 
445  sprintf(str, "/%s/Output/Histo Dump Filename", analyzer_name);
446  size = sizeof(fname);
447 
448 #ifdef HAVE_HBOOK
449  if ( db_get_value(hDB, 0, str, fname, &size, TID_STRING, TRUE) == DB_SUCCESS ) {
450  // tms->tm_year yield "Year - 1900"
451  sprintf(fname, "../his/%04d/lem%02d_%%04d.hsn", tms->tm_year+1900, tms->tm_year%100);
452  db_set_value(hDB, 0, str, &fname, sizeof(fname), 1, TID_STRING);
453  }
454 #else
455  if ( db_get_value(hDB, 0, str, fname, &size, TID_STRING, TRUE) == DB_SUCCESS ) {
456  sprintf(fname, "../his/%04d/lem%02d_his_%%04d.root", tms->tm_year+1900, tms->tm_year%100);
457  db_set_value(hDB, 0, str, &fname, sizeof(fname), 1, TID_STRING);
458  }
459 #endif
460 
461  // Overwrite logger defaults for data directories and
462  // file names.
463  sprintf(str, "/Logger/Data dir");
464  size = sizeof(fname);
465  if ( db_get_value(hDB, 0, str, fname, &size, TID_STRING, FALSE) == DB_SUCCESS ) {
466  sprintf(fname, "/data/%s/dlog", exp_name);
467  db_set_value(hDB, 0, str, &fname, sizeof(fname), 1, TID_STRING);
468  }
469 
470  sprintf(str, "/Logger/ODB Dump File");
471  size = sizeof(fname);
472  if ( db_get_value(hDB, 0, str, fname, &size, TID_STRING, FALSE) == DB_SUCCESS ) {
473  sprintf(fname, "/data/%s/odb/%04d/lem%02d_%%04d.odb", exp_name, tms->tm_year+1900, tms->tm_year%100);
474  db_set_value(hDB, 0, str, &fname, sizeof(fname), 1, TID_STRING);
475  }
476 
477  sprintf(str, "/Logger/Channels/0/Settings/Filename");
478  size = sizeof(fname);
479  if ( db_get_value(hDB, 0, str, fname, &size, TID_STRING, FALSE) == DB_SUCCESS ) {
480  sprintf(fname, "lem%02d_%%04d", tms->tm_year%100);
481  db_set_value(hDB, 0, str, &fname, sizeof(fname), 1, TID_STRING);
482  }
483 
484  sprintf(str, "/Logger/History Dir");
485  sprintf(fname, "/data/%s/history", exp_name);
486  db_set_value(hDB, 0, str, &fname, sizeof(fname), 1, TID_STRING);
487 
488  sprintf(str, "/Logger/History Path");
489  sprintf(fname, "");
490  db_set_value(hDB, 0, str, &fname, sizeof(fname), 1, TID_STRING);
491 
492  sprintf(str, "/Logger/Elog Dir");
493  //sprintf(fname, "/home/%s/elog/LEM_Experiment", exp_name);
494  sprintf(fname, "/home/nemu/elog/LEM_Experiment");
495  db_set_value(hDB, 0, str, &fname, sizeof(fname), 1, TID_STRING);
496 
497 // for lazylogger, use filesize of 128 to agree with string lengths there
498  sprintf(str, "/Lazy/FTP/Settings/Filename format");
499  size = sizeof(lazy_fname);
500  if ( db_get_value(hDB, 0, str, lazy_fname, &size, TID_STRING, FALSE) == DB_SUCCESS ) {
501  sprintf(lazy_fname, "lem%02d_%%04d.root", tms->tm_year%100);
502  db_set_value(hDB, 0, str, &lazy_fname, size, 1, TID_STRING);
503  }
504  /*
505  sprintf(str, "/Lazy/Tape0/Settings/Filename format");
506  size = sizeof(lazy_fname);
507  if ( db_get_value(hDB, 0, str, lazy_fname, &size, TID_STRING, FALSE) == DB_SUCCESS ) {
508  sprintf(lazy_fname, "lem%02d_%%04d", tms->tm_year%100);
509  db_set_value(hDB, 0, str, &lazy_fname, size, 1, TID_STRING);
510  }
511  sprintf(str, "/Lazy/Tape0/Settings/HisFilename format");
512  size = sizeof(lazy_fname);
513  if ( db_get_value(hDB, 0, str, lazy_fname, &size, TID_STRING, FALSE) == DB_SUCCESS ) {
514  sprintf(lazy_fname, "lem%02d_his_%%04d", tms->tm_year%100);
515  db_set_value(hDB, 0, str, &lazy_fname, size, 1, TID_STRING);
516  }
517 
518  sprintf(str, "/Lazy/Tape1/Settings/Filename format");
519  size = sizeof(lazy_fname);
520  if ( db_get_value(hDB, 0, str, lazy_fname, &size, TID_STRING, FALSE) == DB_SUCCESS ) {
521  sprintf(lazy_fname, "lem%02d_%%04d", tms->tm_year%100);
522  db_set_value(hDB, 0, str, &lazy_fname, size, 1, TID_STRING);
523  }
524  sprintf(str, "/Lazy/Tape1/Settings/HisFilename format");
525  size = sizeof(lazy_fname);
526  if ( db_get_value(hDB, 0, str, lazy_fname, &size, TID_STRING, FALSE) == DB_SUCCESS ) {
527  sprintf(lazy_fname, "lem%02d_his_%%04d", tms->tm_year%100);
528  db_set_value(hDB, 0, str, &lazy_fname, size, 1, TID_STRING);
529  }
530  */
531  } /* if (runinfo.online_mode == 1) */
532 
533  // to create Run Name in histograms in analyzer modules
534  sprintf(str, "/%s/Output/Filename", analyzer_name);
535  size = sizeof(fname);
536  db_get_value(hDB, 0, str, fname, &size, TID_STRING, TRUE);
537  strcpy(runname, fname);
538  runname[5] = 0; // truncate run number and extension
539 
540  timestr[0] = 0;
541  sprintf(timestr, "%s", ctime(&now));
542  timestr[24] = 0; // delete new line \n
543  db_set_value(hDB, 0, "/Info/Scaler Update time", &timestr, sizeof(timestr), 1, TID_STRING);
544 
545  // update energy loss, implantation energy etc. in /Info structure
546  update_info();
547 
548  // root file header related things
549  gRunHeader = gROOT->GetRootFolder()->AddFolder("RunHeader", "LEM Run Header Info");
550  gROOT->GetListOfBrowsables()->Add(gRunHeader, "RunHeader");
551  header = new TMusrRunHeader(true);
552  header->FillFolder(gRunHeader);
553  gRunHeader->Add(&Slist);
554  Slist.SetName("RunSummary");
555 
557  write_flag = 1;
558 
559  // Register callback for messages to allow for SMS/E-Mail send in case of an Alarm
560  // cm_msg_register(receive_message);
561 
562  status = db_find_key(hDB, 0, "/Analyzer/Forced Write Data Flag", &hKey);
563  if (status != DB_SUCCESS) { // ODB entry missing, create it
564  status = db_create_key(hDB, 0, "/Analyzer/Forced Write Data Flag", TID_BOOL);
565  }
566 
567  return SUCCESS;
568 }
569 
570 //-- Analyzer Exit -------------------------------------------------
571 
573 {
574  return CM_SUCCESS;
575 }
576 
577 //-- Begin of Run --------------------------------------------------
578 
579 INT ana_begin_of_run(INT run_number, char *error)
580 {
581  HNDLE hDB, hkey;
582 
583  cm_get_experiment_database(&hDB, NULL);
584 
585  //----------------------------------------------------------------------
586  // reset SRAT bank
587  //----------------------------------------------------------------------
588 
589  if ( db_find_key(hDB, 0, "/Equipment/Scaler/Variables/SRAT", &hkey) == DB_SUCCESS ) {
590  memset(&srat_bank, 0, sizeof(srat_bank));
591  db_set_record(hDB, hkey, &srat_bank, sizeof(srat_bank), 0);
592  }
593 
594  //-- display scaler in analyzer window when running online -------------
595  if ( runinfo.online_mode == 1) {
596 
597  /*
598  a bit strange: runinfo.state is still STATE_STOPPED when arriving here,
599  although other ODB parameters like run number and Start time are already
600  set properly for Run start; problem could be that the change of the ODB value
601  for
602  runinfo.state is done at the end of the cm_transition() function, maybe
603  too late for analyzer programs which already reads the runinfo.state value.
604  To avoid this problem I force runinfo.state to have the right value for
605  the analyzer/scaler functions.
606  */
607  runinfo.state = STATE_RUNNING;
609  }
610 
611  versionCounter = 0;
612 
613  // update Run header
614  update_info();
616 
617  write_flag = 1;
618  sum_count = 0;
619 
620  // check if beam shutter is open; if not send a warning to the MIDAS alarm system
621  if (beam_shutter_open(hDB) == 0)
622  al_trigger_alarm( "ana_begin_of_run", "Beam Shutters KV61/62 still closed at begin-of-run!",
623  "Warning", "BeamLine Shutters KV61/62 still closed at BOR!", AT_INTERNAL);
624 
625  return CM_SUCCESS;
626 }
627 
628 //-- End of Run ----------------------------------------------------
629 
630 INT ana_end_of_run(INT run_number, char *error)
631 {
632  FILE *f;
633  time_t now;
634  char str[256], logdir[256], cmd[256], file_name[256];
635  char year[5];
636  INT size, len, status;
637  double n;
638  HNDLE hDB, hkey;
639  BOOL flag;
640 
641  cm_get_experiment_database(&hDB, NULL);
642 
643  // update run log if run was written and running online
644  size = sizeof(flag);
645  db_get_value(hDB, 0, "/Logger/Write data", &flag, &size, TID_BOOL, FALSE);
646  if (flag && runinfo.online_mode == 1) {
647  // update run log
648  size = sizeof(str);
649  str[0] = 0;
650  file_name[0] = 0;
651  year[0] = 0;
652  db_get_value(hDB, 0, "/Logger/Data Dir", str, &size, TID_STRING, FALSE);
653  if (str[0] != 0)
654  if (str[strlen(str)-1] != DIR_SEPARATOR)
655  strcat(str, DIR_SEPARATOR_STR);
656  strcpy(logdir, str); /* save copy of logger dir */
657  strcat(str, "runlog.txt");
658  strcpy(file_name, str);
659  f = fopen(file_name, "a");
660 
661  time(&now);
662  strcpy(str, ctime(&now));
663  year[0] = str[20];
664  year[1] = str[21];
665  year[2] = str[22];
666  year[3] = str[23];
667  year[4] = 0;
668  str[10] = 0;
669 
670  fprintf(f, "%5d\t%s %s", runinfo.run_number, str, year);
671 
672  strcpy(str, runinfo.start_time);
673  str[19] = 0;
674  fprintf(f, "::%s --- ", str+11);
675 
676  strcpy(str, ctime(&now));
677  str[19] = 0;
678  fprintf(f, "%s\t", str+11);
679 
680  size = sizeof(n);
681  db_get_value(hDB, 0, "/Equipment/Trigger/Statistics/Events sent", &n, &size, TID_DOUBLE, FALSE);
682 
683  fprintf(f, "%6.1lfk\t", n/1000);
684  fprintf(f, "%s --- ", exp_param.comment);
685 
686  fprintf(f, "PN: %d\n", info.file_header_info.proposal_number);
687 
688  fclose(f);
689 
690  runinfo.state = STATE_STOPPED;
691  runinfo.stop_time_binary = now;
692  strcpy(runinfo.stop_time, ctime(&now));
693 
694  // delete \n in runinfo.stop_time if present
695  len = strlen(runinfo.stop_time);
696  if (runinfo.stop_time[len-1] == '\n' )
697  runinfo.stop_time[len-1] = 0;
698 
699  //-------- update ODB ----------------------
700  //
701  // also a bit strange here: the ODB dump does not contain the correct Stop time
702  // of a run; it appears to be written too late to the ODB, i.e. a f t e r saving
703  // the ODB.
704  // I force setting the right values to ODB here in analyzer.
705  //------------------------------------------
706 
707  db_set_value(hDB, 0, "/Runinfo/State", &runinfo.state, sizeof(runinfo.state), 1, TID_INT);
708  db_set_value(hDB, 0, "/Runinfo/Stop time", &runinfo.stop_time,
709  sizeof(runinfo.stop_time), 1, TID_STRING);
710  db_set_value(hDB, 0, "/Runinfo/Stop time binary", &runinfo.stop_time_binary,
711  sizeof(runinfo.stop_time_binary), 1, TID_DWORD);
712 
714  ss_printf(0,50,"Rates at EOR are a v e r a g e d rates !");
715  }
716 
717  // update run header
718  update_info();
720 
721  return CM_SUCCESS;
722 }
723 
724 //-- Pause Run -----------------------------------------------------
725 
726 INT ana_pause_run(INT run_number, char *error)
727 {
728  runinfo.state = STATE_PAUSED;
730  return CM_SUCCESS;
731 }
732 
733 //-- Resume Run ----------------------------------------------------
734 
735 INT ana_resume_run(INT run_number, char *error)
736 {
737  HNDLE hDB;
738 
739  cm_get_experiment_database(&hDB, NULL);
740 
741  // check if beam shutter is open; if not send a warning to the MIDAS alarm system
742  if (beam_shutter_open(hDB) == 0)
743  al_trigger_alarm( "ana_begin_of_run", "Beam Shutters KV61/62 still closed at run resume!",
744  "Warning", "BeamLine Shutters KV61/62 still closed at run resume!", AT_INTERNAL);
745 
746  runinfo.state = STATE_RUNNING;
748  return CM_SUCCESS;
749 }
750 
751 //-- Analyzer Loop -------------------------------------------------
752 
754 {
755  DWORD nowtime, difftime;
756  HNDLE hDB, hKey;
757  INT status, size;
758  BOOL forced_write;
759 
760  nowtime = ss_time();
761  difftime = nowtime - last_update_info_write;
762  if (difftime > UPDATE_INFO_PERIOD) {
763  update_info();
764  last_update_info_write = nowtime;
765  }
766 
767  cm_get_experiment_database(&hDB, NULL);
768 
769  if ( runinfo.state == STATE_PAUSED ) return CM_SUCCESS;
770 
771  if ( runinfo.state == STATE_RUNNING ) {
772  write_flag = 0;
773  // get forced-write data flag from odb
774  status = db_find_key(hDB, 0, "/Analyzer/Forced Write Data Flag", &hKey);
775  if (status == DB_SUCCESS) {
776  size = sizeof(forced_write);
777  status = db_get_data(hDB, hKey, &forced_write, &size, TID_BOOL);
778  if (status != DB_SUCCESS)
779  forced_write = FALSE;
780  } else {
781  forced_write = FALSE;
782  }
783  // update timer
784  difftime = nowtime - last_histogram_write;
785  if ( (difftime > HISTOGRAM_WRITE_PERIOD) || forced_write ) { // timeout reached, or forced-write data flag set
788  if (forced_write) { // reset forced-write data flag
789  forced_write = FALSE;
790  status = db_set_data(hDB, hKey, &forced_write, sizeof(forced_write), 1, TID_BOOL);
791  } else {
792  last_histogram_write = nowtime;
793  }
794  if ( sum_count == 1 ) { // extract summary file when we reach this point
795  Slist.Delete();
796  extract_summary_data(); // the 2nd time
797  }
798  sum_count++;
799  }
800  }
801 
802  if ( runinfo.state == STATE_STOPPED && !write_flag ) {
803  ss_sleep(3000); // wait 3sec for final summary file
804  Slist.Delete();
807  write_flag = 1;
808  }
809 
810  return CM_SUCCESS;
811 }
812 
813 // ------------------------------------------------------------------
818 {
819  HNDLE hDB, hkey;
820  char fname[256], str[256], file_name[256], save_file_name[256], cmd[256];
821  INT size, status;
822 
823  cm_get_experiment_database(&hDB, NULL);
824  sprintf(str, "/%s/Output/Histo Dump Filename", analyzer_name);
825  size = sizeof(fname);
826  db_get_value(hDB, 0, str, fname, &size, TID_STRING, TRUE);
827 
828  if (strchr(fname, '%') != NULL)
829  sprintf(file_name, fname, runinfo.run_number);
830  else
831  strcpy(file_name, fname);
832 
833  db_find_key(hDB, 0, "/Logger/Data dir", &hkey);
834  if (hkey) {
835  size = sizeof(str);
836  db_get_data(hDB, hkey, str, &size, TID_STRING);
837  if (str[strlen(str) - 1] != DIR_SEPARATOR)
838  strcat(str, DIR_SEPARATOR_STR);
839  strcat(str, file_name);
840  strcpy(file_name, str);
841  }
842 
843  strcpy(save_file_name, file_name);
844  //
845  // before May-10, 2013: save histogram as lemYY_his_RunNr.V.root
846  //
847  // May-10, 2013: changed to lemYY_his_RunNr.root.V
848  //
849  // *strstr(file_name, ".root") = 0;
850  sprintf(str, ".%d", versionCounter);
851  strcat(file_name, str);
852  // strcat(file_name, ".root");
853  versionCounter++;
854 
855  // the following is adapted from SaveRootHistograms() in mana.c
856  TDirectory *savedir = gDirectory;
857  TFile *outf = new TFile(file_name, "RECREATE", "Midas Analyzer Histograms");
858  if (outf == 0) {
859  cm_msg(MERROR, "SaveRootHistograms", "Cannot create output file %s", file_name);
860  return 0;
861  }
862  outf->cd();
863  gManaHistosFolder->Write();
864  if (header->FillFolder(gRunHeader))
865  gRunHeader->Write();
866  else
867  cm_msg(MERROR, "write_histogram_file", "analyzer error: couldn't fill the run header information!");
868  outf->Close();
869  delete outf;
870  // restore current directory
871  savedir->cd();
872  //
873  // copy lemYY_his_RunNr.V.root to lemYY_his_RunNr.root
874  //
875  ss_sleep(1000);
876  status = gSystem->CopyFile(file_name, save_file_name, kTRUE);
877  if (status != 0) {
878  if (status == -1) {
879  cm_msg(MINFO, "analyzer", "**WARNING** cp in write histogram file failed. (file open failure of %s)", file_name);
880  } else if (status == -2) {
881  cm_msg(MINFO, "analyzer", "**WARNING** cp in write histogram file failed. (write protection error of %s)", save_file_name);
882  } else if (status == -3) {
883  cm_msg(MINFO, "analyzer", "**WARNING** cp in write histogram file failed. (error during copying (%s->%s))", file_name, save_file_name);
884  }
885  }
886 
887  //cm_msg(MINFO, "analyzer_loop", "saved histograms in %s", file_name);
888 
889  return CM_SUCCESS;
890 }
891 
892 //-----------------------------------------------------------------
898 void get_sum_filename(char *filename)
899 {
900  struct tm *tms;
901  time_t now;
902  char dir[256], filebody[256];
903 
904  dir[0] = 0;
905  filebody[0] = 0;
906 
907  if ( getenv("MIDAS_DATA") ) {
908  strcpy(dir, getenv("MIDAS_DATA"));
909  strcat(dir, DIR_SEPARATOR_STR);
910  strcat(dir, "summ");
911  strcat(dir, DIR_SEPARATOR_STR);
912  } else {
913 #if defined (OS_UNIX)
914  strcpy(dir, getenv("HOME"));
915 #elif defined (OS_WINNT)
916  strcpy(dir, getenv("HOMEPATH"));
917 #endif
918  strcat(dir, DIR_SEPARATOR_STR);
919  cm_msg(MINFO, "get_sum_filename",
920  "MIDAS_DATA path not defined, use home directory %s instead\n", dir);
921  }
922 
923  time(&now);
924  tms = localtime(&now);
925  // tms->tm_year yields "Year - 1900"
926  strcpy(filename, dir);
927  sprintf(filebody, "%04d/lem%02d_%04d.summ", tms->tm_year+1900, tms->tm_year%100, runinfo.run_number);
928  strcat(filename, filebody);
929 }
930 
931 //-----------------------------------------------------------------
936 {
937  INT i;
938  char fileName[256], line[256], enumline[256];
939  TObjString *s;
940 
941  get_sum_filename(fileName);
942 
943  i = 0;
944  FILE *fp = fopen(fileName,"r");
945  if ( fp == NULL ) {
946  printf("File %s does not exist!\n", fileName);
947  return;
948  }
949 
950  while (fgets(line,256,fp)) {
951  sprintf(enumline, "%04d ", i);
952  strcat(enumline, line);
953  s = new TObjString(enumline);
954  Slist.Add(s);
955  i++;
956  }
957 
958  fclose(fp);
959 }
960 
961 //-----------------------------------------------------------------
972 float energy_loss( float moderator_hv)
973 {
974  float deltaE, x, p0, p1, p2, p3;
975 
976  if ( moderator_hv > 20.1 ) {
977  deltaE = 0.23;
978  } else {
979  p0 = info.energy_loss_parameter.p0;
980  p1 = info.energy_loss_parameter.p1;
981  p2 = info.energy_loss_parameter.p2;
982  p3 = info.energy_loss_parameter.p3;
983  x = moderator_hv;
984  deltaE = p0 + p1*x + p2*x*x + p3*x*x*x;
985  }
986 
987  return deltaE;
988 }
989 
990 //-----------------------------------------------------------------
998 float get_magnetic_field(float current)
999 {
1000  float Bfield, x, p0, p1;
1001 
1002  if (info.lem_setup_parameter.wew) {
1003  p0 = info.magnet_parameter.wew[0];
1004  p1 = info.magnet_parameter.wew[1];
1005  } else if (info.lem_setup_parameter.bpar) {
1006  p0 = info.magnet_parameter.bpar[0];
1007  p1 = info.magnet_parameter.bpar[1];
1008  } else {
1009  p0 = 0.;
1010  p1 = 0.;
1011  }
1012 
1013  Bfield = p0 + p1*current;
1014 
1015  return Bfield;
1016 }
1017 
1018 //-----------------------------------------------------------------
1023 {
1024  HNDLE hDB, hKey, hSubKey;
1025  INT i, size, result;
1026  float eloss, impEnergy, modHV, sampleHV, current, Bfield;
1027  char lem_setup[STR_SIZE], lem_cryostat[NAME_LENGTH], old_lem_cryostat[NAME_LENGTH], hostname[64];
1028  KEY cryoKey;
1029  BOOL flag, cryo_not_found;
1030 // INTEL_LOG info; // for lem01
1031  LEM00_IPMI_LOG info00; // for lem00
1032  LEM03_IPMI_LOG info03; // for lem03
1033  MICROWAVE_LOG microwave_info;
1034 
1035  cm_get_experiment_database(&hDB, NULL);
1036 
1037  // update energy loss and implantation energy
1038  modHV = hv_event.measured[sc_ana_param.mod_hv_channel];
1039  sampleHV = hv_event.measured[sc_ana_param.sample_hv_channel];
1040  eloss = energy_loss( modHV);
1041  impEnergy = modHV - eloss - sampleHV;
1042  db_set_value(hDB, 0, "/Info/Energy Loss (C-foil)", &eloss, sizeof(eloss), 1, TID_FLOAT);
1043  db_set_value(hDB, 0, "/Info/Implantation Energy (keV)", &impEnergy, sizeof(impEnergy), 1, TID_FLOAT);
1044 
1045  // update B-field, get current from zero flux (Danfyisk of Bruker supply) or from Bruker (I>500A)
1046  // current = scs900_event.input[sc_ana_param.sample_zeroflux_channel];
1047  // this needs to be modified for the new power supply.
1048  current = scs2001m_event.input[sc_ana_param.sample_zeroflux_channel];
1049  if (current < 9.9) // max. output of zero flux meter is 10V = 500A
1050  current = current/10. * 500.; // 10V Zero Flux voltage corresponds to 500A
1051  else { // we have a current >500A, which ZeroFlux can't display anymore;
1052  size = sizeof(float); // get current directly from Bruker in this case
1053  db_get_value(hDB, 0, "/Equipment/Bruker/Variables/Input[3]", &current, &size, TID_FLOAT, FALSE);
1054  }
1055 
1056  Bfield = get_magnetic_field(current);
1057  db_set_value(hDB, 0, "/Info/Magnetic Field (G)", &Bfield, sizeof(Bfield), 1, TID_FLOAT);
1058 
1059  // update t0's
1060  // get_t0();
1061  get_t0L3RA();
1062 
1063  // check which server is in use
1064  result = gethostname(hostname, sizeof(hostname));
1065 
1066  if (strstr(hostname, "lem00")) { // for lem00
1067  result = read_lem00_ipmi_log(&info00);
1068 
1069  if (result > 0) { // i.e. all entries found
1070  db_find_key(hDB, 0, "/Info/Lem00IPMILog", &hKey);
1071  db_set_record(hDB, hKey, &info00, sizeof(info00), 0);
1072  }
1073  }
1074  if (strstr(hostname, "lem03")) { // for lem03
1075  result = read_lem03_ipmi_log(&info03);
1076 
1077  if (result > 0) { // i.e. all entries found
1078  db_find_key(hDB, 0, "/Info/Lem03IPMILog", &hKey);
1079  db_set_record(hDB, hKey, &info03, sizeof(info03), 0);
1080  }
1081  }
1082 
1083 // microwave/laser log file of Lambshift/MuMass experiment
1084 // result = read_microwave_log(&microwave_info);
1085 //
1086 // if (result == SUCCESS) {
1087 // db_find_key(hDB, 0, "/Info/MicrowaveLog", &hKey);
1088 // db_set_record(hDB, hKey, &microwave_info, sizeof(microwave_info), 0);
1089 // }
1090 }
1091 
1092 //-----------------------------------------------------------------
1097 {
1098  HNDLE hDB, hKey;
1099  INT size, i, ival;
1100  std::vector<int> ivec;
1101  char lem_setup[STR_SIZE+NAME_LENGTH];
1102  char str[256], str1[256], str2[256], *p_str;
1103  double ip_sum, scaler_clock_sum, tdc_clock_sum, n_events, dval;
1104  double td_sum, td_clean_sum, td_good_sum, pos_sum[N_DECAY_HISTS];
1105  long time_bin;
1106 
1107  // get the main ODB handle
1108  cm_get_experiment_database(&hDB, NULL);
1109 
1110  sprintf(lem_setup, "%s, ", info.lem_setup);
1111  strcat(lem_setup, info.sample_cryo);
1112 
1113  //----------------------------
1114  // RunInfo (required)
1115  //----------------------------
1116 
1117  // 1st write all the required RunInfo entries
1118 
1119  header->Set("RunInfo/Generic Validator URL", "http://lmu.web.psi.ch/facilities/software/MusrRoot/validation/MusrRoot.xsd");
1120  header->Set("RunInfo/Specific Validator URL", "http://lmu.web.psi.ch/facilities/software/MusrRoot/validation/MusrRootLEM.xsd");
1121  header->Set("RunInfo/Generator", "nemu_analyzer");
1122 
1123  // write proposal number and PI info
1124  header->Set("RunInfo/Proposal Number", info.file_header_info.proposal_number);
1125  header->Set("RunInfo/Main Proposer", info.file_header_info.main_proposer);
1126  header->Set("RunInfo/P-Group", info.file_header_info.pgroup);
1127 
1128  // compose the file name
1129  size = sizeof(str);
1130  db_find_key(hDB, 0, "/Analyzer/Output/Histo Dump Filename", &hKey);
1131  db_get_data(hDB, hKey, &str, &size, TID_STRING);
1132  // filter out the last part of the string spearted by "/", str should have the format <something>/lem<yy>_his_%04d.root
1133  i = 0;
1134  p_str = 0;
1135  do {
1136  if (str[i] == '/')
1137  p_str = &str[i];
1138  i++;
1139  } while (str[i] != '\0');
1140  if (p_str == 0) {
1141  cm_msg(MERROR, "update_run_header", "Couldn't obtain run file name template! ODB corrupted?");
1142  return;
1143  }
1144  p_str++;
1145  // replace "%04d" through the run number
1146  strcpy(str1, p_str);
1147  p_str = strstr(str1, "%");
1148  if (p_str == 0) {
1149  cm_msg(MERROR, "update_run_header", "Wrong run file name template! ODB corrupted?");
1150  return;
1151  }
1152  *p_str = '\0';
1153  sprintf(str, "%04d.root", runinfo.run_number);
1154  strcat(str1, str);
1155  header->Set("RunInfo/File Name", str1);
1156 
1157  header->Set("RunInfo/Run Title", exp_param.comment);
1158  header->Set("RunInfo/Run Number", runinfo.run_number);
1159 
1160  // handle start and stop time
1161  time_bin = (long)runinfo.start_time_binary; // for 64bit this conversion is needed
1162  struct tm *tm = localtime((time_t*)&time_bin);
1163  strftime(str, sizeof(str), "%F %T", tm);
1164  header->Set("RunInfo/Run Start Time", str);
1165  time_bin = (long)runinfo.stop_time_binary;
1166  tm = localtime((time_t*)&time_bin);
1167  strftime(str, sizeof(str), "%F %T", tm);
1168  header->Set("RunInfo/Run Stop Time", str);
1169  if (runinfo.stop_time_binary < runinfo.start_time_binary) // ongoing run
1170  ival = -1;
1171  else
1172  ival = (int)runinfo.stop_time_binary - (int)runinfo.start_time_binary;
1173 
1174  TMusrRunPhysicalQuantity prop;
1175  prop.Set("Run Duration", ival, "sec");
1176  header->Set("RunInfo/Run Duration", prop);
1177 
1178  header->Set("RunInfo/Laboratory", "PSI");
1179  header->Set("RunInfo/Instrument", "LEM");
1180 
1181  prop.Set("Muon Beam Momentum", 28.1, "MeV/c");
1182  header->Set("RunInfo/Muon Beam Momentum", prop);
1183 
1184  header->Set("RunInfo/Muon Species", "positive muon");
1185  header->Set("RunInfo/Muon Source", "Target E - Low Energy Muons");
1186  header->Set("RunInfo/Setup", lem_setup);
1187  header->Set("RunInfo/Comment", "n/a");
1188  header->Set("RunInfo/Sample Name", info.sample_name);
1189 
1190  prop.Set("Sample Temperature", MRH_UNDEFINED, mean.sample_t, mean.var_sample_t, "K");
1191  header->Set("RunInfo/Sample Temperature", prop);
1192  prop.Set("Sample Magnetic Field", MRH_UNDEFINED, mean.sample_b, mean.var_sample_b, "G");
1193  header->Set("RunInfo/Sample Magnetic Field", prop);
1194 
1195  header->Set("RunInfo/No of Histos", N_DECAY_HISTS);
1196 
1197  prop.Set("Time Resolution", 0.1953125, "ns", "TDC CAEN V1190");
1198  header->Set("RunInfo/Time Resolution", prop);
1199 
1200  ivec.push_back(0);
1201  ivec.push_back(N_OFFSET_PPC_HISTOGRAMS);
1202  ivec.push_back(N_OFFSET_ONOFF_HISTOGRAMS);
1204  header->Set("RunInfo/RedGreen Offsets", ivec);
1205 
1206  // 2nd write all the LEM specifiy RunInfo entries
1207 
1208  header->Set("RunInfo/Moderator", info.moderator);
1209  prop.Set("Moderator HV", MRH_UNDEFINED, mean.moderator_hv, mean.var_moderator_hv, "kV");
1210  header->Set("RunInfo/Moderator HV", prop);
1211  prop.Set("Sample HV", MRH_UNDEFINED, mean.sample_hv, mean.var_sample_hv, "kV");
1212  header->Set("RunInfo/Sample HV", prop);
1213  prop.Set("Implantation Energy", info.implantation_energy, "keV");
1214  header->Set("RunInfo/Implantation Energy", prop);
1215  prop.Set("Muon Spin Angle", info.spinrot_parameter.rotation_angle, "degree");
1216  header->Set("RunInfo/Muon Spin Angle", prop);
1217  header->Set("RunInfo/Cuts", "none");
1218 
1219  //----------------------------
1220  // DetectorInfo (required)
1221  //----------------------------
1222  // In the future, this part should probably being filled in a more abstract manner, especially if it comes to
1223  // real red/green mode experiments and histo fillings.
1224 
1225  // NPP's, EXT. OFF
1226  for (i=0; i<N_DECAY_HISTS; i++) {
1227  // Name
1228  sprintf(str, "DetectorInfo/Detector%03d", i+1);
1229  snprintf(str1, sizeof(str1), "%s/Name", str);
1230  sprintf(str2, "%s, EXT. OFF", decay_ana_param.histotitles.decaytitles.titles[i]);
1231  header->Set(str1, str2);
1232  // Histo Number
1233  snprintf(str1, sizeof(str1), "%s/Histo Number", str);
1234  header->Set(str1, i+1);
1235  // Histo Length
1236  snprintf(str1, sizeof(str1), "%s/Histo Length", str);
1237  header->Set(str1, decay_ana_param.histobinning.decaybin.histonbin[i]);
1238  // Time Zero Bin
1239  snprintf(str1, sizeof(str1), "%s/Time Zero Bin", str);
1240  dval = (double) info.t0_parameter.t0[i];
1241  header->Set(str1, dval);
1242  // First Good Bin
1243  snprintf(str1, sizeof(str1), "%s/First Good Bin", str);
1244  ival = (int) ceil(dval);
1245  header->Set(str1, ival);
1246  // Last Good Bin
1247  snprintf(str1, sizeof(str1), "%s/Last Good Bin", str);
1248  header->Set(str1, decay_ana_param.histobinning.decaybin.histonbin[i]-1);
1249  }
1250 
1251  // PPC's, EXT. OFF
1252  for (i=0; i<N_DECAY_HISTS; i++) {
1253  // Name
1254  sprintf(str, "DetectorInfo/Detector%03d", i+1+N_OFFSET_PPC_HISTOGRAMS);
1255  snprintf(str1, sizeof(str1), "%s/Name", str);
1256  sprintf(str2, "%s, EXT. OFF", decay_ana_param.histotitles.decaytitles.titles[i+N_DECAY_HISTS]);
1257  header->Set(str1, str2);
1258  // Histo Number
1259  snprintf(str1, sizeof(str1), "%s/Histo Number", str);
1260  header->Set(str1, i+1+N_OFFSET_PPC_HISTOGRAMS);
1261  // Histo Length
1262  snprintf(str1, sizeof(str1), "%s/Histo Length", str);
1263  header->Set(str1, decay_ana_param.histobinning.decaybin.histonbin[i+N_DECAY_HISTS]);
1264  // Time Zero Bin
1265  snprintf(str1, sizeof(str1), "%s/Time Zero Bin", str);
1266  dval = (double) info.t0_parameter.t0[i];
1267  header->Set(str1, dval);
1268  // First Good Bin
1269  snprintf(str1, sizeof(str1), "%s/First Good Bin", str);
1270  ival = (int) ceil(dval);
1271  header->Set(str1, ival);
1272  // Last Good Bin
1273  snprintf(str1, sizeof(str1), "%s/Last Good Bin", str);
1274  header->Set(str1, decay_ana_param.histobinning.decaybin.histonbin[i+N_DECAY_HISTS]-1);
1275  }
1276 
1277  // NPP's, EXT. ON
1278  for (i=0; i<N_DECAY_HISTS; i++) {
1279  // Name
1280  sprintf(str, "DetectorInfo/Detector%03d", i+1+N_OFFSET_ONOFF_HISTOGRAMS);
1281  snprintf(str1, sizeof(str1), "%s/Name", str);
1282  sprintf(str2, "%s, EXT. ON", decay_ana_param.histotitles.decaytitles.titles[i]);
1283  header->Set(str1, str2);
1284  // Histo Number
1285  snprintf(str1, sizeof(str1), "%s/Histo Number", str);
1286  header->Set(str1, i+1);
1287  // Histo Length
1288  snprintf(str1, sizeof(str1), "%s/Histo Length", str);
1289  header->Set(str1, decay_ana_param.histobinning.decaybin.histonbin[i]);
1290  // Time Zero Bin
1291  snprintf(str1, sizeof(str1), "%s/Time Zero Bin", str);
1292  dval = (double) info.t0_parameter.t0[i];
1293  header->Set(str1, dval);
1294  // First Good Bin
1295  snprintf(str1, sizeof(str1), "%s/First Good Bin", str);
1296  ival = (int) ceil(dval);
1297  header->Set(str1, ival);
1298  // Last Good Bin
1299  snprintf(str1, sizeof(str1), "%s/Last Good Bin", str);
1300  header->Set(str1, decay_ana_param.histobinning.decaybin.histonbin[i]-1);
1301  }
1302 
1303  // PPC's, EXT. ON
1304  for (i=0; i<N_DECAY_HISTS; i++) {
1305  // Name
1306  sprintf(str, "DetectorInfo/Detector%03d", i+1+N_OFFSET_PPC_HISTOGRAMS+N_OFFSET_ONOFF_HISTOGRAMS);
1307  snprintf(str1, sizeof(str1), "%s/Name", str);
1308  sprintf(str2, "%s, EXT. ON", decay_ana_param.histotitles.decaytitles.titles[i+N_DECAY_HISTS]);
1309  header->Set(str1, str2);
1310  // Histo Number
1311  snprintf(str1, sizeof(str1), "%s/Histo Number", str);
1312  header->Set(str1, i+1+N_OFFSET_PPC_HISTOGRAMS);
1313  // Histo Length
1314  snprintf(str1, sizeof(str1), "%s/Histo Length", str);
1315  header->Set(str1, decay_ana_param.histobinning.decaybin.histonbin[i+N_DECAY_HISTS]);
1316  // Time Zero Bin
1317  snprintf(str1, sizeof(str1), "%s/Time Zero Bin", str);
1318  dval = (double) info.t0_parameter.t0[i];
1319  header->Set(str1, dval);
1320  // First Good Bin
1321  snprintf(str1, sizeof(str1), "%s/First Good Bin", str);
1322  ival = (int) ceil(dval);
1323  header->Set(str1, ival);
1324  // Last Good Bin
1325  snprintf(str1, sizeof(str1), "%s/Last Good Bin", str);
1326  header->Set(str1, decay_ana_param.histobinning.decaybin.histonbin[i+N_DECAY_HISTS]-1);
1327  }
1328 
1329 
1330  //-----------------------------------
1331  // SampleEnvironmentInfo (required)
1332  //-----------------------------------
1333 
1334  // 1st required entries for SampleEnvironmentInfo
1335 
1336  header->Set("SampleEnvironmentInfo/Cryo", info.sample_cryo);
1337 
1338  // 2nd LEM specific entries for SampleEnvironmentInfo
1339 
1340  // nothing to be set yet
1341 
1342 
1343  //-----------------------------------------
1344  // MagneticFieldEnvironmentInfo (required)
1345  //-----------------------------------------
1346 
1347  // 1st required entries for MagneticFieldEnvironmentInfo
1348 
1349  header->Set("MagneticFieldEnvironmentInfo/Magnet Name", info.lem_setup);
1350 
1351  // 2nd LEM specific entries for MagneticFieldEnvironmentInfo
1352 
1353  // nothing to be set yet
1354 
1355  //----------------------------
1356  // BeamlineInfo (required)
1357  //----------------------------
1358 
1359  // 1st required entries for BeamlineInfo
1360 
1361  header->Set("BeamlineInfo/Name", "muE4");
1362 
1363  // 2nd LEM specific entries for MagneticFieldEnvironmentInfo
1364 
1365  header->Set("BeamlineInfo/Beamline Settings", info.beamline_settings);
1366 
1367  //---------------------------------------------
1368  // ScalerInfo (NOT required, i.e LEM specific)
1369  //--------------------------------------------
1370 
1371  size = sizeof(double);
1372  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[0]", &ip_sum, &size, TID_DOUBLE, FALSE);
1373  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[1]", &scaler_clock_sum, &size, TID_DOUBLE, FALSE);
1374  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[4]", &td_sum, &size, TID_DOUBLE, FALSE);
1375  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[40]", &pos_sum[0], &size, TID_DOUBLE, FALSE);
1376  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[41]", &pos_sum[1], &size, TID_DOUBLE, FALSE);
1377  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[42]", &pos_sum[2], &size, TID_DOUBLE, FALSE);
1378  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[43]", &pos_sum[3], &size, TID_DOUBLE, FALSE);
1379  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[44]", &pos_sum[4], &size, TID_DOUBLE, FALSE);
1380  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[45]", &pos_sum[5], &size, TID_DOUBLE, FALSE);
1381  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[46]", &pos_sum[6], &size, TID_DOUBLE, FALSE);
1382  db_get_value(hDB, 0, "/Equipment/Scaler/Variables/SSUM[47]", &pos_sum[7], &size, TID_DOUBLE, FALSE);
1383  db_get_value(hDB, 0, "/Equipment/Trigger/VME_Statistics/TD clean", &td_clean_sum, &size, TID_DOUBLE, FALSE);
1384  db_get_value(hDB, 0, "/Equipment/Trigger/VME_Statistics/TD good" , &td_good_sum, &size, TID_DOUBLE, FALSE);
1385  db_get_value(hDB, 0, "/Equipment/Trigger/VME_Statistics/channelCounts[1]" , &tdc_clock_sum, &size, TID_DOUBLE, FALSE);
1386  db_get_value(hDB, 0, "/Equipment/Trigger/VME_Statistics/SlowMuonEvents" , &n_events, &size, TID_DOUBLE, FALSE);
1387 
1388  header->Set("ScalerInfo/Sum Ip", ip_sum);
1389  header->Set("ScalerInfo/Sum Clock (Scaler)", scaler_clock_sum);
1390  header->Set("ScalerInfo/Sum Clock (TDC)", tdc_clock_sum);
1391  header->Set("ScalerInfo/Sum Slow Muon Events", n_events);
1392  header->Set("ScalerInfo/Sum TD", td_sum);
1393  header->Set("ScalerInfo/Sum TD_Clean", td_clean_sum);
1394  header->Set("ScalerInfo/Sum TD_Good", td_good_sum);
1395 
1396  TIntVector posSumVec;
1397  for (unsigned int i=0; i<8; i++)
1398  posSumVec.push_back((int)pos_sum[i]);
1399  header->Set("ScalerInfo/Sum Positrons", posSumVec);
1400 }
1401 
1402 //-----------------------------------------------------------------
1419 void get_t0()
1420 {
1421  HNDLE hDB, hKey;
1422  INT t0[N_DECAY_HISTS];
1423  INT size, i;
1424  float moderator_hv, energy_after_TD_XXkV;
1425  float tofXXkV, muon_mass, c_light, l_eff, scale;
1426 
1427  moderator_hv = hv_event.demand[sc_ana_param.mod_hv_channel];
1428 
1429  if (moderator_hv < 5.0)
1430  return;
1431 
1432  energy_after_TD_XXkV = moderator_hv - energy_loss(moderator_hv);
1433 
1434  muon_mass = 105658.370; // keV
1435  c_light = 299.792458; // speed of light, mm/ns
1436 
1437  //check, if WEW is installed and if WEW field is <> 130G; RA is off for B>130G
1438  if ((strstr(info.lem_setup, "WEW") != NULL && fabs(info.magnetic_field) < 130.) ||
1439  strstr(info.lem_setup, "Bpar") != NULL)
1440  l_eff = info.t0_parameter.leff_RAon;
1441  else
1442  l_eff = info.t0_parameter.leff_RAoff;
1443 
1444  scale = l_eff/c_light*sqrt(muon_mass/2.);
1445 
1446  tofXXkV = scale/sqrt(energy_after_TD_XXkV);
1447 
1448  tofXXkV = tofXXkV/0.1953125; //offset in TDC channels
1449 
1450  for (i=0; i<N_DECAY_HISTS; i++)
1451  t0[i] = info.t0_parameter.t0Hist[i] + (int) roundf(tofXXkV);
1452 
1453  cm_get_experiment_database(&hDB, NULL);
1454  db_find_key(hDB, 0, "/Info/t0_parameter/t0", &hKey);
1455  db_set_record(hDB, hKey, &t0, sizeof(t0), 0);
1456 }
1457 
1458 //-----------------------------------------------------------------
1522 {
1523  HNDLE hDB, hKey;
1524  INT t0[N_DECAY_HISTS];
1525  INT size, i;
1526  float moderatorHV, energyAfterTD;
1527  float tofXXkV, muonMass, cLight;
1528  float dTotal, dFree, dL3, dRA;
1529  float tofFree, tofL3, tofRA;
1530  float scaleL3, scaleRA;
1531  float UL3, URA;
1532 
1533  moderatorHV = hv_event.demand[tdsampletof_param.moderator_channel];
1534 
1535  if (moderatorHV < 5.0)
1536  return;
1537 
1538  energyAfterTD = moderatorHV - energy_loss(moderatorHV);
1539  muonMass = 105658.37; // keV
1540  cLight = 299.792458; // speed of light, mm/ns
1541 
1542  UL3 = hv_event.demand[tdsampletof_param.l3_channel];
1543  URA = hv_event.demand[tdsampletof_param.ral_channel]
1544  + hv_event.demand[tdsampletof_param.rar_channel]
1545  + hv_event.demand[tdsampletof_param.rat_channel]
1546  + hv_event.demand[tdsampletof_param.rab_channel];
1547  URA = 0.25*URA;
1548 
1549  dTotal = tdsampletof_param.dtotalp0 + tdsampletof_param.dtotalp1*moderatorHV;
1550  dL3 = tdsampletof_param.dl3;
1551  dRA = tdsampletof_param.dra;
1552  dFree = dTotal - dL3 - dRA;
1553  scaleL3 = tdsampletof_param.scalel3p0 + tdsampletof_param.scalel3p1*moderatorHV;
1554  scaleRA = tdsampletof_param.scalerap0 + tdsampletof_param.scalerap1*moderatorHV;
1555  UL3 = scaleL3 * UL3;
1556  URA = scaleRA * URA;
1557 
1558  if ( UL3 == 0. ) UL3 = 0.0001; //to avoid division by zero later
1559  if ( URA == 0. ) URA = 0.0001; //to avoid division by zero later
1560 
1561  //calculate tof's
1562  tofFree = dFree/sqrt(2.*energyAfterTD/muonMass)/cLight;
1563  if (UL3 <= energyAfterTD)
1564  tofL3 = dL3/UL3/cLight * sqrt(2.*muonMass*energyAfterTD) * (1. - sqrt(1.-UL3/energyAfterTD));
1565  else
1566  tofL3 = dL3/UL3/cLight * sqrt(2.*muonMass*energyAfterTD);
1567  if (URA <= energyAfterTD)
1568  tofRA = dRA/URA/cLight * sqrt(2.*muonMass*energyAfterTD) * (1. - sqrt(1.-URA/energyAfterTD));
1569  else
1570  tofRA = dRA/URA/cLight * sqrt(2.*muonMass*energyAfterTD);
1571 
1572  tofXXkV = tofFree + tofL3 + tofRA;
1573  tofXXkV = tofXXkV/0.1953125; //TOF in TDC channels
1574 
1575  for (i=0; i<N_DECAY_HISTS; i++)
1576  t0[i] = info.t0_parameter.t0Hist[i] + (int) roundf(tofXXkV);
1577 
1578  cm_get_experiment_database(&hDB, NULL);
1579  db_find_key(hDB, 0, "/Info/t0_parameter/t0", &hKey);
1580  db_set_record(hDB, hKey, &t0, sizeof(t0), 0);
1581 }
1582 
1583 /* ---------------------------------------------------------------------------
1584 void receive_message(HNDLE hBuf, HNDLE id, EVENT_HEADER * evHeader, void *message)
1585 /* *****************************************************************************\
1586 
1587  Name: receive_message
1588  Author: Thomas Prokscha
1589  Date: 05-May-2007
1590 
1591  Purpose: if enabled send SMS/E-mail to recipient specified in
1592  "/Info/Alarm Notification"
1593  /Info/Alarm Notification/Enabled y/n
1594  /Info/Alarm Notification/Recipients <Phone>@sms.switch.ch <EMail>@psi.ch...
1595 
1596  Method: template taken from Midas code mlxspeaker.c
1597 
1598 \* *****************************************************************************
1599 {
1600  char cmd[256], *pc, *sp;
1601  char dir[256], filename[256], hostname[256];
1602 
1603  dir[0] = cmd[0] = filename[0] = hostname[0] = 0;
1604 
1605  if ( !info.alarm_notification.enabled ) return;
1606 
1607  // skip none talking message
1608  if (evHeader->trigger_mask == MT_TALK || evHeader->trigger_mask == MT_USER) {
1609  pc = strchr((char *) (message), ']') + 2;
1610  sp = pc + strlen(pc) - 1;
1611  while (*sp == ' ' || *sp == '\t')
1612  sp--;
1613  *(++sp) = '\0';
1614 
1615  // create filename containing message to be sent
1616  if ( getenv("MIDAS_WORK") ) {
1617  strcpy(dir, getenv("MIDAS_WORK"));
1618  strcat(dir, DIR_SEPARATOR_STR);
1619  }
1620  else{
1621  strcpy(dir, getenv("HOME"));
1622  strcat(dir, DIR_SEPARATOR_STR);
1623  }
1624  strcpy(filename, dir);
1625  strcat(filename, "Nemu_AlarmMessage.dat");
1626 
1627  // create message to be sent
1628  strcpy(hostname, getenv("HOSTNAME"));
1629  FILE *fp = fopen(filename,"w");
1630  fprintf(fp, "Midas alarm detected for experiment Nemu on host %s.\n", hostname);
1631  fprintf(fp, "%s.\n", pc);
1632  fclose(fp);
1633 
1634  //create command to be sent by "mail"
1635  sprintf(cmd, "cat %s | mail -s \"Midas Alarm\" %s", filename, info.alarm_notification.recipients);
1636  system(cmd);
1637  }
1638  return;
1639 }
1640 */
1641 
1642 //---------------------------------------------------------------------------
1652 {
1653  FILE *fd; // File pointer
1654  char filename_mws[] = "/data/nemu/test.txt"; // file to read
1655 // char filename_mws[] = "/data/nemu/MWScan_currentscan.txt"; // file to read
1656  static const long max_len = 200; // define the max length of the line to read
1657  char buff[max_len + 1]; // define the buffer and allocate the length
1658  int i=0;
1659 
1660  if ((fd = fopen(filename_mws, "rb")) != NULL) { // open file. I omit error checks
1661 
1662  fseek(fd, -max_len, SEEK_END); // set pointer to the end of file minus the length you need. Presumably there can be more than one new line caracter
1663  fread(buff, max_len-1, 1, fd); // read the contents of the file starting from where fseek() positioned us
1664  fclose(fd); // close the file
1665 
1666  buff[max_len-1] = '\0'; // close the string
1667  char *last_newline = strrchr(buff, '\n'); // find last occurrence of newlinw
1668  char *last_line = last_newline+1; // jump to it
1669 
1670  printf("last line: %s\n", last_line); //
1671 
1672  if (strstr(last_line,",") != NULL){
1673  sscanf(last_line,"%lf,%lf,%lf",
1674  &info->tektronix_timestamp,
1675  &info->tektronix_set_frequency,
1676  &info->tektronix_set_power);
1677  }
1678  }
1679  else{
1680  cm_msg(MINFO, "read_microwave_log", "read_microwave_log: cannot find file %s.", filename_mws);
1681  return -1;
1682  }
1683 
1684 // char filename_hfs[] = "/data/nemu/HFS_currentscan.txt"; // file to read
1685 // static const long max_len = 200; // define the max length of the line to read
1686 // char buff[max_len + 1]; // define the buffer and allocate the length
1687 // int i=0;
1688 //
1689 // if ((fd = fopen(filename_hfs, "rb")) != NULL) { // open file. I omit error checks
1690 //
1691 // fseek(fd, -max_len, SEEK_END); // set pointer to the end of file minus the length you need. Presumably there can be more than one new line caracter
1692 // fread(buff, max_len-1, 1, fd); // read the contents of the file starting from where fseek() positioned us
1693 // fclose(fd); // close the file
1694 //
1695 // buff[max_len-1] = '\0'; // close the string
1696 // char *last_newline = strrchr(buff, '\n'); // find last occurrence of newlinw
1697 // char *last_line = last_newline+1; // jump to it
1698 //
1699 // printf("last line: %s\n", last_line); //
1700 // sscanf(last_line,"%lf,%lf,%lf",
1701 // &info->ana_pico_timestamp,
1702 // &info->ana_pico_set_frequency,
1703 // &info->ana_pico_set_power);
1704 // }
1705 // else{
1706 // cm_msg(MINFO, "read_microwave_log", "read_microwave_log: cannot find file %s.", filename_hfs);
1707 // return -1;
1708 // }
1709 
1710  info->ana_pico_timestamp = -1.;
1711  info->ana_pico_set_frequency = -1.;
1712  info->ana_pico_set_power = -1.;
1713  info->keysight_u2002a_timestamp = (double) vme_stats.channelCounts[1];
1714  info->keysight_u2002a_measured_power = -1.;
1715  info->keysight_u8481a_timestamp = -1.;
1716  info->keysight_u8481a_measured_power = -1.;
1717  info->pressure_1 = -1.;
1718  info->pressure_2 = -1.;
1719  info->pressure_3 = -1.;
1720 
1721  return SUCCESS;
1722 }
1723 
1724 //---------------------------------------------------------------------------
1734 {
1735  FILE *fp;
1736  char line[128], *str_p;
1737  int status, ival;
1738  float fval;
1739  int lineNo=0;
1740  static DWORD last = 0;
1741  DWORD now;
1742 
1743  now = ss_time();
1744  if (now - last < UPDATE_INFO_PERIOD_IPMI) {
1745  return -1;
1746  }
1747 
1748  last = now; // keep current time stamp
1749 
1750  // init info structure
1751  info->cpu1_temp = -1.0;
1752  info->cpu2_temp = -1.0;
1753  info->system_temp = -1.0;
1754  info->peripherial_temp = -1.0;
1755  info->pch_temp = -1.0;
1756  info->p1_dimma1_temp = -1.0;
1757  info->p1_dimmb1_temp = -1.0;
1758  info->p2_dimme1_temp = -1.0;
1759  info->p2_dimmf1_temp = -1.0;
1760  info->fan1 = -1;
1761  info->fan2 = -1;
1762  info->fan3 = -1;
1763  info->fan5 = -1;
1764  info->fan6 = -1;
1765  info->vtt = -9999.0;
1766  info->cpu1_vcore = -9999.0;
1767  info->cpu2_vcore = -9999.0;
1768  info->vdimm_ab = -9999.0;
1769  info->vdimm_cd = -9999.0;
1770  info->vdimm_ef = -9999.0;
1771  info->vdimm_gh = -9999.0;
1772  info->p1_1v = -9999.0;
1773  info->p1_5v = -9999.0;
1774  info->p3_3v = -9999.0;
1775  info->p3_3vsb = -9999.0;
1776  info->p5v = -9999.0;
1777  info->p5vsb = -9999.0;
1778  info->p12v = -9999.0;
1779  info->vbat = -9999.0;
1780  info->chassis_intru = -1;
1781  info->ps1_status = -1;
1782  info->ps2_status = -1;
1783 
1784  fp = fopen("/var/log/lem00.psi.ch_ipmi.log", "r");
1785  if (fp == NULL) {
1786  printf("\nCouldn't open log file.\n");
1787  return -1;
1788  }
1789 
1790  while (!feof(fp)) {
1791  fgets(line, sizeof(line), fp);
1792  lineNo++;
1793 
1794  if (strstr(line, "CPU1 Temp")) {
1795  str_p = strstr(line, "|");
1796  if (str_p == NULL) { // couldn't find '|' within the line
1797  fclose(fp);
1798  return lineNo;
1799  }
1800  status = sscanf(str_p+1, "%f", &fval);
1801  if (status != 1) { // couldn't properly parse the line
1802  fclose(fp);
1803  return lineNo;
1804  }
1805  info->cpu1_temp = fval;
1806  } else if (strstr(line, "CPU2 Temp")) {
1807  str_p = strstr(line, "|");
1808  if (str_p == NULL) { // couldn't find '|' within the line
1809  fclose(fp);
1810  return lineNo;
1811  }
1812  status = sscanf(str_p+1, "%f", &fval);
1813  if (status != 1) { // couldn't properly parse the line
1814  fclose(fp);
1815  return lineNo;
1816  }
1817  info->cpu2_temp = fval;
1818  } else if (strstr(line, "System Temp")) {
1819  str_p = strstr(line, "|");
1820  if (str_p == NULL) { // couldn't find '|' within the line
1821  fclose(fp);
1822  return lineNo;
1823  }
1824  status = sscanf(str_p+1, "%f", &fval);
1825  if (status != 1) { // couldn't properly parse the line
1826  fclose(fp);
1827  return lineNo;
1828  }
1829  info->system_temp = fval;
1830  } else if (strstr(line, "Peripheral Temp")) {
1831  str_p = strstr(line, "|");
1832  if (str_p == NULL) { // couldn't find '|' within the line
1833  fclose(fp);
1834  return lineNo;
1835  }
1836  status = sscanf(str_p+1, "%f", &fval);
1837  if (status != 1) { // couldn't properly parse the line
1838  fclose(fp);
1839  return lineNo;
1840  }
1841  info->peripherial_temp = fval;
1842  } else if (strstr(line, "PCH Temp")) {
1843  str_p = strstr(line, "|");
1844  if (str_p == NULL) { // couldn't find '|' within the line
1845  fclose(fp);
1846  return lineNo;
1847  }
1848  status = sscanf(str_p+1, "%f", &fval);
1849  if (status != 1) { // couldn't properly parse the line
1850  fclose(fp);
1851  return lineNo;
1852  }
1853  info->pch_temp = fval;
1854  } else if (strstr(line, "P1-DIMMA1 TEMP")) {
1855  str_p = strstr(line, "|");
1856  if (str_p == NULL) { // couldn't find '|' within the line
1857  fclose(fp);
1858  return lineNo;
1859  }
1860  status = sscanf(str_p+1, "%f", &fval);
1861  if (status != 1) { // couldn't properly parse the line
1862  fclose(fp);
1863  return lineNo;
1864  }
1865  info->p1_dimma1_temp = fval;
1866  } else if (strstr(line, "P1-DIMMB1 TEMP")) {
1867  str_p = strstr(line, "|");
1868  if (str_p == NULL) { // couldn't find '|' within the line
1869  fclose(fp);
1870  return lineNo;
1871  }
1872  status = sscanf(str_p+1, "%f", &fval);
1873  if (status != 1) { // couldn't properly parse the line
1874  fclose(fp);
1875  return lineNo;
1876  }
1877  info->p1_dimmb1_temp = fval;
1878  } else if (strstr(line, "P2-DIMME1 TEMP")) {
1879  str_p = strstr(line, "|");
1880  if (str_p == NULL) { // couldn't find '|' within the line
1881  fclose(fp);
1882  return lineNo;
1883  }
1884  status = sscanf(str_p+1, "%f", &fval);
1885  if (status != 1) { // couldn't properly parse the line
1886  fclose(fp);
1887  return lineNo;
1888  }
1889  info->p2_dimme1_temp = fval;
1890  } else if (strstr(line, "P2-DIMMF1 TEMP")) {
1891  str_p = strstr(line, "|");
1892  if (str_p == NULL) { // couldn't find '|' within the line
1893  fclose(fp);
1894  return lineNo;
1895  }
1896  status = sscanf(str_p+1, "%f", &fval);
1897  if (status != 1) { // couldn't properly parse the line
1898  fclose(fp);
1899  return lineNo;
1900  }
1901  info->p2_dimmf1_temp = fval;
1902  } else if (strstr(line, "FAN1")) {
1903  str_p = strstr(line, "|");
1904  if (str_p == NULL) { // couldn't find '|' within the line
1905  fclose(fp);
1906  return lineNo;
1907  }
1908  status = sscanf(str_p+1, "%d", &ival);
1909  if (status != 1) { // couldn't properly parse the line
1910  fclose(fp);
1911  return lineNo;
1912  }
1913  info->fan1 = ival;
1914  } else if (strstr(line, "FAN2")) {
1915  str_p = strstr(line, "|");
1916  if (str_p == NULL) { // couldn't find '|' within the line
1917  fclose(fp);
1918  return lineNo;
1919  }
1920  status = sscanf(str_p+1, "%d", &ival);
1921  if (status != 1) { // couldn't properly parse the line
1922  fclose(fp);
1923  return lineNo;
1924  }
1925  info->fan2 = ival;
1926  } else if (strstr(line, "FAN3")) {
1927  str_p = strstr(line, "|");
1928  if (str_p == NULL) { // couldn't find '|' within the line
1929  fclose(fp);
1930  return lineNo;
1931  }
1932  status = sscanf(str_p+1, "%d", &ival);
1933  if (status != 1) { // couldn't properly parse the line
1934  fclose(fp);
1935  return lineNo;
1936  }
1937  info->fan3 = ival;
1938  } else if (strstr(line, "FAN5")) {
1939  str_p = strstr(line, "|");
1940  if (str_p == NULL) { // couldn't find '|' within the line
1941  fclose(fp);
1942  return lineNo;
1943  }
1944  status = sscanf(str_p+1, "%d", &ival);
1945  if (status != 1) { // couldn't properly parse the line
1946  fclose(fp);
1947  return lineNo;
1948  }
1949  info->fan5 = ival;
1950  } else if (strstr(line, "FAN6")) {
1951  str_p = strstr(line, "|");
1952  if (str_p == NULL) { // couldn't find '|' within the line
1953  fclose(fp);
1954  return lineNo;
1955  }
1956  status = sscanf(str_p+1, "%d", &ival);
1957  if (status != 1) { // couldn't properly parse the line
1958  fclose(fp);
1959  return lineNo;
1960  }
1961  info->fan6 = ival;
1962  } else if (strstr(line, "VTT")) {
1963  str_p = strstr(line, "|");
1964  if (str_p == NULL) { // couldn't find '|' within the line
1965  fclose(fp);
1966  return lineNo;
1967  }
1968  status = sscanf(str_p+1, "%f", &fval);
1969  if (status != 1) { // couldn't properly parse the line
1970  fclose(fp);
1971  return lineNo;
1972  }
1973  info->vtt = fval;
1974  } else if (strstr(line, "CPU1 Vcore")) {
1975  str_p = strstr(line, "|");
1976  if (str_p == NULL) { // couldn't find '|' within the line
1977  fclose(fp);
1978  return lineNo;
1979  }
1980  status = sscanf(str_p+1, "%f", &fval);
1981  if (status != 1) { // couldn't properly parse the line
1982  fclose(fp);
1983  return lineNo;
1984  }
1985  info->cpu1_vcore = fval;
1986  } else if (strstr(line, "CPU2 Vcore")) {
1987  str_p = strstr(line, "|");
1988  if (str_p == NULL) { // couldn't find '|' within the line
1989  fclose(fp);
1990  return lineNo;
1991  }
1992  status = sscanf(str_p+1, "%f", &fval);
1993  if (status != 1) { // couldn't properly parse the line
1994  fclose(fp);
1995  return lineNo;
1996  }
1997  info->cpu2_vcore = fval;
1998  } else if (strstr(line, "VDIMM AB")) {
1999  str_p = strstr(line, "|");
2000  if (str_p == NULL) { // couldn't find '|' within the line
2001  fclose(fp);
2002  return lineNo;
2003  }
2004  status = sscanf(str_p+1, "%f", &fval);
2005  if (status != 1) { // couldn't properly parse the line
2006  fclose(fp);
2007  return lineNo;
2008  }
2009  info->vdimm_ab = fval;
2010  } else if (strstr(line, "VDIMM CD")) {
2011  str_p = strstr(line, "|");
2012  if (str_p == NULL) { // couldn't find '|' within the line
2013  fclose(fp);
2014  return lineNo;
2015  }
2016  status = sscanf(str_p+1, "%f", &fval);
2017  if (status != 1) { // couldn't properly parse the line
2018  fclose(fp);
2019  return lineNo;
2020  }
2021  info->vdimm_cd = fval;
2022  } else if (strstr(line, "VDIMM EF")) {
2023  str_p = strstr(line, "|");
2024  if (str_p == NULL) { // couldn't find '|' within the line
2025  fclose(fp);
2026  return lineNo;
2027  }
2028  status = sscanf(str_p+1, "%f", &fval);
2029  if (status != 1) { // couldn't properly parse the line
2030  fclose(fp);
2031  return lineNo;
2032  }
2033  info->vdimm_ef = fval;
2034  } else if (strstr(line, "VDIMM GH")) {
2035  str_p = strstr(line, "|");
2036  if (str_p == NULL) { // couldn't find '|' within the line
2037  fclose(fp);
2038  return lineNo;
2039  }
2040  status = sscanf(str_p+1, "%f", &fval);
2041  if (status != 1) { // couldn't properly parse the line
2042  fclose(fp);
2043  return lineNo;
2044  }
2045  info->vdimm_gh = fval;
2046  } else if (strstr(line, "+1.1 V")) {
2047  str_p = strstr(line, "|");
2048  if (str_p == NULL) { // couldn't find '|' within the line
2049  fclose(fp);
2050  return lineNo;
2051  }
2052  status = sscanf(str_p+1, "%f", &fval);
2053  if (status != 1) { // couldn't properly parse the line
2054  fclose(fp);
2055  return lineNo;
2056  }
2057  info->p1_1v = fval;
2058  } else if (strstr(line, "+1.5 V")) {
2059  str_p = strstr(line, "|");
2060  if (str_p == NULL) { // couldn't find '|' within the line
2061  fclose(fp);
2062  return lineNo;
2063  }
2064  status = sscanf(str_p+1, "%f", &fval);
2065  if (status != 1) { // couldn't properly parse the line
2066  fclose(fp);
2067  return lineNo;
2068  }
2069  info->p1_5v = fval;
2070  } else if (strstr(line, "3.3V ")) {
2071  str_p = strstr(line, "|");
2072  if (str_p == NULL) { // couldn't find '|' within the line
2073  fclose(fp);
2074  return lineNo;
2075  }
2076  status = sscanf(str_p+1, "%f", &fval);
2077  if (status != 1) { // couldn't properly parse the line
2078  fclose(fp);
2079  return lineNo;
2080  }
2081  info->p3_3v = fval;
2082  } else if (strstr(line, "+3.3VSB")) {
2083  str_p = strstr(line, "|");
2084  if (str_p == NULL) { // couldn't find '|' within the line
2085  fclose(fp);
2086  return lineNo;
2087  }
2088  status = sscanf(str_p+1, "%f", &fval);
2089  if (status != 1) { // couldn't properly parse the line
2090  fclose(fp);
2091  return lineNo;
2092  }
2093  info->p3_3vsb = fval;
2094  } else if (strstr(line, "5V ")) {
2095  str_p = strstr(line, "|");
2096  if (str_p == NULL) { // couldn't find '|' within the line
2097  fclose(fp);
2098  return lineNo;
2099  }
2100  status = sscanf(str_p+1, "%f", &fval);
2101  if (status != 1) { // couldn't properly parse the line
2102  fclose(fp);
2103  return lineNo;
2104  }
2105  info->p5v = fval;
2106  } else if (strstr(line, "+5VSB")) {
2107  str_p = strstr(line, "|");
2108  if (str_p == NULL) { // couldn't find '|' within the line
2109  fclose(fp);
2110  return lineNo;
2111  }
2112  status = sscanf(str_p+1, "%f", &fval);
2113  if (status != 1) { // couldn't properly parse the line
2114  fclose(fp);
2115  return lineNo;
2116  }
2117  info->p5vsb = fval;
2118  } else if (strstr(line, "12V")) {
2119  str_p = strstr(line, "|");
2120  if (str_p == NULL) { // couldn't find '|' within the line
2121  fclose(fp);
2122  return lineNo;
2123  }
2124  status = sscanf(str_p+1, "%f", &fval);
2125  if (status != 1) { // couldn't properly parse the line
2126  fclose(fp);
2127  return lineNo;
2128  }
2129  info->p12v = fval;
2130  } else if (strstr(line, "VBAT")) {
2131  str_p = strstr(line, "|");
2132  if (str_p == NULL) { // couldn't find '|' within the line
2133  fclose(fp);
2134  return lineNo;
2135  }
2136  status = sscanf(str_p+1, "%f", &fval);
2137  if (status != 1) { // couldn't properly parse the line
2138  fclose(fp);
2139  return lineNo;
2140  }
2141  info->vbat = fval;
2142  } else if (strstr(line, "Chassis Intru")) {
2143  str_p = strstr(line, "|");
2144  if (str_p == NULL) { // couldn't find '|' within the line
2145  fclose(fp);
2146  return lineNo;
2147  }
2148  status = sscanf(str_p+1, "%d", &ival);
2149  if (status != 1) { // couldn't properly parse the line
2150  fclose(fp);
2151  return lineNo;
2152  }
2153  info->chassis_intru = ival;
2154  } else if (strstr(line, "PS1 Status")) {
2155  str_p = strstr(line, "|");
2156  if (str_p == NULL) { // couldn't find '|' within the line
2157  fclose(fp);
2158  return lineNo;
2159  }
2160  status = sscanf(str_p+1, "%x", &ival);
2161  if (status != 1) { // couldn't properly parse the line
2162  fclose(fp);
2163  return lineNo;
2164  }
2165  info->ps1_status = ival;
2166  } else if (strstr(line, "PS2 Status")) {
2167  str_p = strstr(line, "|");
2168  if (str_p == NULL) { // couldn't find '|' within the line
2169  fclose(fp);
2170  return lineNo;
2171  }
2172  status = sscanf(str_p+1, "%x", &ival);
2173  if (status != 1) { // couldn't properly parse the line
2174  fclose(fp);
2175  return lineNo;
2176  }
2177  info->ps2_status = ival;
2178  }
2179  }
2180 
2181  fclose(fp);
2182 
2183  return lineNo;
2184 }
2185 
2186 //---------------------------------------------------------------------------
2196 {
2197  FILE *fp;
2198  char line[128], *str_p;
2199  int status, ival;
2200  float fval;
2201  int lineNo=0;
2202  static DWORD last = 0;
2203  DWORD now;
2204 
2205  now = ss_time();
2206  if (now - last < UPDATE_INFO_PERIOD_IPMI) {
2207  return -1;
2208  }
2209 
2210  last = now; // keep current time stamp
2211 
2212  // init info structure
2213  info->cpu1_temp = -1.0;
2214  info->cpu2_temp = -1.0;
2215  info->pch_temp = -1.0;
2216  info->system_temp = -1.0;
2217  info->peripherial_temp = -1.0;
2218  info->vrmcpu1 = -1.0;
2219  info->vrmcpu2 = -1.0;
2220  info->vrmp1abc = -1.0;
2221  info->vrmp1def = -1.0;
2222  info->vrmp2abc = -1.0;
2223  info->vrmp2def = -1.0;
2224  info->p1_dimma1_temp = -1.0;
2225  info->p1_dimmd1_temp = -1.0;
2226  info->p2_dimma1_temp = -1.0;
2227  info->p2_dimmd1_temp = -1.0;
2228  info->fan1 = -1;
2229  info->fan2 = -1;
2230  info->fan3 = -1;
2231  info->fan5 = -1;
2232  info->fan6 = -1;
2233  info->p12v = -9999.0;
2234  info->p5vcc = -9999.0;
2235  info->p3_3vcc = -9999.0;
2236  info->vbat = -1;
2237  info->vcpu1 = -9999.0;
2238  info->vcpu2 = -9999.0;
2239  info->vdimmp1abc = -9999.0;
2240  info->vdimmp1def = -9999.0;
2241  info->vdimmp2abc = -9999.0;
2242  info->vdimmp2def = -9999.0;
2243  info->p5vsb = -9999.0;
2244  info->p3_3vsb = -9999.0;
2245  info->p1_8v_pch = -9999.0;
2246  info->pvnn_pch = -9999.0;
2247  info->p1_05v_pch = -9999.0;
2248  info->chassis_intru = -1;
2249  info->ps1_status = -1;
2250  info->ps2_status = -1;
2251  info->hdd_temp = -9999.0;
2252  info->hdd_status = -1;
2253 
2254  fp = fopen("/var/log/lem03.psi.ch_ipmi.log", "r");
2255  if (fp == NULL) {
2256  printf("\nCouldn't open log file.\n");
2257  return -1;
2258  }
2259 
2260  while (!feof(fp)) {
2261  fgets(line, sizeof(line), fp);
2262  lineNo++;
2263 
2264  if (strstr(line, "CPU1 Temp")) {
2265  str_p = strstr(line, "|");
2266  if (str_p == NULL) { // couldn't find '|' within the line
2267  fclose(fp);
2268  return lineNo;
2269  }
2270  status = sscanf(str_p+1, "%f", &fval);
2271  if (status != 1) { // couldn't properly parse the line
2272  fclose(fp);
2273  return lineNo;
2274  }
2275  info->cpu1_temp = fval;
2276  } else if (strstr(line, "CPU2 Temp")) {
2277  str_p = strstr(line, "|");
2278  if (str_p == NULL) { // couldn't find '|' within the line
2279  fclose(fp);
2280  return lineNo;
2281  }
2282  status = sscanf(str_p+1, "%f", &fval);
2283  if (status != 1) { // couldn't properly parse the line
2284  fclose(fp);
2285  return lineNo;
2286  }
2287  info->cpu2_temp = fval;
2288  } else if (strstr(line, "PCH Temp")) {
2289  str_p = strstr(line, "|");
2290  if (str_p == NULL) { // couldn't find '|' within the line
2291  fclose(fp);
2292  return lineNo;
2293  }
2294  status = sscanf(str_p+1, "%f", &fval);
2295  if (status != 1) { // couldn't properly parse the line
2296  fclose(fp);
2297  return lineNo;
2298  }
2299  info->pch_temp = fval;
2300  } else if (strstr(line, "System Temp")) {
2301  str_p = strstr(line, "|");
2302  if (str_p == NULL) { // couldn't find '|' within the line
2303  fclose(fp);
2304  return lineNo;
2305  }
2306  status = sscanf(str_p+1, "%f", &fval);
2307  if (status != 1) { // couldn't properly parse the line
2308  fclose(fp);
2309  return lineNo;
2310  }
2311  info->system_temp = fval;
2312  } else if (strstr(line, "Peripheral Temp")) {
2313  str_p = strstr(line, "|");
2314  if (str_p == NULL) { // couldn't find '|' within the line
2315  fclose(fp);
2316  return lineNo;
2317  }
2318  status = sscanf(str_p+1, "%f", &fval);
2319  if (status != 1) { // couldn't properly parse the line
2320  fclose(fp);
2321  return lineNo;
2322  }
2323  info->peripherial_temp = fval;
2324  } else if (strstr(line, "VRMCpu1 Temp")) {
2325  str_p = strstr(line, "|");
2326  if (str_p == NULL) { // couldn't find '|' within the line
2327  fclose(fp);
2328  return lineNo;
2329  }
2330  status = sscanf(str_p+1, "%f", &fval);
2331  if (status != 1) { // couldn't properly parse the line
2332  fclose(fp);
2333  return lineNo;
2334  }
2335  info->vrmcpu1 = fval;
2336  } else if (strstr(line, "VRMCpu2 Temp")) {
2337  str_p = strstr(line, "|");
2338  if (str_p == NULL) { // couldn't find '|' within the line
2339  fclose(fp);
2340  return lineNo;
2341  }
2342  status = sscanf(str_p+1, "%f", &fval);
2343  if (status != 1) { // couldn't properly parse the line
2344  fclose(fp);
2345  return lineNo;
2346  }
2347  info->vrmcpu2 = fval;
2348  } else if (strstr(line, "VRMP1ABC Temp")) {
2349  str_p = strstr(line, "|");
2350  if (str_p == NULL) { // couldn't find '|' within the line
2351  fclose(fp);
2352  return lineNo;
2353  }
2354  status = sscanf(str_p+1, "%f", &fval);
2355  if (status != 1) { // couldn't properly parse the line
2356  fclose(fp);
2357  return lineNo;
2358  }
2359  info->vrmp1abc= fval;
2360  } else if (strstr(line, "VRMP1DEF Temp")) {
2361  str_p = strstr(line, "|");
2362  if (str_p == NULL) { // couldn't find '|' within the line
2363  fclose(fp);
2364  return lineNo;
2365  }
2366  status = sscanf(str_p+1, "%f", &fval);
2367  if (status != 1) { // couldn't properly parse the line
2368  fclose(fp);
2369  return lineNo;
2370  }
2371  info->vrmp1def= fval;
2372  } else if (strstr(line, "VRMP2ABC Temp")) {
2373  str_p = strstr(line, "|");
2374  if (str_p == NULL) { // couldn't find '|' within the line
2375  fclose(fp);
2376  return lineNo;
2377  }
2378  status = sscanf(str_p+1, "%f", &fval);
2379  if (status != 1) { // couldn't properly parse the line
2380  fclose(fp);
2381  return lineNo;
2382  }
2383  info->vrmp2abc= fval;
2384  } else if (strstr(line, "VRMP2DEF Temp")) {
2385  str_p = strstr(line, "|");
2386  if (str_p == NULL) { // couldn't find '|' within the line
2387  fclose(fp);
2388  return lineNo;
2389  }
2390  status = sscanf(str_p+1, "%f", &fval);
2391  if (status != 1) { // couldn't properly parse the line
2392  fclose(fp);
2393  return lineNo;
2394  }
2395  info->vrmp2def= fval;
2396  } else if (strstr(line, "P1-DIMMA1 Temp")) {
2397  str_p = strstr(line, "|");
2398  if (str_p == NULL) { // couldn't find '|' within the line
2399  fclose(fp);
2400  return lineNo;
2401  }
2402  status = sscanf(str_p+1, "%f", &fval);
2403  if (status != 1) { // couldn't properly parse the line
2404  fclose(fp);
2405  return lineNo;
2406  }
2407  info->p1_dimma1_temp = fval;
2408  } else if (strstr(line, "P1-DIMMD1 Temp")) {
2409  str_p = strstr(line, "|");
2410  if (str_p == NULL) { // couldn't find '|' within the line
2411  fclose(fp);
2412  return lineNo;
2413  }
2414  status = sscanf(str_p+1, "%f", &fval);
2415  if (status != 1) { // couldn't properly parse the line
2416  fclose(fp);
2417  return lineNo;
2418  }
2419  info->p1_dimmd1_temp = fval;
2420  } else if (strstr(line, "P2-DIMMA1 Temp")) {
2421  str_p = strstr(line, "|");
2422  if (str_p == NULL) { // couldn't find '|' within the line
2423  fclose(fp);
2424  return lineNo;
2425  }
2426  status = sscanf(str_p+1, "%f", &fval);
2427  if (status != 1) { // couldn't properly parse the line
2428  fclose(fp);
2429  return lineNo;
2430  }
2431  info->p2_dimma1_temp = fval;
2432  } else if (strstr(line, "P2-DIMMD1 Temp")) {
2433  str_p = strstr(line, "|");
2434  if (str_p == NULL) { // couldn't find '|' within the line
2435  fclose(fp);
2436  return lineNo;
2437  }
2438  status = sscanf(str_p+1, "%f", &fval);
2439  if (status != 1) { // couldn't properly parse the line
2440  fclose(fp);
2441  return lineNo;
2442  }
2443  info->p2_dimmd1_temp = fval;
2444  } else if (strstr(line, "FAN1")) {
2445  str_p = strstr(line, "|");
2446  if (str_p == NULL) { // couldn't find '|' within the line
2447  fclose(fp);
2448  return lineNo;
2449  }
2450  status = sscanf(str_p+1, "%d", &ival);
2451  if (status != 1) { // couldn't properly parse the line
2452  fclose(fp);
2453  return lineNo;
2454  }
2455  info->fan1 = ival;
2456  } else if (strstr(line, "FAN2")) {
2457  str_p = strstr(line, "|");
2458  if (str_p == NULL) { // couldn't find '|' within the line
2459  fclose(fp);
2460  return lineNo;
2461  }
2462  status = sscanf(str_p+1, "%d", &ival);
2463  if (status != 1) { // couldn't properly parse the line
2464  fclose(fp);
2465  return lineNo;
2466  }
2467  info->fan2 = ival;
2468  } else if (strstr(line, "FAN3")) {
2469  str_p = strstr(line, "|");
2470  if (str_p == NULL) { // couldn't find '|' within the line
2471  fclose(fp);
2472  return lineNo;
2473  }
2474  status = sscanf(str_p+1, "%d", &ival);
2475  if (status != 1) { // couldn't properly parse the line
2476  fclose(fp);
2477  return lineNo;
2478  }
2479  info->fan3 = ival;
2480  } else if (strstr(line, "FAN5")) {
2481  str_p = strstr(line, "|");
2482  if (str_p == NULL) { // couldn't find '|' within the line
2483  fclose(fp);
2484  return lineNo;
2485  }
2486  status = sscanf(str_p+1, "%d", &ival);
2487  if (status != 1) { // couldn't properly parse the line
2488  fclose(fp);
2489  return lineNo;
2490  }
2491  info->fan5 = ival;
2492  } else if (strstr(line, "FAN6")) {
2493  str_p = strstr(line, "|");
2494  if (str_p == NULL) { // couldn't find '|' within the line
2495  fclose(fp);
2496  return lineNo;
2497  }
2498  status = sscanf(str_p+1, "%d", &ival);
2499  if (status != 1) { // couldn't properly parse the line
2500  fclose(fp);
2501  return lineNo;
2502  }
2503  info->fan6 = ival;
2504  } else if (strstr(line, "12V")) {
2505  str_p = strstr(line, "|");
2506  if (str_p == NULL) { // couldn't find '|' within the line
2507  fclose(fp);
2508  return lineNo;
2509  }
2510  status = sscanf(str_p+1, "%f", &fval);
2511  if (status != 1) { // couldn't properly parse the line
2512  fclose(fp);
2513  return lineNo;
2514  }
2515  info->p12v = fval;
2516  } else if (strstr(line, "5VCC")) {
2517  str_p = strstr(line, "|");
2518  if (str_p == NULL) { // couldn't find '|' within the line
2519  fclose(fp);
2520  return lineNo;
2521  }
2522  status = sscanf(str_p+1, "%f", &fval);
2523  if (status != 1) { // couldn't properly parse the line
2524  fclose(fp);
2525  return lineNo;
2526  }
2527  info->p5vcc = fval;
2528  } else if (strstr(line, "3.3VCC")) {
2529  str_p = strstr(line, "|");
2530  if (str_p == NULL) { // couldn't find '|' within the line
2531  fclose(fp);
2532  return lineNo;
2533  }
2534  status = sscanf(str_p+1, "%f", &fval);
2535  if (status != 1) { // couldn't properly parse the line
2536  fclose(fp);
2537  return lineNo;
2538  }
2539  info->p3_3vcc = fval;
2540  } else if (strstr(line, "VBAT")) {
2541  str_p = strstr(line, "|");
2542  if (str_p == NULL) { // couldn't find '|' within the line
2543  fclose(fp);
2544  return lineNo;
2545  }
2546  status = sscanf(str_p+1, "%x", &ival);
2547  if (status != 1) { // couldn't properly parse the line
2548  fclose(fp);
2549  return lineNo;
2550  }
2551  info->vbat = ival;
2552  } else if (strstr(line, "Vcpu1")) {
2553  str_p = strstr(line, "|");
2554  if (str_p == NULL) { // couldn't find '|' within the line
2555  fclose(fp);
2556  return lineNo;
2557  }
2558  status = sscanf(str_p+1, "%f", &fval);
2559  if (status != 1) { // couldn't properly parse the line
2560  fclose(fp);
2561  return lineNo;
2562  }
2563  info->vcpu1 = fval;
2564  } else if (strstr(line, "Vcpu2")) {
2565  str_p = strstr(line, "|");
2566  if (str_p == NULL) { // couldn't find '|' within the line
2567  fclose(fp);
2568  return lineNo;
2569  }
2570  status = sscanf(str_p+1, "%f", &fval);
2571  if (status != 1) { // couldn't properly parse the line
2572  fclose(fp);
2573  return lineNo;
2574  }
2575  info->vcpu2 = fval;
2576  } else if (strstr(line, "VDimmP1ABC")) {
2577  str_p = strstr(line, "|");
2578  if (str_p == NULL) { // couldn't find '|' within the line
2579  fclose(fp);
2580  return lineNo;
2581  }
2582  status = sscanf(str_p+1, "%f", &fval);
2583  if (status != 1) { // couldn't properly parse the line
2584  fclose(fp);
2585  return lineNo;
2586  }
2587  info->vdimmp1abc = fval;
2588  } else if (strstr(line, "VDimmP1DEF")) {
2589  str_p = strstr(line, "|");
2590  if (str_p == NULL) { // couldn't find '|' within the line
2591  fclose(fp);
2592  return lineNo;
2593  }
2594  status = sscanf(str_p+1, "%f", &fval);
2595  if (status != 1) { // couldn't properly parse the line
2596  fclose(fp);
2597  return lineNo;
2598  }
2599  info->vdimmp1def = fval;
2600  } else if (strstr(line, "VDimmP2ABC")) {
2601  str_p = strstr(line, "|");
2602  if (str_p == NULL) { // couldn't find '|' within the line
2603  fclose(fp);
2604  return lineNo;
2605  }
2606  status = sscanf(str_p+1, "%f", &fval);
2607  if (status != 1) { // couldn't properly parse the line
2608  fclose(fp);
2609  return lineNo;
2610  }
2611  info->vdimmp2abc = fval;
2612  } else if (strstr(line, "VDimmP2DEF")) {
2613  str_p = strstr(line, "|");
2614  if (str_p == NULL) { // couldn't find '|' within the line
2615  fclose(fp);
2616  return lineNo;
2617  }
2618  status = sscanf(str_p+1, "%f", &fval);
2619  if (status != 1) { // couldn't properly parse the line
2620  fclose(fp);
2621  return lineNo;
2622  }
2623  info->vdimmp2def = fval;
2624  } else if (strstr(line, "5VSB")) {
2625  str_p = strstr(line, "|");
2626  if (str_p == NULL) { // couldn't find '|' within the line
2627  fclose(fp);
2628  return lineNo;
2629  }
2630  status = sscanf(str_p+1, "%f", &fval);
2631  if (status != 1) { // couldn't properly parse the line
2632  fclose(fp);
2633  return lineNo;
2634  }
2635  info->p5vsb = fval;
2636  } else if (strstr(line, "3.3VSB")) {
2637  str_p = strstr(line, "|");
2638  if (str_p == NULL) { // couldn't find '|' within the line
2639  fclose(fp);
2640  return lineNo;
2641  }
2642  status = sscanf(str_p+1, "%f", &fval);
2643  if (status != 1) { // couldn't properly parse the line
2644  fclose(fp);
2645  return lineNo;
2646  }
2647  info->p3_3vsb = fval;
2648  } else if (strstr(line, "1.8V PCH")) {
2649  str_p = strstr(line, "|");
2650  if (str_p == NULL) { // couldn't find '|' within the line
2651  fclose(fp);
2652  return lineNo;
2653  }
2654  status = sscanf(str_p+1, "%f", &fval);
2655  if (status != 1) { // couldn't properly parse the line
2656  fclose(fp);
2657  return lineNo;
2658  }
2659  info->p1_8v_pch = fval;
2660  } else if (strstr(line, "PVNN PCH")) {
2661  str_p = strstr(line, "|");
2662  if (str_p == NULL) { // couldn't find '|' within the line
2663  fclose(fp);
2664  return lineNo;
2665  }
2666  status = sscanf(str_p+1, "%f", &fval);
2667  if (status != 1) { // couldn't properly parse the line
2668  fclose(fp);
2669  return lineNo;
2670  }
2671  info->pvnn_pch = fval;
2672  } else if (strstr(line, "1.05V PCH")) {
2673  str_p = strstr(line, "|");
2674  if (str_p == NULL) { // couldn't find '|' within the line
2675  fclose(fp);
2676  return lineNo;
2677  }
2678  status = sscanf(str_p+1, "%f", &fval);
2679  if (status != 1) { // couldn't properly parse the line
2680  fclose(fp);
2681  return lineNo;
2682  }
2683  info->p1_05v_pch = fval;
2684  } else if (strstr(line, "Chassis Intru")) {
2685  str_p = strstr(line, "|");
2686  if (str_p == NULL) { // couldn't find '|' within the line
2687  fclose(fp);
2688  return lineNo;
2689  }
2690  status = sscanf(str_p+1, "%x", &ival);
2691  if (status != 1) { // couldn't properly parse the line
2692  fclose(fp);
2693  return lineNo;
2694  }
2695  info->chassis_intru = ival;
2696  } else if (strstr(line, "PS1 Status")) {
2697  str_p = strstr(line, "|");
2698  if (str_p == NULL) { // couldn't find '|' within the line
2699  fclose(fp);
2700  return lineNo;
2701  }
2702  status = sscanf(str_p+1, "%x", &ival);
2703  if (status != 1) { // couldn't properly parse the line
2704  fclose(fp);
2705  return lineNo;
2706  }
2707  info->ps1_status = ival;
2708  } else if (strstr(line, "PS2 Status")) {
2709  str_p = strstr(line, "|");
2710  if (str_p == NULL) { // couldn't find '|' within the line
2711  fclose(fp);
2712  return lineNo;
2713  }
2714  status = sscanf(str_p+1, "%x", &ival);
2715  if (status != 1) { // couldn't properly parse the line
2716  fclose(fp);
2717  return lineNo;
2718  }
2719  info->ps2_status = ival;
2720  } else if (strstr(line, "AOC_SAS Temp")) {
2721  str_p = strstr(line, "|");
2722  if (str_p == NULL) { // couldn't find '|' within the line
2723  fclose(fp);
2724  return lineNo;
2725  }
2726  status = sscanf(str_p+1, "%f", &fval);
2727  if (status != 1) { // couldn't properly parse the line
2728  fclose(fp);
2729  return lineNo;
2730  }
2731  info->aoc_sas_temp = fval;
2732  } else if (strstr(line, "HDD Temp")) {
2733  str_p = strstr(line, "|");
2734  if (str_p == NULL) { // couldn't find '|' within the line
2735  fclose(fp);
2736  return lineNo;
2737  }
2738  status = sscanf(str_p+1, "%f", &fval);
2739  if (status != 1) { // couldn't properly parse the line
2740  fclose(fp);
2741  return lineNo;
2742  }
2743  info->hdd_temp = fval;
2744  } else if (strstr(line, "HDD Status")) {
2745  str_p = strstr(line, "|");
2746  if (str_p == NULL) { // couldn't find '|' within the line
2747  fclose(fp);
2748  return lineNo;
2749  }
2750  status = sscanf(str_p+1, "%x", &ival);
2751  if (status != 1) { // couldn't properly parse the line
2752  fclose(fp);
2753  return lineNo;
2754  }
2755  info->hdd_status = ival;
2756  }
2757  }
2758 
2759  fclose(fp);
2760 
2761  return lineNo;
2762 }
2763 
2764 //------------------------------------------------------------------
2775 {
2776  INT i, indexKV61, indexKV62, size;
2777  HNDLE hkey, hsubkey;
2778  KEY key;
2779  char magnetNames[100*32]; // just too lazy, assume max. array size of 100 beam line elements
2780  float measuredKV61, measuredKV62;
2781 
2782  measuredKV61 = measuredKV62 = 0.;
2783  indexKV61 = indexKV62 = 0;
2784 
2785  // determine index of KV61 and KV62
2786  if (db_find_key(hDB, 0, "/Equipment/Beamline/Settings/Names", &hkey) != DB_SUCCESS) {
2787  cm_msg(MERROR, "beam_shutter_open", "Warning: can't get Names array for beam shutter status.");
2788  return 1;
2789  }
2790 
2791  db_get_key(hDB, hkey, &key);
2792  size = key.num_values*32;
2793  db_get_data(hDB, hkey, magnetNames, &size, TID_STRING);
2794 
2795  for (i=0; i<key.num_values; i++) {
2796  if (strstr(magnetNames+NAME_LENGTH*i, "KV61 (1=open)") != NULL) indexKV61 = i;
2797  if (strstr(magnetNames+NAME_LENGTH*i, "KV62 (1=open)") != NULL) indexKV62 = i;
2798  }
2799 
2800  // now, get the measured values of the KV position
2801  if (db_find_key(hDB, 0, "/Equipment/Beamline/Variables/Measured", &hkey) != DB_SUCCESS) {
2802  cm_msg(MERROR, "beam_shutter_open", "Warning: can't determine status of beam shutters.");
2803  return 1;
2804  }
2805 
2806  size = sizeof(float);
2807 
2808  if (db_get_data_index(hDB, hkey, &measuredKV61, &size, indexKV61, TID_FLOAT) != DB_SUCCESS) {
2809  cm_msg(MERROR, "beam_shutter_open", "Warning: can't get measured value of KV61.");
2810  return 1;
2811  }
2812  if (db_get_data_index(hDB, hkey, &measuredKV62, &size, indexKV62, TID_FLOAT) != DB_SUCCESS) {
2813  cm_msg(MERROR, "beam_shutter_open", "Warning: can't get measured value of KV62.");
2814  return 1;
2815  }
2816 
2817  if (measuredKV61 == 1. && measuredKV62 == 1.)
2818  return 1;
2819 
2820  //cm_msg(MINFO, "beam_shutter_open", "KV61 = %f, KV62 = %f", measuredKV61, measuredKV62);
2821 
2822  return 0;
2823 }
2824 
2825 //------------------------------------------------------------------
2826 //-- Global hotlink dispatcher routines ----------------------------
2834 void update_t0shift(INT dummy1, INT dummy2, void *dummy3)
2835 {
2836  HNDLE hDB, hKey;
2837  INT i, size;
2838  char str[80];
2839 
2840  cm_get_experiment_database(&hDB, NULL);
2841 
2842  // the following is necessary to get the right value of Bpar
2843  size = sizeof(info.lem_setup_parameter.bpar);
2844  db_get_value(hDB, 0, "/Info/LEM_Setup_Parameter/Bpar", &info.lem_setup_parameter.bpar, &size, TID_BOOL, FALSE);
2845 
2846  if (info.lem_setup_parameter.bpar) {
2847  cm_msg(MINFO,"update_t0shift","Changed t0 shifts of decay histograms for magnet Bpar...");
2848  for ( i=0; i<N_DECAY_HISTS; i++)
2849  t0shift_param.delta_t0[i] += t0shift_param.shift_delta_t0[i];
2850  } else {
2851  for ( i=0; i<N_DECAY_HISTS; i++)
2852  t0shift_param.delta_t0[i] -= t0shift_param.shift_delta_t0[i];
2853  cm_msg(MINFO,"update_t0shift","Changed t0 shifts of decay histograms for magnet WEW...");
2854  }
2855 
2856  sprintf(str, "/%s/Parameters/t0Shift", analyzer_name);
2857  db_find_key(hDB, 0, str, &hKey);
2858  db_set_record(hDB, hKey, &t0shift_param, sizeof(t0shift_param), 0);
2859 
2860  return;
2861 }
2862 
2863 //-- end -------------------------------------------------------------------------
2864 
2865 
2866 //------------------------------------------------------------------
2871 void set_spin_rot_angle(INT hDB, INT hKey, void *dummy)
2872 {
2873  INT i, size;
2874  BOOL flag_spinrot;
2875  char str[80];
2876  float sr_current, right_plate, left_plate, right_rod, left_rod;
2877  float moderator_hv, a[4];
2878 
2879  // Check if the spin rotator is enable or disabled
2880  flag_spinrot = info.spinrot_parameter.SRenable;
2881 
2882  cm_msg(MINFO,"set_spin_rot_angle","Spin rotator called with %i enable/disable and angle of %f degrees", flag_spinrot, rotation_angle);
2883 
2884  if (flag_spinrot) {
2885  // Get moderator energy into moderator_hv
2886  moderator_hv = hv_event.demand[sc_ana_param.mod_hv_channel];
2887  // Check if moderator is set at a sensible value
2888  if ((moderator_hv <= 1.0) || (moderator_hv >= 21.0)) {
2889  al_trigger_alarm( "ana_Spin_rotator", "Moderator HV should be between 1 and 20kV for spin rotation!",
2890  "Warning", "Moderator HV should be between 1 and 20kV for spin rotation!", AT_INTERNAL);
2891  return;
2892  }
2893 
2894  // Check if rotation angle is within allowed range
2895  if ((rotation_angle >= 91.0) || (rotation_angle <= -91.0)) {
2896  al_trigger_alarm( "ana_Spin_rotator", "Rotation angle is out of range, +/- 90 degrees!",
2897  "Warning", "Rotation angle is out of range, +/- 90 degrees!", AT_INTERNAL);
2898  return;
2899  }
2900 
2901  // get parameters for spin rotator calibration
2902  a[0] = info.spinrot_parameter.a0;
2903  a[1] = info.spinrot_parameter.a1;
2904  a[2] = info.spinrot_parameter.a2;
2905  a[3] = info.spinrot_parameter.a3;
2906  a[4] = info.spinrot_parameter.a4;
2907 
2908  sr_current=((rotation_angle-90.)/a[0]+a[1])*sqrt(moderator_hv);
2909  right_plate=(sr_current*sqrt(moderator_hv))/(a[2]+pow(fabs(sr_current/sqrt(moderator_hv)+a[3]),a[4]));
2910  left_plate=-1.0*right_plate;
2911  right_rod=0.5*right_plate;
2912  left_rod=0.5*left_plate;
2913 
2914  // Now set the appropriate odb values
2915 
2916  // Set SR current into "/Equipment/Danfysik_Spin_Rot/Variables/Output[2]" SRCurrent
2917  if (db_find_key(hDB, 0, "/Equipment/Danfysik_Spin_Rot/Variables/Output", &hKey) == DB_SUCCESS ) {
2918  db_set_data_index(hDB, hKey, &sr_current, sizeof(sr_current), 2, TID_FLOAT); }
2919  if (db_find_key(hDB, 0, "/Equipment/HV/Variables/Demand", &hKey) == DB_SUCCESS ) {
2920  // Set SR Right plate into "/Equipment/HV/Variables/Demand[3]" right_plate
2921  db_set_data_index(hDB, hKey, &right_plate, sizeof(right_plate), 3, TID_FLOAT);
2922  // Set SR Left plate into "/Equipment/HV/Variables/Demand[2]" -1.0*right_plate
2923  db_set_data_index(hDB, hKey, &left_plate, sizeof(left_plate), 2, TID_FLOAT);
2924  // Set SR Left Rod into "/Equipment/HV/Variables/Demand[1]" -0.5*right_plate
2925  db_set_data_index(hDB, hKey, &left_rod, sizeof(left_rod), 1, TID_FLOAT);
2926  // Set SR Right Rod into "/Equipment/HV/Variables/Demand[0]" +0.5*right_plate
2927  db_set_data_index(hDB, hKey, &right_rod, sizeof(right_rod), 0, TID_FLOAT);}
2928 
2929  // Add messages to log
2930  cm_msg(MINFO,"set_spin_rot_angle","Changed spin rotation angle to %f degrees", rotation_angle);
2931  cm_msg(MINFO,"set_spin_rot_angle","SR current %f and potential %f", sr_current, right_plate);
2932  } else {
2933  // SR disabled, igonre angle change
2934  cm_msg(MINFO,"set_spin_rot_angle","Spin rotator disabled, angle not changed.");
2935  }
2936  return;
2937 }
2938 
2939 //-- end -------------------------------------------------------------------------
double pressure_3
Definition: nemu_experim.h:290
float input[44]
Definition: experim.h:11083
#define UPDATE_INFO_PERIOD_IPMI
Definition: analyzer.cxx:116
struct INFO::@293 lem_setup_parameter
double keysight_u8481a_timestamp
Definition: nemu_experim.h:286
ANA_MODULE * sc_module[]
Definition: analyzer.cxx:146
float implantation_energy
Definition: nemu_experim.h:302
INT32 rar_channel
Definition: experim.h:564
#define UPDATE_INFO_PERIOD
Definition: analyzer.cxx:115
INT beam_shutter_open(HNDLE hDB)
Definition: analyzer.cxx:2774
void get_sum_filename(char *filename)
Definition: analyzer.cxx:898
INT32 sample_zeroflux_channel
Definition: experim.h:481
VME_STATS vme_stats
Required ODB structures.
Definition: analyzer.cxx:82
SCALER_SETTINGS scaler_settings
Definition: analyzer.cxx:86
int t0[N_DECAY_HISTS]
Definition: nemu_experim.h:323
#define T0SHIFT_PARAM_STR(_name)
Definition: experim.h:523
int proposal_number
Definition: nemu_experim.h:383
double channelCounts[N_TDC_CHANNELS]
Definition: nemu_experim.h:104
ANA_MODULE tof_ana_module
void set_spin_rot_angle(INT hDB, INT hKey, void *dummy)
Definition: analyzer.cxx:2871
void update_t0shift(INT dummy1, INT dummy2, void *dummy3)
Definition: analyzer.cxx:2834
float moderator_hv
Definition: experim.h:1343
struct DECAYANAMODULE_PARAM::@1::@3 decaybin
INT32 ral_channel
Definition: experim.h:563
#define EXP_EDIT_STR(_name)
Definition: experim.h:54
RATE_BANK rate_bank
Definition: analyzer.cxx:87
ANA_MODULE * trigger_module[]
Definition: analyzer.cxx:133
float p2
Definition: nemu_experim.h:308
float var_sample_hv
Definition: experim.h:1348
DECAYANAMODULE_PARAM decay_ana_param
double tektronix_set_power
Definition: nemu_experim.h:279
char lem_setup[STR_SIZE]
Definition: nemu_experim.h:297
BANK_LIST scaler_bank_list[]
Definition: analyzer.cxx:167
float var_moderator_hv
Definition: experim.h:1347
#define INFO_STR(_name)
Definition: nemu_experim.h:397
const char * analyzer_name
Definition: analyzer.cxx:71
RATE_BANK_STR(rate_bank_str)
float p1_dimma1_temp
Definition: nemu_experim.h:245
double tektronix_timestamp
Definition: nemu_experim.h:278
#define N_OFFSET_PPC_HISTOGRAMS
ID offset of postpileup-rejected histograms.
Definition: nemu_experim.h:72
void get_t0()
Definition: analyzer.cxx:1419
ANA_MODULE mcp1_ana_module
#define HISTOGRAM_WRITE_PERIOD
Definition: analyzer.cxx:114
static INT write_flag
Definition: analyzer.cxx:117
char moderator[STR_SIZE]
Definition: nemu_experim.h:295
static INT sum_count
Definition: analyzer.cxx:118
struct DECAYANAMODULE_PARAM::@0 histotitles
float a1
Definition: nemu_experim.h:330
ANA_MODULE pileup_ana_module
INT odb_size
Definition: analyzer.cxx:77
INT read_lem03_ipmi_log(LEM03_IPMI_LOG *info)
Definition: analyzer.cxx:2195
void disp_scaler(INT n)
float sample_b
Definition: experim.h:1346
INT analyzer_loop()
Definition: analyzer.cxx:753
HV_EVENT hv_event
Definition: analyzer.cxx:95
float var_sample_b
Definition: experim.h:1350
char runname[256]
Definition: analyzer.cxx:79
BOOL SRenable
Definition: nemu_experim.h:335
double keysight_u2002a_timestamp
Definition: nemu_experim.h:284
double ana_pico_timestamp
Definition: nemu_experim.h:281
double pressure_1
Definition: nemu_experim.h:288
struct DECAYANAMODULE_PARAM::@1 histobinning
struct DECAYANAMODULE_PARAM::@0::@2 decaytitles
double keysight_u2002a_measured_power
Definition: nemu_experim.h:285
float sample_t
Definition: experim.h:1345
char sample_name[128]
Definition: nemu_experim.h:298
SCANAMODULE_PARAM sc_ana_param
float delta_t0[8]
Definition: experim.h:519
struct INFO::@294 t0_parameter
#define STR_SIZE
Definition: nemu_experim.h:293
void get_t0L3RA()
Definition: analyzer.cxx:1521
MEAN_BANK mean
float a3
Definition: nemu_experim.h:332
float a4
Definition: nemu_experim.h:333
float rotation_angle
Definition: nemu_experim.h:334
float measured[16]
Definition: experim.h:3915
float a0
Definition: nemu_experim.h:329
float peripherial_temp
Definition: nemu_experim.h:238
INT ana_resume_run(INT run_number, char *error)
Definition: analyzer.cxx:735
void extract_summary_data()
Definition: analyzer.cxx:935
INFO info
Definition: analyzer.cxx:94
char comment[136]
Definition: experim.h:27
ANA_MODULE * scaler_module[]
Definition: analyzer.cxx:141
TRIGGER_SETTINGS trigger_settings
Definition: analyzer.cxx:93
INT read_lem00_ipmi_log(LEM00_IPMI_LOG *info)
Definition: analyzer.cxx:1733
POSI_BANK posi_bank
Definition: analyzer.cxx:91
static DWORD last_histogram_write
Definition: analyzer.cxx:112
#define TDSAMPLETOF_PARAM_STR(_name)
Definition: experim.h:569
static TMusrRunHeader * header
Definition: analyzer.cxx:109
struct INFO::@300 file_header_info
INT read_microwave_log(MICROWAVE_LOG *microwave_info)
Definition: analyzer.cxx:1651
float a2
Definition: nemu_experim.h:331
INT analyzer_exit()
Definition: analyzer.cxx:572
INT32 rab_channel
Definition: experim.h:566
RUNINFO runinfo
Definition: analyzer.cxx:83
float wew[2]
Definition: nemu_experim.h:312
char pgroup[80]
Definition: nemu_experim.h:385
static float rotation_angle
Definition: analyzer.cxx:120
double tektronix_set_frequency
Definition: nemu_experim.h:280
float p2_dimma1_temp
Definition: nemu_experim.h:247
ANALYZE_REQUEST analyze_request[]
Definition: analyzer.cxx:195
float sample_hv
Definition: experim.h:1344
char beamline_settings[132]
Definition: nemu_experim.h:304
float p2_dimmd1_temp
Definition: nemu_experim.h:248
BANK_LIST trigger_bank_list[]
Definition: analyzer.cxx:158
char line[MAXLINE]
char sample_cryo[NAME_LENGTH]
Definition: nemu_experim.h:299
float p1
Definition: nemu_experim.h:307
SRAT_BANK srat_bank
Definition: analyzer.cxx:89
INT32 sample_hv_channel
Definition: experim.h:480
SRAT_BANK_STR(srat_bank_str)
float p0
Definition: nemu_experim.h:306
TFolder * gManaHistosFolder
INT write_histogram_file()
Definition: analyzer.cxx:817
float p3
Definition: nemu_experim.h:309
float shift_delta_t0[8]
Definition: experim.h:520
HNDLE hKey
struct INFO::@292 magnet_parameter
float leff_RAoff
Definition: nemu_experim.h:326
static TFolder * gRunHeader
Definition: analyzer.cxx:107
TDSAMPLETOF_PARAM tdsampletof_param
Definition: analyzer.cxx:100
ANA_MODULE sc_ana_module
EXP_EDIT exp_edit
Definition: analyzer.cxx:84
void update_info()
Definition: analyzer.cxx:1022
SCS2001M_EVENT scs2001m_event
Definition: analyzer.cxx:97
#define SCALER_SETTINGS_STR(_name)
Definition: experim.h:1199
float magnetic_field
Definition: nemu_experim.h:303
ANA_MODULE scaler_rate_sum
#define MEAN_BANK_STR(_name)
Definition: experim.h:1353
INT32 mod_hv_channel
Definition: experim.h:477
#define N_SCALER
total number of scaler channels
Definition: nemu_experim.h:63
float demand[16]
Definition: experim.h:3914
float energy_loss(float moderator_hv)
Definition: analyzer.cxx:972
BANK_LIST sc_bank_list[]
Definition: analyzer.cxx:179
INT32 l3_channel
Definition: experim.h:562
#define EXP_PARAM_STR(_name)
Definition: experim.h:30
INT ana_end_of_run(INT run_number, char *error)
Definition: analyzer.cxx:630
INT32 moderator_channel
Definition: experim.h:561
struct INFO::@295 spinrot_parameter
INT analyzer_loop_period
Definition: analyzer.cxx:74
float p1_dimma1_temp
Definition: nemu_experim.h:204
static DWORD last_update_info_write
Definition: analyzer.cxx:113
float var_sample_t
Definition: experim.h:1349
float bpar[2]
Definition: nemu_experim.h:313
HNDLE hDB
float p1_dimmd1_temp
Definition: nemu_experim.h:246
char main_proposer[80]
Definition: nemu_experim.h:384
INT ana_pause_run(INT run_number, char *error)
Definition: analyzer.cxx:726
#define N_OFFSET_ONOFF_HISTOGRAMS
ID offset for &quot;on/off&quot;, &quot;red/green&quot; histograms: no offset means &quot;off&quot;.
Definition: nemu_experim.h:73
float p1_dimmb1_temp
Definition: nemu_experim.h:205
float peripherial_temp
Definition: nemu_experim.h:202
#define N_DECAY_HISTS
number of LE-uSR npp decay histograms
Definition: nemu_experim.h:71
float p2_dimmf1_temp
Definition: nemu_experim.h:207
static TObjArray Slist(0)
float p2_dimme1_temp
Definition: nemu_experim.h:206
INT32 rat_channel
Definition: experim.h:565
double ana_pico_set_frequency
Definition: nemu_experim.h:283
float leff_RAon
Definition: nemu_experim.h:325
T0SHIFT_PARAM t0shift_param
Definition: analyzer.cxx:99
POSI_BANK_STR(posi_bank_str)
ANA_MODULE decay_ana_module
double ana_pico_set_power
Definition: nemu_experim.h:282
INT versionCounter
Definition: analyzer.cxx:80
EXP_PARAM exp_param
Definition: analyzer.cxx:85
int t0Hist[N_DECAY_HISTS]
Definition: nemu_experim.h:324
float get_magnetic_field(float current)
Definition: analyzer.cxx:998
double keysight_u8481a_measured_power
Definition: nemu_experim.h:287
double pressure_2
Definition: nemu_experim.h:289
INT ana_begin_of_run(INT run_number, char *error)
Definition: analyzer.cxx:579
INT analyzer_init()
Definition: analyzer.cxx:262
struct INFO::@291 energy_loss_parameter
void update_run_header()
Definition: analyzer.cxx:1096