18TFile *
Utils::OpenFile(std::string filename, std::string mode,
bool createLocalDir)
24 filename = gSystem->ExpandPathName(filename.c_str());
27 if (!mode.compare(
"RECREATE") || !mode.compare(
"UPDATE") || !mode.compare(
"WRITE")) {
29 TString filenameT(filename.c_str());
30 bool isLocalFile = filenameT.BeginsWith(
"file://");
33 filenameT.ReplaceAll(
"file://",
"");
36 isLocalFile = !filenameT.Contains(
"://");
41 std::string pwd = gSystem->pwd();
42 if (filenameT[0] !=
'/') filenameT = pwd +
"/" + filenameT;
43 filenameT.ReplaceAll(
"?remote=1&",
"?");
44 filenameT.ReplaceAll(
"?remote=1",
"");
45 filenameT.ReplaceAll(
"&remote=1",
"");
46 TUrl url(filenameT.Data());
48 std::string filenameLocal = gSystem->GetDirName(url.GetFile()).Data();
50 gSystem->mkdir(filenameLocal.c_str(), kTRUE);
54 return TFile::Open(filename.c_str(), mode.c_str());
64 TFile * f =
OpenFile(TString::Format(
"%s?filetype=raw", filename.c_str()).Data());
70 char buff[buffsize + 1];
72 Long64_t buffread = 0;
73 while (buffread < f->GetSize()) {
74 if (buffread + buffsize > f->GetSize()) buffsize = f->GetSize() - buffread;
77 f->ReadBuffer(buff, buffread, buffsize);
78 buff[buffsize] =
'\0';
149 std::string path =
"";
150 std::string rebinStr =
"";
151 for (
auto & cut : cuts) {
153 Int_t rebin_start = 1;
154 Int_t rebin_minimum = 1;
155 if (cut[
"enabled"].is_boolean() && cut[
"enabled"].get<
bool>() ==
false)
continue;
156 if (cut[
"rebin"].is_number_integer()) rebin = cut[
"rebin"].get<Int_t>();
157 if (cut[
"rebin_start"].is_number_integer()) rebin_start = cut[
"rebin_start"].get<Int_t>();
159 if (rebin_start > 1) {
160 rebin_minimum = (rebin_start % rebin);
161 if (rebin_minimum == 0) rebin_minimum = 1;
163 path += cut[
"axis"].get<std::string>() +
"_";
165 rebinStr += std::to_string(rebin) +
"-" + std::to_string(rebin_minimum) +
"_";
167 path[path.size() - 1] =
'/';
168 rebinStr[rebinStr.size() - 1] =
'/';
198 bool normalizeToWidth,
bool onlyPositive,
double times)
205 if (!cfg[
"user"][
"verbose"].is_null() && cfg[
"user"][
"verbose"].is_number_integer()) {
206 verbose = cfg[
"user"][
"verbose"].get<
int>();
209 bool isValNan = TMath::IsNaN(val);
210 bool isErrNaN = TMath::IsNaN(err);
212 if (isValNan || isErrNaN) {
214 Printf(
"Error: SetResultValueError %s val=%f[isNaN=%d] err=%f[isNan=%d]", name.c_str(), val, isValNan, err,
219 if (onlyPositive && val < 0) {
223 if (times > 0 && times * std::abs(val) < err) {
225 Printf(
"Warning: Skipping '%s' because 'times * val < err' ( %f * %f < %f ) ...", name.c_str(), times,
230 if (normalizeToWidth) {
232 for (
auto & cut : cfg[
"ndmspc"][
"cuts"]) {
233 if (cut[
"enabled"].is_boolean() && cut[
"enabled"].get<
bool>() ==
false)
continue;
237 for (
int iCut = 0; iCut < nDimsCuts; iCut++) {
238 double w = output->GetAxis(iCut + 1)->GetBinWidth(point[iCut + 1]);
245 int idx = output->GetAxis(0)->FindBin(name.c_str());
250 Long64_t binId = output->GetBin(point);
251 output->SetBinContent(binId, val);
252 output->SetBinError(binId, err);
262 std::vector<std::string> out;
264 for (
auto found = input.find(delim); found != std::string_view::npos; found = input.find(delim)) {
265 out.emplace_back(input, 0, found);
266 input.remove_prefix(found + 1);
269 if (not input.empty()) out.emplace_back(input);
static int SetResultValueError(json cfg, THnSparse *output, std::string name, Int_t *point, double val, double err, bool normalizeToWidth=false, bool onlyPositive=false, double times=1)