Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-20 09:34:02

0001 // Uses current production classes, not the old Tests/Setup demonstration class.
0002 #include "../../NewStructure/Calib.h"
0003 #include "../../NewStructure/Tile.h"
0004 #include <TClass.h>
0005 #include <TFile.h>
0006 #include <TSystem.h>
0007 #include <TTree.h>
0008 #include <cmath>
0009 #include <iostream>
0010 #include <stdexcept>
0011 #include <string>
0012 
0013 namespace {
0014 void smoke_require(bool ok, const char* message) {
0015   if (!ok) throw std::runtime_error(message);
0016 }
0017 void smoke_calibration(Calib& calibration) {
0018   // Exact, deterministic control for production GetCalcScaleLow: 120 / 4 = 30.
0019   const double value = calibration.GetCalcScaleLow(7);
0020   smoke_require(std::isfinite(value) && std::abs(value - 30.) <= 1.e-12,
0021                 "known calibration value must be 30");
0022   smoke_require(calibration.GetRunNumber() == 42, "calibration run number changed");
0023   smoke_require(calibration.GetBCCalib() && calibration.GetVop() == 44.
0024                 && calibration.GetVov() == 3., "calibration metadata changed");
0025   const auto channel = calibration.find(7);
0026   smoke_require(channel != calibration.end() && channel->second.ScaleH == 120.
0027                 && channel->second.LGHGCorr == 4. && channel->second.BadChannel == 3,
0028                 "calibration channel constants changed");
0029 }
0030 }
0031 
0032 int lfhcal_smoke_payload() {
0033   try {
0034     const char* path = gSystem->Getenv("LFHCAL_SMOKE_FILE");
0035     const char* requested_mode = gSystem->Getenv("LFHCAL_SMOKE_MODE");
0036     smoke_require(path && requested_mode, "missing smoke fixture configuration");
0037     const std::string mode(requested_mode);
0038     for (const char* name : {"Tile", "Calib", "TileCalib"}) {
0039       TClass* type = TClass::GetClass(name);
0040       smoke_require(type && type->IsLoaded(), "production ROOT dictionary is not loaded");
0041     }
0042     if (mode == "write") {
0043       Calib calibration;
0044       calibration.SetRunNumber(42);
0045       calibration.SetVop(44.);
0046       calibration.SetVov(3.);
0047       calibration.SetBCCalib(true);
0048       TileCalib* channel = calibration.GetTileCalib(7);
0049       channel->ScaleH = 120.;
0050       channel->LGHGCorr = 4.;
0051       channel->BadChannel = 3;
0052       smoke_calibration(calibration);
0053       TFile file(path, "CREATE");
0054       smoke_require(!file.IsZombie() && file.IsWritable(), "cannot create ROOT fixture");
0055       smoke_require(file.WriteObject(&calibration, "calibration") > 0,
0056                     "cannot write calibration object");
0057       {
0058         Tile tile(ReadOut::Type::Caen);
0059         tile.SetCellID(7);
0060         tile.SetE(2.5);
0061         tile.SetTOA(12.);
0062         Tile* address = &tile;
0063         TTree tree("events", "one synthetic LFHCal tile");
0064         smoke_require(tree.Branch("tile", &address) != nullptr, "cannot create Tile branch");
0065         smoke_require(tree.Fill() > 0 && tree.Write() > 0, "cannot write event tree");
0066       }
0067       file.Close();
0068       smoke_require(!file.TestBit(TFile::kWriteError), "ROOT reported a write/close error");
0069     } else if (mode == "read") {
0070       // A new ROOT process reads disk state, not an object retained by the writer.
0071       TFile file(path, "READ");
0072       smoke_require(!file.IsZombie() && !file.TestBit(TFile::kRecovered),
0073                     "fixture missing, corrupt, or recovered");
0074       Calib* calibration = nullptr;
0075       file.GetObject("calibration", calibration);
0076       smoke_require(calibration != nullptr, "missing calibration object");
0077       smoke_calibration(*calibration);
0078       TTree* tree = nullptr;
0079       file.GetObject("events", tree);
0080       smoke_require(tree && tree->GetEntries() == 1, "expected exactly one event");
0081       Tile* tile = nullptr;
0082       smoke_require(tree->SetBranchAddress("tile", &tile) >= 0, "cannot bind Tile branch");
0083       smoke_require(tree->GetEntry(0) > 0 && tile, "cannot load first event");
0084       smoke_require(tile->GetCellID() == 7 && tile->GetE() == 2.5 && tile->GetTOA() == 12.,
0085                     "Tile round-trip values changed");
0086       tree->ResetBranchAddresses();
0087       delete tile;
0088     } else {
0089       throw std::runtime_error("unknown smoke mode");
0090     }
0091     std::cout << "LFHCAL_SMOKE_OK: " << mode << '\n';
0092     return 0;
0093   } catch (const std::exception& error) {
0094     std::cerr << "FAIL: " << error.what() << '\n';
0095     return 1;
0096   }
0097 }