diff --git a/inc/TRestDetectorReadoutModule.h b/inc/TRestDetectorReadoutModule.h index 08235dc6..8ce2fa7d 100644 --- a/inc/TRestDetectorReadoutModule.h +++ b/inc/TRestDetectorReadoutModule.h @@ -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 @@ -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; } @@ -189,7 +189,7 @@ class TRestDetectorReadoutModule { /// Disables warning output inline void DisableWarnings() { showWarnings = false; } - void DoReadoutMapping( ); + void DoReadoutMapping(); void UpdateDecoding(); diff --git a/macros/REST_Detector_UpdateDecoding.C b/macros/REST_Detector_UpdateDecoding.C index 916d5662..6656ea4d 100644 --- a/macros/REST_Detector_UpdateDecoding.C +++ b/macros/REST_Detector_UpdateDecoding.C @@ -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(); } - diff --git a/src/TRestDetectorReadout.cxx b/src/TRestDetectorReadout.cxx index 6426ec7b..4f73f8fe 100644 --- a/src/TRestDetectorReadout.cxx +++ b/src/TRestDetectorReadout.cxx @@ -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); @@ -528,15 +528,13 @@ 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); - } - } /////////////////////////////////////////////// @@ -544,15 +542,14 @@ void TRestDetectorReadout::InitFromConfigFile() { /// 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) { diff --git a/src/TRestDetectorReadoutModule.cxx b/src/TRestDetectorReadoutModule.cxx index ecfbb084..1341aed3 100644 --- a/src/TRestDetectorReadoutModule.cxx +++ b/src/TRestDetectorReadoutModule.cxx @@ -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 @@ -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); @@ -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> rdChannel; + std::vector> 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(); } /////////////////////////////////////////////// @@ -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 "