PAASS
Software suite to Acquire and Analyze Data from Pixie16
headReader.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <string.h>
4 
5 #include "Unpacker.hpp"
6 #include "ScanInterface.hpp"
7 #include "hribf_buffers.h"
8 
12 
13 void help(char *name_){
14  std::cout << " SYNTAX: " << name_ << " [options] <files ...>\n";
15  std::cout << " Available options:\n";
16  std::cout << " --columns | Output file information in tab-delimited columns.\n";
17 }
18 
19 int main(int argc, char *argv[]){
20  if(argc < 2){
21  std::cout << " Error: Invalid number of arguments to " << argv[0] << ". Expected 1, received " << argc-1 << ".\n";
22  help(argv[0]);
23  return 1;
24  }
25 
26  bool col_output = false;
27  int file_format = -1;
28  int file_count = 1;
29  std::string dummy, extension;
30  for(int i = 1; i < argc; i++){
31  // Check for command line options.
32  if(strcmp(argv[i], "--columns") == 0){
33  col_output = true;
34  continue;
35  }
36 
37  if(!col_output)
38  std::cout << "File no. " << file_count++ << ": " << argv[i] << std::endl;
39  else
40  std::cout << file_count++ << "\t" << argv[i] << "\t";
41 
42  extension = get_extension(argv[i], dummy);
43  if(extension == "ldf") // List data format file
44  file_format = 0;
45  else if(extension == "pld") // Pixie list data file format
46  file_format = 1;
47  else{
48  if(!col_output)
49  std::cout << " ERROR! Invalid file extension '" << extension << "'.\n\n";
50  else
51  std::cout << "FAILED\n";
52  continue;
53  }
54 
55  std::ifstream file(argv[i], std::ios::binary);
56  if(!file.is_open() || !file.good()){
57  if(!col_output)
58  std::cout << " ERROR! Failed to open input file! Check that the path is correct.\n\n";
59  else
60  std::cout << "FAILED\n";
61  file.close();
62  continue;
63  }
64 
65  // Start reading the file
66  // Every poll2 ldf file starts with a DIR buffer followed by a HEAD buffer
67  if(file_format == 0){
68  ldfDir.Read(&file);
69  ldfHead.Read(&file);
70  if(!col_output){
71  ldfDir.Print();
72  ldfHead.Print();
73  }
74  else{
75  ldfDir.PrintDelimited();
76  ldfHead.PrintDelimited();
77  }
78  std::cout << std::endl;
79  }
80  else if(file_format == 1){
81  pldHead.Read(&file);
82  if(!col_output)
83  pldHead.Print();
84  else
85  pldHead.PrintDelimited();
86  std::cout << std::endl;
87  }
88 
89  file.close();
90  }
91 
92  return 0;
93 }
94 
95 
PLD_header pldHead
Definition: headReader.cpp:11
void Print()
Print header information.
The pld header contains information about the run including the date/time, the title, and the run number.
Definition: hribf_buffers.h:70
void PrintDelimited(const char &delimiter_='\t')
Print dir buffer information in a delimited list.
HEAD_buffer ldfHead
Definition: headReader.cpp:10
A class to handle reading from various UTK/ORNL pixie16 data formats.
void help(char *name_)
Definition: headReader.cpp:13
void Print()
Print dir buffer information.
void Print()
Print header information.
void PrintDelimited(const char &delimiter_='\t')
Print header information in a delimited list.
int main(int argc, char *argv[])
Definition: headReader.cpp:19
void PrintDelimited(const char &delimiter_='\t')
Print header information in a delimited list.
virtual bool Read(std::ifstream *file_)
Read a DIR buffer from a file. Return false if buffer has the wrong header and return true otherwise...
virtual bool Read(std::ifstream *file_)
Read a HEAD buffer from a pld format file. Return false if buffer has the wrong header and return tru...
virtual bool Read(std::ifstream *file_)
Read a HEAD buffer from a file. Return false if buffer has the wrong header and return true otherwise...
A class to handle the unpacking of UTK/ORNL style pixie16 data spills.
DIR_buffer ldfDir
Definition: headReader.cpp:9
Handles poll2 output data files.
std::string get_extension(std::string filename_, std::string &prefix)
Get the file extension from an input filename string.