HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoFeminosHeader.cxx
Go to the documentation of this file.
1 //
2 // File HarpoFeminosHeader.cxx
3 //
11 #include "HarpoConfig.h"
12 #include "HarpoFeminosHeader.h"
13 #include "HarpoFeminosReader.h"
14 #include "HarpoPedMgr.h"
15 #include <cstdlib>
16 #include <cstdio>
17 #include <iostream>
18 #include <time.h>
19 
20 // From D. Calvet
21 #include "frame.h"
22 
23 
24 //Feminos has variable header length
25 #define HARO_RUN_HEADER_LEN 256
26 
27 ClassImp(HarpoFeminosHeader)
28 
30 {
31  fHeader = new char[(HARO_RUN_HEADER_LEN)+1];
32  fHeader[HARO_RUN_HEADER_LEN] = 0; // Zero termination for string
33  fHeader[0] = 0; // Zero string
34  peds = NULL;
35 }
36 
38 {
39  //size_t nr;
40  unsigned short sh, al;
41 
42  fHeader = new char[(HARO_RUN_HEADER_LEN)+1];
43  fHeader[HARO_RUN_HEADER_LEN] = 0; // Zero termination for string
44  fHeader[0] = 0; // Zero string
45  peds = NULL;
46 
47 // Read prefix
48  if (std::fread(&sh, sizeof(unsigned short), 1, fIn) != 1)
49  {
50  printf("Error: could not read first prefix.\n");
51  return;
52  }
53  //f->tot_file_rd+= sizeof(unsigned short);
54 
55  // This must be the prefix for an ASCII string
57  {
58  printf("Error: missing string prefix in 0x%x\n", sh);
59  return;
60  }
61  al = GET_ASCII_LEN(sh);
62 
63  // Read Run information string
64  if (std::fread(fHeader, sizeof(char), al, fIn) != al)
65  {
66  printf("Error: could not read %d characters.\n", al);
67  return;
68  }
69  fHeader[al] = 0;
70  //std::printf("nr %zi hdr %s\n",al,fHeader);
71  // ferror ? , feof ?
72 }
73 
74 
76  {
77  struct tm startTime;
78  char *str, *endptr;
79  const char *timefmt = "R%Y_%m_%d-%H_%M_%S-";
80 
81 
82  //std::printf("hdr %s\n",fHeader);
83  if ( (str = strptime(fHeader,timefmt,&startTime)) == (char *)NULL )
84  {
85  printf("FEMINOS Bad Header %s\n",fHeader);
86  return false;
87  };
88 
89  //This to make valgrin happy
90  startTime.tm_isdst = -1; /* Not set by strptime(); tells mktime()
91  to determine whether daylight saving time
92  is in effect */
93 
94  //std::printf("seq %s\n",str);
95 
96  fTime = mktime(&startTime);
97 
98 
99  //str++; // Skeep '-'
100  fSubrun = strtol(str, &endptr, 10);
101 
102  if (endptr == str) {
103  std::cout << "No subrun digits were found" << std::endl;
104  };
105 
107  HarpoPedMgr * pedmgr = gHConfig->GetHarpoPedMgr();
108  Long64_t run = gHConfig->GetRunNo();
109 
110  peds = pedmgr->Lookup(run,rdr->GetDet());
111 
112  return true;
113  }
114 
116  {
117  std::cout << "--- HarpoFeminosHeader" << std::endl
118  << "Start Time : " << fTime << std::endl
119  << "Femios Run Header : " << fHeader << std::endl
120  << "Femios Sub Run Number : " << fSubrun << std::endl;
121  }
122 
A class hold HARPO run iformation.
Long64_t GetRunNo()
Set Run Number.
Definition: HarpoConfig.h:127
HarpoPedestal * Lookup(Long_t run, Long_t detno)
! Serach pedestal and means for given plane
Definition: HarpoPedMgr.cxx:37
#define PFX_ASCII_MSG_LEN
Definition: frame.h:60
HarpoPedMgr * GetHarpoPedMgr()
Get pointer to Harpo Feminos pdestal manager.
Definition: HarpoConfig.h:163
#define HARO_RUN_HEADER_LEN
A class hold HARPO run iformation.
#define PFX_8_BIT_CONTENT_MASK
Definition: frame.h:59
const char * timefmt
A class which read HARPO dcc file from one FEMINOS and creant Dcc Events and Dcc Headers for FEMINOS ...
HarpoConfig * gHConfig
#define GET_ASCII_LEN(w)
Definition: frame.h:157
Int_t GetDet()
Define plane X or Y.
HarpoPedestal * peds