HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pmm2Header.cxx
Go to the documentation of this file.
1 //
2 // File Pmm2Header.cxx
3 //
11 #include "Pmm2Header.h"
12 #include <cstdlib>
13 #include <cstdio>
14 #include <iostream>
15 #include <time.h>
16 
17 
18 //TODO Header format T2K -> MINOS
19 #define HARO_RUN_HEADER_LEN 120
20 
21  // ASCII message length
22 #define PFX_8_BIT_CONTENT_MASK 0xFF00 // Mask to select 8 MSB's of prefix
23 #define PFX_ASCII_MSG_LEN 0x0100
24 //
25 // Macros to act on 8-bit data content
26 //
27 #define GET_ASCII_LEN(w) (((w) & 0x00FF) >> 0)
28 #define PUT_ASCII_LEN(w) (PFX_ASCII_MSG_LEN | ((w) & 0x00FF))
29 
30 ClassImp(Pmm2Header)
31 
33 {
34  // Init
35  fSubrun = 0;
36  fPmm2Temperature = 0.0;
37  fStatus = NULL;
38  fHeader = new char[(HARO_RUN_HEADER_LEN)+1];
39  fHeader[HARO_RUN_HEADER_LEN] = 0; // Zero termination for string
40  fHeader[0] = 0; // Zero string
41 }
42 
44 {
45  unsigned short sh, al;
46 
47  fHeader = new char[(HARO_RUN_HEADER_LEN)+1];
48  fHeader[HARO_RUN_HEADER_LEN] = 0; // Zero termination for string
49  fHeader[0] = 0; // Zero string
50 
51  // Init
52  fSubrun = 0;
53  fPmm2Temperature = 0.0;
54  fStatus = NULL;
55 
56 // Read prefix
57  if (std::fread(&sh, sizeof(unsigned short), 1, fIn) != 1)
58  {
59  printf("Error: could not read first prefix.\n");
60  return;
61  }
62  //f->tot_file_rd+= sizeof(unsigned short);
63 
64  // This must be the prefix for an ASCII string
66  {
67  printf("Error: missing string prefix in 0x%x\n", sh);
68  return;
69  }
70  al = GET_ASCII_LEN(sh);
71 
72  // Read Run information string
73  if (std::fread(fHeader, sizeof(char), al, fIn) != al)
74  {
75  printf("Error: could not read %d characters.\n", al);
76  return;
77  }
78  fHeader[al] = 0;
79  // std::printf("nr %d hdr %s\n",al,fHeader);
80  }
81 
82 
84  {
85  struct tm startTime;
86  char *str, *endptr;
87  const char *timefmt = "R%Y_%m_%d-%H_%M_%S-";
88 
89  //std::printf("hdr %s\n",fHeader);
90  if ( (str = strptime(fHeader,timefmt,&startTime)) == (char *)NULL )
91  {
92  printf("HARPO Bad Header %s\n",fHeader);
93  return false;
94  };
95 
96  //This to make valgrin happy
97  startTime.tm_isdst = -1; /* Not set by strptime(); tells mktime()
98  to determine whether daylight saving time
99  is in effect */
100 
101  //std::printf("seq %s\n",str);
102 
103  fTime = mktime(&startTime);
104 
105 
106  //str++; // Skeep '-'
107  fSubrun = strtol(str, &endptr, 10);
108 
109  if (endptr == str) {
110  std::cout << "No subrun digits were found" << std::endl;
111  };
112  return true;
113  }
114 
116  {
117  std::cout << "--- Pmm2Header" << std::endl
118  << "Start Time : " << fTime << std::endl
119  << "Pmm2 Run Header : " << fHeader << std::endl
120  << "Pmm2 Sub Run Number : " << fSubrun << std::endl;
121 
122  }
123 
A class hold HARPO run iformation.
#define PFX_ASCII_MSG_LEN
Definition: Pmm2Header.cxx:23
double fPmm2Temperature
Definition: Pmm2Header.h:44
long fSubrun
Definition: Pmm2Header.h:40
#define HARO_RUN_HEADER_LEN
Definition: Pmm2Header.cxx:19
Bool_t check()
Definition: Pmm2Header.cxx:83
A class hold HARPO run information.
Definition: Pmm2Header.h:17
const char * timefmt
void print()
Definition: Pmm2Header.cxx:115
#define GET_ASCII_LEN(w)
Definition: Pmm2Header.cxx:27
Pmm2Status * fStatus
Definition: Pmm2Header.h:45
#define PFX_8_BIT_CONTENT_MASK
Definition: Pmm2Header.cxx:22