Project
Loading...
Searching...
No Matches
rawReaderTRUDigits.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include <iostream>
16#include <boost/program_options.hpp>
17
18#include <TTree.h>
19
22#include "EMCALBase/Mapper.h"
26#include <fairlogger/Logger.h>
27
28namespace bpo = boost::program_options;
29// using namespace o2::emcal;
30
31int main(int argc, char** argv)
32{
33 bpo::variables_map vm;
34 bpo::options_description opt_general("Usage:\n " + std::string(argv[0]) +
35 " <cmds/options>\n"
36 " Tool will decode the DDLx data for EMCAL 0\n"
37 "Commands / Options");
38 bpo::options_description opt_hidden("");
39 bpo::options_description opt_all;
40 bpo::positional_options_description opt_pos;
41
42 try {
43 auto add_option = opt_general.add_options();
44 add_option("help,h", "Print this help message");
45 add_option("verbose,v", bpo::value<uint32_t>()->default_value(0), "Select verbosity level [0 = no output]");
46 add_option("version", "Print version information");
47 add_option("input-file,i", bpo::value<std::string>()->required(), "Specifies input file.");
48 add_option("debug,d", bpo::value<uint32_t>()->default_value(0), "Select debug output level [0 = no debug output]");
49
50 opt_all.add(opt_general).add(opt_hidden);
51 bpo::store(bpo::command_line_parser(argc, argv).options(opt_all).positional(opt_pos).run(), vm);
52
53 if (vm.count("help") || argc == 1) {
54 std::cout << opt_general << std::endl;
55 exit(0);
56 }
57
58 if (vm.count("version")) {
59 // std::cout << GitInfo();
60 exit(0);
61 }
62
63 bpo::notify(vm);
64 } catch (bpo::error& e) {
65 std::cerr << "ERROR: " << e.what() << std::endl
66 << std::endl;
67 std::cerr << opt_general << std::endl;
68 exit(1);
69 } catch (std::exception& e) {
70 std::cerr << e.what() << ", application will now exit" << std::endl;
71 exit(2);
72 }
73
74 auto rawfilename = vm["input-file"].as<std::string>();
75
78 reader.setDefaultDataDescription(o2::header::gDataDescriptionRawData);
79 reader.setDefaultReadoutCardType(o2::raw::RawFileReader::RORC);
80 reader.addFile(rawfilename);
81 reader.init();
82
84 o2::emcal::TriggerMappingV2 triggermapping;
85
86 std::unique_ptr<TFile> treefile(TFile::Open("trudata.root", "RECREATE"));
87 TTree trudata("trudata", "Tree with TRU data");
88 // branches in tree
89 struct collisiontrigger {
90 unsigned long bc;
91 unsigned long orbit;
92 } mycollision;
93 int absFastOR;
94 int starttime;
95 std::vector<int> timesamples;
96 tree->Branch(&mycollision, "collisiontrigger", "bc,orbit/l");
97 tree->Branch(&starttime, "starttime", "starttime/i");
98 tree->Branch(&timesamples, "timesamples", ""); // @todo check how to write std::vector to tree;
99
100 while (1) {
101 int tfID = reader.getNextTFToRead();
102 if (tfID >= reader.getNTimeFrames()) {
103 LOG(info) << "nothing left to read after " << tfID << " TFs read";
104 break;
105 }
106 std::vector<char> dataBuffer; // where to put extracted data
107 for (int il = 0; il < reader.getNLinks(); il++) {
108 auto& link = reader.getLink(il);
109 std::cout << "Decoding link " << il << std::endl;
110
111 auto sz = link.getNextTFSize(); // size in bytes needed for the next TF of this link
112 dataBuffer.resize(sz);
113 link.readNextTF(dataBuffer.data());
114
115 // Parse
116 o2::emcal::RawReaderMemory parser(dataBuffer);
117 while (parser.hasNext()) {
118 parser.next();
119 auto rdh = parser.getRawHeader();
120 auto ddl = o2::raw::RDHUtils::getFEEID(parser.getRawHeader());
121 // Exclude STU DDLs
122 if (ddl >= 40) {
123 continue;
124 }
125
126 mycollision.bc = o2::raw::RDHUtils::getTriggerBC(rdh);
127 mycollision.orbit = o2::raw::RDHUtils::getTriggerOrbit(rdh);
128
129 o2::emcal::AltroDecoder decoder(parser);
130 decoder.decode();
131 auto& ddlmapping = mapper.getMappingForDDL(ddl);
132
133 std::cout << decoder.getRCUTrailer() << std::endl;
134 for (auto& chan : decoder.getChannels()) {
135 if (ddlmapping.getChannelType(chan.getHardwareAddress) != o2::emcal::ChannelType_t::TRU) {
136 continue;
137 }
138 std::cout << "Hw address: " << chan.getHardwareAddress() << std::endl;
139 // Get absolute FastOR index - this will tell us where on the EMCAL surface the FastOR is
140 // TRU index is encoded in column, needs to be converted to an absoluted FastOR ID via the
141 // trigger mapping. The absoluted FastOR ID can be connected via the geometry to tower IDs
142 // from the FEC data.
143 // we are only interested in the FastORs for now, skip patches starting from 96
144 auto fastorInTRU = ddlmapping.getColumn(chan.getHardwareAddress());
145 if (fastorInTRU >= 96) {
146 // indices starting from 96 encode patches, not FastORs
147 continue;
148 }
149 auto truindex = triggermapping.getTRUIndexFromOnlineHardareAddree(chan.getHardwareAddress(), ddl, ddl / 2);
150 auto absFastOrID = triggermapping.getAbsFastORIndexFromIndexInTRU(truindex, fastorInTRU);
151
152 for (auto& bunch : chan.getBunches()) {
153 std::cout << "BunchLength: " << int(bunch.getBunchLength()) << std::endl;
154 auto adcs = bunch.getADC();
155 int time = bunch.getStartTime();
156 starttime = time;
157 timesamples.clear();
158 timesamples.resize(adcs.size());
159 std::copy(adcs.begin(), adcs.end(), timesamples.begin());
160 trudata.Fill();
161 for (int i = adcs.size() - 1; i >= 0; i--) {
162 std::cout << "Timebin " << time << ", ADC " << adcs[i] << std::endl;
163 time--;
164 }
165 }
166 }
167 }
168 }
169 reader.setNextTFToRead(++tfID);
170 }
171}
uint64_t orbit
Definition RawEventData.h:6
uint64_t bc
Definition RawEventData.h:5
int16_t time
Definition RawEventData.h:4
int32_t i
Reader for (multiple) raw data files.
Decoder of the ALTRO data in the raw page.
void decode()
Decode the ALTRO stream.
const RCUTrailer & getRCUTrailer() const
Get reference to the RCU trailer object.
const std::vector< Channel > & getChannels() const
Get the reference to the channel container.
Handler providing the correct mapping for the given DDL.
Definition Mapper.h:313
Mapper & getMappingForDDL(unsigned int ddl)
Get Mapping for given DDL.
Definition Mapper.cxx:112
Reader for raw data produced by the Readout application in in-memory format.
bool hasNext() const
check if more pages are available in the raw file
const o2::header::RDHAny & getRawHeader() const
access to the raw header of the current page
void next()
Read next payload from the stream.
Trigger mapping starting from Run2.
IndexFastOR getAbsFastORIndexFromIndexInTRU(IndexTRU truIndex, IndexFastOR fastorIndexTRU) const
Get the absolute index of the FastOr from the index in the TRU.
IndexTRU getTRUIndexFromOnlineHardareAddree(int hardwareAddress, unsigned int ddlID, unsigned int supermoduleID) const
Get the TRU Index from the hardware address of the ALTRO channel (TRU rawdata)
void setDefaultDataOrigin(const std::string &orig)
constexpr o2::header::DataDescription gDataDescriptionRawData
Definition DataHeader.h:597
constexpr o2::header::DataOrigin gDataOriginEMC
Definition DataHeader.h:565
@ TRU
TRU channel.
Definition Constants.h:36
#define main
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))