Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 4, 2023
1 parent 93a645a commit 9c8ce94
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 95 deletions.
10 changes: 5 additions & 5 deletions inc/TRestDetectorReadoutModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class TRestDetectorReadoutModule {
Bool_t showWarnings; //!///< Flag to enable/disable warning outputs. Disabled by
//! default. REST_Warning in TRestDetectorReadout will enable it.

Int_t fFirstDaqChannel = 0; ///< First DAQ channel
Int_t fFirstDaqChannel = 0; ///< First DAQ channel

std::string fDecodingFile = ""; ///< Decoding file
std::string fDecodingFile = ""; ///< Decoding file

Int_t fMappingNodes = 0; ///< Number of nodes
Int_t fMappingNodes = 0; ///< Number of nodes

Bool_t fDecoding; ///< Defines if a decoding file was used to set the relation
///< between a physical readout channel id and a signal daq id
Expand Down Expand Up @@ -121,7 +121,7 @@ class TRestDetectorReadoutModule {
inline void SetMappingNodes(Int_t nodes) { fMappingNodes = nodes; }

/// Sets decoding file
inline void SetDecodingFile(const std::string &decodingFile) { fDecodingFile = decodingFile; }
inline void SetDecodingFile(const std::string& decodingFile) { fDecodingFile = decodingFile; }

/// Gets the tolerance for independent pixel overlaps
inline Double_t GetTolerance() const { return fTolerance; }
Expand Down Expand Up @@ -189,7 +189,7 @@ class TRestDetectorReadoutModule {
/// Disables warning output
inline void DisableWarnings() { showWarnings = false; }

void DoReadoutMapping( );
void DoReadoutMapping();

void UpdateDecoding();

Expand Down
32 changes: 15 additions & 17 deletions macros/REST_Detector_UpdateDecoding.C
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
void REST_Detector_UpdateDecoding (const std::string& rootFile, const std::string &readoutName, const std::string & decodingFile ) {
void REST_Detector_UpdateDecoding(const std::string& rootFile, const std::string& readoutName,
const std::string& decodingFile) {
TFile* f = TFile::Open(rootFile.c_str(), "UPDATE");
TRestDetectorReadout* readout = (TRestDetectorReadout*)f->Get(readoutName.c_str());

TFile *f = TFile::Open(rootFile.c_str(), "UPDATE");
TRestDetectorReadout* readout = (TRestDetectorReadout*)f->Get(readoutName.c_str());
// readout->PrintMetadata();

//readout->PrintMetadata();
for (int p = 0; p < readout->GetNumberOfReadoutPlanes(); p++) {
TRestDetectorReadoutPlane* plane = readout->GetReadoutPlane(p);
for (int m = 0; m < plane->GetNumberOfModules(); m++) {
TRestDetectorReadoutModule* module = &(*plane)[m];
module->SetDecodingFile(decodingFile);
module->UpdateDecoding();
}
}

for( int p = 0; p < readout->GetNumberOfReadoutPlanes(); p++ ){
TRestDetectorReadoutPlane *plane = readout->GetReadoutPlane( p );
for( int m = 0; m < plane->GetNumberOfModules(); m++ ) {
TRestDetectorReadoutModule* module = &(*plane)[m];
module->SetDecodingFile(decodingFile);
module->UpdateDecoding();
}
}

readout->Write(readoutName.c_str());

f->Close();
readout->Write(readoutName.c_str());

f->Close();
}

23 changes: 10 additions & 13 deletions src/TRestDetectorReadout.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,10 @@ void TRestDetectorReadout::InitFromConfigFile() {

Int_t firstDaqChannel = StringToInteger(GetFieldValue("firstDaqChannel", moduleDefinition));

if(firstDaqChannel == -1) {
fModuleDefinitions[mid].SetFirstDaqChannel(addedChannels);
if (firstDaqChannel == -1) {
fModuleDefinitions[mid].SetFirstDaqChannel(addedChannels);
} else {
fModuleDefinitions[mid].SetFirstDaqChannel(firstDaqChannel);
fModuleDefinitions[mid].SetFirstDaqChannel(firstDaqChannel);
}

std::string decodingFile = GetFieldValue("decodingFile", moduleDefinition);
Expand All @@ -528,31 +528,28 @@ void TRestDetectorReadout::InitFromConfigFile() {
// missing numbers in a multi-module readout plane. Modules can have their
// special "id", e.g. M0, M2, M3, M4 in SJTU proto. We don't have M1

for (auto & mod : moduleVector) {
for (auto& mod : moduleVector) {
plane.AddModule(mod);
}

this->AddReadoutPlane(std::move(plane));
planeDefinition = GetNextElement(planeDefinition);

}

}

///////////////////////////////////////////////
/// \brief This function is used to generate the
/// readout after opening the rml file
///
void TRestDetectorReadout::GenerateReadout() {

for(auto && plane : fReadoutPlanes){
for(size_t m = 0; m < plane.GetNumberOfModules(); m++){
plane[m].DoReadoutMapping();
plane[m].UpdateDecoding();
for (auto&& plane : fReadoutPlanes) {
for (size_t m = 0; m < plane.GetNumberOfModules(); m++) {
plane[m].DoReadoutMapping();
plane[m].UpdateDecoding();
}
}
}

ValidateReadout();
ValidateReadout();
}

TRestDetectorReadoutModule* TRestDetectorReadout::ParseModuleDefinition(TiXmlElement* moduleDefinition) {
Expand Down
119 changes: 59 additions & 60 deletions src/TRestDetectorReadoutModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void TRestDetectorReadoutModule::SetMinMaxDaqIDs() {
/// is computationally expensive but it greatly optimizes the FindChannel
/// process later on.
///
void TRestDetectorReadoutModule::DoReadoutMapping( ) {
void TRestDetectorReadoutModule::DoReadoutMapping() {
///////////////////////////////////////////////////////////////////////////////
// We initialize the mapping readout net to sqrt(numberOfPixels)
// However this might not be good for readouts where the pixels are
Expand Down Expand Up @@ -177,7 +177,8 @@ void TRestDetectorReadoutModule::DoReadoutMapping( ) {
}

for (int i = 0; i < fMappingNodes; i++) {
printf("Completed : %.2lf %%\r", 100. * (i * (Double_t)fMappingNodes) / fMappingNodes / fMappingNodes);
printf("Completed : %.2lf %%\r",
100. * (i * (Double_t)fMappingNodes) / fMappingNodes / fMappingNodes);
fflush(stdout);
for (int j = 0; j < fMappingNodes; j++) {
Double_t x = fMapping.GetX(i);
Expand Down Expand Up @@ -229,75 +230,73 @@ void TRestDetectorReadoutModule::DoReadoutMapping( ) {
///////////////////////////////////////////////
/// \brief Determines if a given *daqID* number is in the range of the module
///
void TRestDetectorReadoutModule::UpdateDecoding(){
void TRestDetectorReadoutModule::UpdateDecoding() {
if (fDecodingFile == "Not defined" || fDecodingFile.empty() || RESTREADOUT_DECODINGFILE_ERROR) {
fDecoding = false;
} else {
fDecoding = true;
}

if (fDecodingFile == "Not defined" || fDecodingFile.empty() || RESTREADOUT_DECODINGFILE_ERROR) {
fDecoding = false;
} else {
fDecoding = true;
}

if (fDecoding && !TRestTools::fileExists(fDecodingFile)) {
RESTWarning << "The decoding file does not exist!" << RESTendl;
RESTWarning << "--------------------------------" << RESTendl;
RESTWarning << "File : " << fDecodingFile << RESTendl;
RESTWarning << "Default decoding will be used. readoutChannel=daqChannel" << RESTendl;
RESTWarning << "To avoid this message and use the default decoding define : "
"decodingFile=\"\""<< RESTendl;
RESTWarning << "--------------------------------" << RESTendl;
RESTWarning << "Press a KEY to continue..." << RESTendl;
GetChar();
fDecoding = false;
RESTREADOUT_DECODINGFILE_ERROR = true;
}
if (fDecoding && !TRestTools::fileExists(fDecodingFile)) {
RESTWarning << "The decoding file does not exist!" << RESTendl;
RESTWarning << "--------------------------------" << RESTendl;
RESTWarning << "File : " << fDecodingFile << RESTendl;
RESTWarning << "Default decoding will be used. readoutChannel=daqChannel" << RESTendl;
RESTWarning << "To avoid this message and use the default decoding define : "
"decodingFile=\"\""
<< RESTendl;
RESTWarning << "--------------------------------" << RESTendl;
RESTWarning << "Press a KEY to continue..." << RESTendl;
GetChar();
fDecoding = false;
RESTREADOUT_DECODINGFILE_ERROR = true;
}

std::vector<std::pair<Int_t ,Int_t>> rdChannel;
std::vector<std::pair<Int_t, Int_t>> rdChannel;
if (fDecoding && TRestTools::fileExists(fDecodingFile)) {
FILE* f = fopen(fDecodingFile.c_str(), "r");
Int_t daq, readout;
FILE* f = fopen(fDecodingFile.c_str(), "r");
Int_t daq, readout;
while (!feof(f)) {
if (fscanf(f, "%d\t%d\n", &daq, &readout) <= 0) {
RESTError << "TRestDetectorReadoutModule::UpdateDecoding. Problem reading decoding"
<< RESTendl;
RESTError << "This error might need support at REST forum" << RESTendl;
exit(-1);
}
// we skip blank daq channels if readout id is <0
// e.g. daq id: 22, readout id: -1
if (readout >= 0) {
rdChannel.push_back(std::make_pair(readout, daq + fFirstDaqChannel) );
}
if (fscanf(f, "%d\t%d\n", &daq, &readout) <= 0) {
RESTError << "TRestDetectorReadoutModule::UpdateDecoding. Problem reading decoding"
<< RESTendl;
RESTError << "This error might need support at REST forum" << RESTendl;
exit(-1);
}
// we skip blank daq channels if readout id is <0
// e.g. daq id: 22, readout id: -1
if (readout >= 0) {
rdChannel.push_back(std::make_pair(readout, daq + fFirstDaqChannel));
}
}
fclose(f);
fclose(f);
}

if (fDecoding && (unsigned int)this->GetNumberOfChannels() != rdChannel.size()) {
RESTError << "TRestDetectorReadout."
<< " The number of channels defined in the readout is not the same"
<< " as the number of channels found in the decoding." << RESTendl;
exit(1);
}
if (fDecoding && (unsigned int)this->GetNumberOfChannels() != rdChannel.size()) {
RESTError << "TRestDetectorReadout."
<< " The number of channels defined in the readout is not the same"
<< " as the number of channels found in the decoding." << RESTendl;
exit(1);
}

for (size_t ch = 0; ch < this->GetNumberOfChannels(); ch++) {
for (size_t ch = 0; ch < this->GetNumberOfChannels(); ch++) {
if (!fDecoding) {
Int_t id = ch;
rdChannel.push_back(std::make_pair( id, id + fFirstDaqChannel) );
Int_t id = ch;
rdChannel.push_back(std::make_pair(id, id + fFirstDaqChannel));
}

// WRONG version before -->
// fModuleDefinitions[mid].GetChannel(ch)->SetID( rChannel[ch] );
const auto &[readout, daq] = rdChannel[ch];
if (!this->GetChannel(readout)) {
RESTError << "Problem setting readout channel " << readout
<< " with daq id: " << daq << RESTendl;
continue;
}
this->GetChannel(readout)->SetDaqID(daq);
this->GetChannel(readout)->SetChannelID(readout);
}

this->SetMinMaxDaqIDs();
const auto& [readout, daq] = rdChannel[ch];
if (!this->GetChannel(readout)) {
RESTError << "Problem setting readout channel " << readout << " with daq id: " << daq << RESTendl;
continue;
}
this->GetChannel(readout)->SetDaqID(daq);
this->GetChannel(readout)->SetChannelID(readout);
}

this->SetMinMaxDaqIDs();
}

///////////////////////////////////////////////
Expand Down Expand Up @@ -620,11 +619,11 @@ void TRestDetectorReadoutModule::Print(Int_t DetailLevel) {
RESTMetadata << "----------------------------------------------------------------" << RESTendl;
RESTMetadata << "-- Decoding File: " << fDecodingFile << RESTendl;
RESTMetadata << "Decoding was defined : ";
if (fDecoding) {
if (fDecoding) {
RESTMetadata << "YES" << RESTendl;
} else{
} else {
RESTMetadata << "NO" << RESTendl;
}
}
RESTMetadata << "-- First DAQ Channel: " << fFirstDaqChannel << RESTendl;
RESTMetadata << "-- Number of mapping nodes: " << fMappingNodes << RESTendl;
RESTMetadata << "-- Origin position : X = " << fOrigin.X() << " mm "
Expand Down

0 comments on commit 9c8ce94

Please sign in to comment.