-
Notifications
You must be signed in to change notification settings - Fork 3
/
SiStripConditions.cc
71 lines (62 loc) · 2.1 KB
/
SiStripConditions.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
#include <fstream>
#include <iostream>
#include <algorithm>
#include <cassert>
#ifdef USE_GPU
#include <cuda_runtime.h>
#include "cuda_rt_call.h"
#endif
#include "SiStripConditions.h"
struct FileChannel {
fedId_t fedId_;
detId_t detId_;
fedCh_t fedCh_;
APVPair_t ipair_;
float noise_[ChannelConditions::kStripsPerChannel];
float gain_[ChannelConditions::kStripsPerChannel];
bool bad_[ChannelConditions::kStripsPerChannel];
};
SiStripConditions::SiStripConditions(const std::string& file)
{
std::ifstream datafile(file, std::ios::in | std::ios::binary);
FileChannel fc;
while (datafile.read((char*) &fc, sizeof(fc)).gcount() == sizeof(fc)) {
auto fedi = fc.fedId_ - kFedFirst;
auto fch = fc.fedCh_;
detID_[fedi][fch] = fc.detId_;
iPair_[fedi][fch] = fc.ipair_;
detToFeds_.emplace_back(fc.detId_, fc.ipair_, fc.fedId_, fc.fedCh_);
auto choff = fch*kStripsPerChannel;
for (auto i = 0; i < ChannelConditions::kStripsPerChannel; ++i, ++choff) {
noise_[fedi][choff] = fc.noise_[i];
gain_[fedi][choff] = fc.gain_[i];
bad_[fedi][choff] = fc.bad_[i];
}
}
std::sort(detToFeds_.begin(), detToFeds_.end(),
[](const DetToFed& a, const DetToFed& b){
return a.detID() < b.detID() || (a.detID() == b.detID() && a.pair() < b.pair());
});
#ifdef DBGPRINT
for (const auto& d : detToFeds_) {
std::cout << d.detID() << ":" << d.pair() << " --> " << d.fedID() << ":" << (uint16_t) d.fedCh() << std::endl;
}
#endif
}
const ChannelConditions SiStripConditionsBase::operator()(fedId_t fed, fedCh_t channel) const
{
fed -= kFedFirst;
const auto detID = detID_[fed][channel];
const auto pair = iPair_[fed][channel];
const auto choff = channel*kStripsPerChannel;
return ChannelConditions(detID, pair, &noise_[fed][choff], &gain_[fed][choff], &bad_[fed][choff]);
}
SiStripConditionsGPU* SiStripConditionsBase::toGPU() const
{
SiStripConditionsGPU* s = nullptr;
#ifdef USE_GPU
CUDA_RT_CALL(cudaMalloc((void**) &s, sizeof(SiStripConditionsGPU)));
CUDA_RT_CALL(cudaMemcpyAsync(s, this, sizeof(SiStripConditionsGPU), cudaMemcpyDefault));
#endif
return s;
}