FileInfo.h 1.93 KB
Newer Older
1
2
3
4
5
6
7
8
9
#ifndef _evb_bu_FileInfo_h_
#define _evb_bu_FileInfo_h_

#include <ios>
#include <memory>
#include <cstdint>
#include <ctime>
#include <string>

10
11
12
#ifdef EVB_USE_LOCS_VECTOR
#include "evb/DataLocations.h"
#endif
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

namespace evb {

  namespace bu { // namespace evb::bu

    struct FileHeader
    {
      const uint8_t id[4]      = {0x52,0x41,0x57,0x5f}; // "RAW_"
      const uint8_t version[4] = {0x30,0x30,0x30,0x31}; // "0001"
      const uint16_t headerSize = 24;
      uint16_t eventCount = 0;
      uint32_t lumiSection = 0;
      uint64_t fileSize = 24;
    };

    struct FileInfo
    {
      FileHeader header;
      const time_t creationTime;
      const std::string fileName;
      std::vector<EventPtr> events;
34
35
36
#ifdef EVB_USE_LOCS_VECTOR
      DataLocations dataLocations;
#endif
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

      FileInfo(const std::string fileName)
        : creationTime(time(0)),fileName(fileName) {};

      double getFileAge() const
      { return difftime(time(0),creationTime); }

    };

    using FileInfoPtr = std::unique_ptr<FileInfo>;

    inline std::ostream& operator<<
    (
      std::ostream& s,
      const evb::bu::FileInfo& fileInfo
    )
    {
      s << "fileName=" << fileInfo.fileName << " ";
      s << "id=";
      for (const uint8_t& c : fileInfo.header.id)
        s << static_cast<char>(c);
      for (const uint8_t& c : fileInfo.header.version)
        s << static_cast<char>(c);
      s << " ";
      s << "headerSize=" << fileInfo.header.headerSize << " Bytes ";
      s << "eventCount=" << fileInfo.header.eventCount << " ";
      s << "lumiSection=" << fileInfo.header.lumiSection << " ";
      s << "fileSize=" << fileInfo.header.fileSize << " Bytes";
      s << "fileAge=" << std::fixed << std::setprecision(2) << fileInfo.getFileAge() << " seconds";

      return s;
    }

  } } // namespace evb::bu

#endif // _evb_bu_FileInfo_h_


/// emacs configuration
/// Local Variables: -
/// mode: c++ -
/// c-basic-offset: 2 -
/// indent-tabs-mode: nil -
/// End: -