Commit 068197c5 authored by Sarah Seif El Nasr's avatar Sarah Seif El Nasr
Browse files

Added python utilities for creating calibration skeleton

parent e94a0b08
......@@ -20,7 +20,7 @@
#include <time.h>
#include <uhal/uhal.hpp>
#include <algorithm>
uint8_t cLpGBTI2CHack = false;
uint8_t cLpGBTI2CHack = true;
// #pragma GCC diagnostic ignored "-Wpedantic"
using namespace Ph2_HwDescription;
......
/*!
*
* \file CLASS_NAME_TEMPLATE.h
* \brief CLASS_NAME_TEMPLATE class
* \author CLASS_AUTOR
* \date TODAY_DATE
*
*/
#ifndef CLASS_NAME_TEMPLATE_h__
#define CLASS_NAME_TEMPLATE_h__
#include "Tool.h"
#include <map>
#ifdef __USE_ROOT__
// Calibration is not running on the SoC: I need to instantiate the DQM histrgrammer here
#include "../DQMUtils/DQMHistogramCLASS_NAME_TEMPLATE.h"
#endif
class CLASS_NAME_TEMPLATE : public Tool
{
public:
CLASS_NAME_TEMPLATE();
~CLASS_NAME_TEMPLATE();
void Initialise(void);
// State machine
void Running() override;
void Stop() override;
void ConfigureCalibration() override;
void Pause() override;
void Resume() override;
void Reset();
private:
//
#ifdef __USE_ROOT__
// Calibration is not running on the SoC: Histogrammer is handeld by the calibration itself
DQMHistogramCLASS_NAME_TEMPLATE fDQMHistogramCLASS_NAME_TEMPLATE;
#endif
};
#endif
#include "../tools/CLASS_NAME_TEMPLATE.h"
using namespace Ph2_HwDescription;
using namespace Ph2_HwInterface;
using namespace Ph2_System;
CLASS_NAME_TEMPLATE::CLASS_NAME_TEMPLATE() : Tool() {}
CLASS_NAME_TEMPLATE::~CLASS_NAME_TEMPLATE() {}
void CLASS_NAME_TEMPLATE::Initialise(void)
{
#ifdef __USE_ROOT__ // to disable and anable ROOT by command
// Calibration is not running on the SoC: plots are booked during initialization
fDQMHistogramCLASS_NAME_TEMPLATE.book(fResultFile, *fDetectorContainer, fSettingsMap);
#endif
}
void CLASS_NAME_TEMPLATE::ConfigureCalibration()
{
}
void CLASS_NAME_TEMPLATE::Running()
{
LOG(INFO) << "Starting CLASS_NAME_TEMPLATE measurement.";
Initialise();
LOG(INFO) << "Done with CLASS_NAME_TEMPLATE.";
}
void CLASS_NAME_TEMPLATE::Stop(void)
{
LOG(INFO) << "Stopping CLASS_NAME_TEMPLATE measurement.";
#ifdef __USE_ROOT__
// Calibration is not running on the SoC: processing the histograms
fDQMHistogramCLASS_NAME_TEMPLATE.process();
#endif
dumpConfigFiles();
SaveResults();
closeFileHandler();
LOG(INFO) << "CLASS_NAME_TEMPLATE stopped.";
}
void CLASS_NAME_TEMPLATE::Pause()
{
}
void CLASS_NAME_TEMPLATE::Resume()
{
}
/*!
\file DQMHistogramCLASS_NAME_TEMPLATE.h
\brief DQM class for CLASS_NAME_TEMPLATE
\author CLASS_AUTOR
\date TODAY_DATE
*/
#ifndef DQMHistogramCLASS_NAME_TEMPLATE_h_
#define DQMHistogramCLASS_NAME_TEMPLATE_h_
#include "../DQMUtils/DQMHistogramBase.h"
#include "../Utils/Container.h"
#include "../Utils/DataContainer.h"
class TFile;
/*!
* \class DQMHistogramCLASS_NAME_TEMPLATE
* \brief Class for CLASS_NAME_TEMPLATE monitoring histograms
*/
class DQMHistogramCLASS_NAME_TEMPLATE : public DQMHistogramBase
{
public:
/*!
* constructor
*/
DQMHistogramCLASS_NAME_TEMPLATE();
/*!
* destructor
*/
~DQMHistogramCLASS_NAME_TEMPLATE();
/*!
* \brief Book histograms
* \param theOutputFile : where histograms will be saved
* \param theDetectorStructure : Detector container as obtained after file parsing, used to create histograms for
* all board/chip/hybrid/channel \param pSettingsMap : setting as for Tool setting map in case coe informations are
* needed (i.e. FitSCurve)
*/
void book(TFile* theOutputFile, DetectorContainer& theDetectorStructure, const Ph2_System::SettingsMap& pSettingsMap) override;
/*!
* \brief fill : fill histograms from TCP stream, need to be overwritten to avoid compilation errors, but it is not
* needed if you do not fo into the SoC \param dataBuffer : vector of char with the TCP datastream
*/
bool fill(std::vector<char>& dataBuffer) override;
/*!
* \brief process : do something with the histogram like colors, fit, drawing canvases, etc
*/
void process() override;
/*!
* \brief Reset histogram
*/
void reset(void) override;
private:
DetectorDataContainer fDetectorData;
};
#endif
#include "../DQMUtils/DQMHistogramCLASS_NAME_TEMPLATE.h"
#include "../RootUtils/RootContainerFactory.h"
#include "../Utils/Container.h"
#include "../Utils/ContainerFactory.h"
#include "../Utils/ContainerStream.h"
#include "TFile.h"
//========================================================================================================================
DQMHistogramCLASS_NAME_TEMPLATE::DQMHistogramCLASS_NAME_TEMPLATE() {}
//========================================================================================================================
DQMHistogramCLASS_NAME_TEMPLATE::~DQMHistogramCLASS_NAME_TEMPLATE() {}
//========================================================================================================================
void DQMHistogramCLASS_NAME_TEMPLATE::book(TFile* theOutputFile, DetectorContainer& theDetectorStructure, const Ph2_System::SettingsMap& pSettingsMap)
{
// SoC utilities only - BEGIN
// THIS PART IT IS JUST TO SHOW HOW DATA ARE DECODED FROM THE TCP STREAM WHEN WE WILL GO ON THE SOC
// IF YOU DO NOT WANT TO GO INTO THE SOC WITH YOUR CALIBRATION YOU DO NOT NEED THE FOLLOWING COMMENTED LINES
// make fDetectorData ready to receive the information fromm the stream
ContainerFactory::copyStructure(theDetectorStructure, fDetectorData);
// SoC utilities only - END
}
//========================================================================================================================
void DQMHistogramCLASS_NAME_TEMPLATE::process()
{
// This step it is not necessary, unless you want to format / draw histograms,
// otherwise they will be automatically saved
}
//========================================================================================================================
void DQMHistogramCLASS_NAME_TEMPLATE::reset(void)
{
// Clear histograms if needed
}
//========================================================================================================================
bool DQMHistogramCLASS_NAME_TEMPLATE::fill(std::vector<char>& dataBuffer)
{
// SoC utilities only - BEGIN
// THIS PART IT IS JUST TO SHOW HOW DATA ARE DECODED FROM THE TCP STREAM WHEN WE WILL GO ON THE SOC
// IF YOU DO NOT WANT TO GO INTO THE SOC WITH YOUR CALIBRATION YOU DO NOT NEED THE FOLLOWING COMMENTED LINES
// As example, I'm expecting to receive a data stream from an uint32_t contained from calibration "CLASS_NAME_TEMPLATE"
// ChannelContainerStream<uint32_t> theHitStreamer("CLASS_NAME_TEMPLATE");
// Try to see if the char buffer matched what I'm expection (container of uint32_t from CLASS_NAME_TEMPLATE
// procedure)
// if(theHitStreamer.attachBuffer(&dataBuffer))
// {
// // It matched! Decoding chip data
// theHitStreamer.decodeChipData(fDetectorData);
// // Filling the histograms
// fillCLASS_NAME_TEMPLATEPlots(fDetectorData);
// // Cleaning the data container to be ready for the next TCP string
// fDetectorData.cleanDataStored();
// return true;
// }
// the stream does not match, the expected (DQM interface will try to check if other DQM istogrammers are looking
// for this stream)
return false;
// SoC utilities only - END
}
import os
import sys
import datetime
def checkIfFileExists(fileName):
if os.path.exists(fileName):
print "File ", fileName, " already exists\naborting..."
sys.exit(1)
def createFileFromTemplate(templateFile, outputFile):
with open(templateFile, 'r') as file : filedata = file.read()
# Replace the target string
filedata = filedata.replace('CLASS_NAME_TEMPLATE', className)
filedata = filedata.replace('CLASS_AUTOR' , autor )
filedata = filedata.replace('TODAY_DATE' , todayDate)
# Write the file out again
with open(outputFile, 'w') as file: file.write(filedata)
print "Created file ", outputFile
if not 'PH2ACF_BASE_DIR' in os.environ:
print "Please source the setup.sh to set the enviromental variables\naborting..."
sys.exit(1)
ph2acfDirectory = os.environ['PH2ACF_BASE_DIR']
className = raw_input("Please enter the calibration name: ")
className = className.decode('utf-8')
if not className.isalnum():
print "C++ class names can contain only letters or numbers\naborting..."
sys.exit(1)
if ' ' in className:
print "C++ class names cannot contain spaces\naborting..."
sys.exit(1)
if className[0].isnumeric():
print "C++ class names cannot start with a number\naborting..."
sys.exit(1)
if not className[0].isupper():
print "Adopted convention required the class name to start with upper case\naborting..."
sys.exit(1)
templateFile = ph2acfDirectory + "/pythonUtils/CalibrationTemplates/{0}"
calibrationFile = ph2acfDirectory + "/tools/{0}"
dqmFile = ph2acfDirectory + "/DQMUtils/DQMHistogram{0}"
checkIfFileExists(calibrationFile.format(className + ".h" ))
checkIfFileExists(calibrationFile.format(className + ".cc"))
checkIfFileExists(dqmFile .format(className + ".h" ))
checkIfFileExists(dqmFile .format(className + ".cc"))
autor = raw_input("Please enter the autor name: ")
todayDate = datetime.datetime.now().strftime('%d/%m/%y')
createFileFromTemplate(templateFile.format("templateCalibrationHeader.txt" ), calibrationFile.format(className + ".h" ))
createFileFromTemplate(templateFile.format("templateCalibrationImplementation.txt"), calibrationFile.format(className + ".cc"))
createFileFromTemplate(templateFile.format("templateDQMHeader.txt" ), dqmFile .format(className + ".h" ))
createFileFromTemplate(templateFile.format("templateDQMImplementation.txt" ), dqmFile .format(className + ".cc"))
\ No newline at end of file
......@@ -19,8 +19,6 @@
#include "../DQMUtils/DQMHistogramCalibrationExample.h"
#endif
using namespace Ph2_System;
class CalibrationExample : public Tool
{
public:
......
Supports Markdown
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