Commit 2ac28a60 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Update Dummy module and rework addModule script

parent 0d74801b
......@@ -5,6 +5,17 @@ echo -e "\nPreparing code basis for a new module:\n"
# Ask for module name:
read -p "Name of the module? " MODNAME
# Ask for module type:
echo -e "Type of the module?\n"
type=0
select yn in "global" "detector" "dut"; do
case $yn in
global ) type=1; break;;
detector ) type=2; break;;
dut ) type=3; break;;
esac
done
echo "Creating directory and files..."
echo
......@@ -53,6 +64,32 @@ opt=-i
platform=`uname`
if [ "$platform" == "Darwin" ]; then opt="-i \"\""; fi
# Change to detector or dut module type if necessary:
if [ "$type" != 1 ]; then
# Prepare sed commands to change to per detector module
# Change module type in CMakeLists
if [ "$type" == 3 ]; then
command="sed $opt 's/_GLOBAL_/_DUT_/g' $MODDIR/$MODNAME/CMakeLists.txt"
else
command="sed $opt 's/_GLOBAL_/_DETECTOR_/g' $MODDIR/$MODNAME/CMakeLists.txt"
fi
eval $command
# Change header file
command="sed ${opt} \
-e 's/param detectors.*/param detector Pointer to the detector for this module instance/g' \
-e 's/std::vector<Detector\*> detectors/Detector\* detector/g' \
$MODDIR/$MODNAME/${MODNAME}.h"
eval $command
# Change implementation file
command="sed ${opt} \
-e 's/std::vector<Detector\*> detectors/Detector\* detector/g' \
-e 's/move(detectors)/move\(detector\)/g' \
$MODDIR/$MODNAME/${MODNAME}.cpp"
eval $command
fi
# Print a summary of the module created:
FINALPATH=`realpath $MODDIR/$MODNAME`
echo "Name: $MODNAME"
......
/**
* @file
* @brief Implementation of [Dummy] module
* @copyright Copyright (c) 2017 CERN and the Allpix Squared authors.
* This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
* In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*/
#include "Dummy.h"
using namespace corryvreckan;
using namespace std;
Dummy::Dummy(Configuration config, std::vector<Detector*> detectors) : Module(std::move(config), std::move(detectors)) {}
void Dummy::initialise() {
// Initialise histograms per device
for(auto& detector : get_detectors()) {
// Simple histogram per device
string name = "plotForDevice_" + detector->name();
plotPerDevice[detector->name()] = new TH2F(name.c_str(), name.c_str(), 256, 0, 256, 256, 0, 256);
LOG(DEBUG) << "Initialise for detector " + detector->name();
}
// Initialise single histograms
string name = "singlePlot";
singlePlot = new TH1F(name.c_str(), name.c_str(), 1000, 0, 1000);
// Initialise member variables
m_eventNumber = 0;
}
StatusCode Dummy::run(Clipboard* clipboard) {
StatusCode Dummy::run(Clipboard*) {
// Loop over all Timepix3 and make plots
// Loop over all detectors
for(auto& detector : get_detectors()) {
// Get the pixels
Pixels* pixels = reinterpret_cast<Pixels*>(clipboard->get(detector->name(), "pixels"));
if(pixels == nullptr) {
LOG(DEBUG) << "Detector " << detector->name() << " does not have any pixels on the clipboard";
continue;
}
// Get the clusters
Clusters* clusters = reinterpret_cast<Clusters*>(clipboard->get(detector->name(), "clusters"));
if(clusters == nullptr) {
LOG(DEBUG) << "Detector " << detector->name() << " does not have any clusters on the clipboard";
continue;
}
// Loop over all pixels and make hitmaps
for(auto& pixel : (*pixels)) {
// Fill the plots for this device
plotPerDevice[detector->name()]->Fill(pixel->column(), pixel->row());
}
// Get the detector name
std::string detectorName = detector->name();
LOG(DEBUG) << "Detector with name " << detectorName;
}
// Fill single histogram
singlePlot->Fill(m_eventNumber);
// Increment event counter
m_eventNumber++;
......
#ifndef Dummy_H
#define Dummy_H 1
/**
* @file
* @brief Definition of [Dummy] module
* @copyright Copyright (c) 2017 CERN and the Allpix Squared authors.
* This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
* In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*
* Contains minimal dummy module to use as a start for the development of your own module
*
* Refer to the User's Manual for more details.
*/
#include <iostream>
#include "TCanvas.h"
......@@ -12,27 +22,37 @@
namespace corryvreckan {
/** @ingroup Modules
* @brief Module to do function
*
* More detailed explanation of module
*/
class Dummy : public Module {
public:
// Constructors and destructors
/**
* @brief Constructor for this unique module
* @param config Configuration object for this module as retrieved from the steering file
* @param detectors Vector of pointers to the detectors
*/
Dummy(Configuration config, std::vector<Detector*> detectors);
~Dummy() {}
// Functions
/**
* @brief [Initialise this module]
*/
void initialise();
StatusCode run(Clipboard* clipboard);
void finalise();
// Histograms for several devices
std::map<std::string, TH2F*> plotPerDevice;
/**
* @brief [Run the function of this module]
*/
StatusCode run(Clipboard* clipboard);
// Single histograms
TH1F* singlePlot;
/**
* @brief [Finalise module]
*/
void finalise();
// Member variables
private:
int m_eventNumber;
};
} // namespace corryvreckan
#endif // Dummy_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment