Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit ad4d222e authored by Jérémie Dudouet's avatar Jérémie Dudouet
Browse files

Add in BasicAFC and BasicAFP the possibility to give the parameters (conf file...

Add in BasicAFC and BasicAFP the possibility to give the parameters (conf file content) using a method rather than using configuration files
parent c4087ae0
......@@ -35,184 +35,208 @@ using namespace ADF;
std::string BasicAFC::gConfigurationFilename = "BasicAFC.conf";
BasicAFC::BasicAFC(Int_t id) :
NarvalConsumer(),
fEndOfFrames(aMByte,ConfAgent::kWrite),
fPath("./"),
fBaseForName("AFC_"),
fCurrentFile(0x0),
fCurrentFileNumber(0u),
fMaxSize(kMaxInt_t),
fMyID(id),
fVertex(0x0)
BasicAFC::BasicAFC(Int_t id) :
NarvalConsumer(),
fEndOfFrames(aMByte,ConfAgent::kWrite),
fPath("./"),
fBaseForName("AFC_"),
fCurrentFile(0x0),
fCurrentFileNumber(0u),
fMaxSize(kMaxInt_t),
fMyID(id),
fVertex(0x0),
fInitialized(false)
{
// log system
Log.GetProcessName() = "BasicAFC";
Log.SetPID(GetPID());
// frameio related
GetFrameIO().SetName("BasicAFC");
// to be sure unknown frames are written in the ouput
GetFrameIO().SetModel(ConfAgent::kSafe);
// to protect readings in the source of frames
fEndOfFrames.SetModeIO(ConfAgent::kWrite);
GetFrameIO().Attach(0x0,&fEndOfFrames);
// log system
Log.GetProcessName() = "BasicAFC";
Log.SetPID(GetPID());
// frameio related
GetFrameIO().SetName("BasicAFC");
// to be sure unknown frames are written in the ouput
GetFrameIO().SetModel(ConfAgent::kSafe);
// to protect readings in the source of frames
fEndOfFrames.SetModeIO(ConfAgent::kWrite);
GetFrameIO().Attach(0x0,&fEndOfFrames);
}
BasicAFC::~BasicAFC()
{
// in principle not needed ... just in case reset it has not been called by narval
UInt_t error = 0u; process_reset(&error) ;
if ( fVertex )
delete fVertex;
// in principle not needed ... just in case reset it has not been called by narval
UInt_t error = 0u; process_reset(&error) ;
if ( fVertex )
delete fVertex;
}
void BasicAFC::process_config (const Char_t *directory_path, UInt_t *error_code)
{
// first init narval stuff
NarvalInterface::process_config(directory_path,error_code);
if ( (*error_code) == 0u ) {
// now init your stuff if required
}
// first init narval stuff
NarvalInterface::process_config(directory_path,error_code);
if ( (*error_code) == 0u ) {
// now init your stuff if required
}
}
Bool_t BasicAFC::NewFile()
{
Log.SetProcessMethod("NewFile");
Bool_t ok = false;
// close if already open
if ( fCurrentFile ) {
::fclose(fCurrentFile);
fCurrentFile = 0x0;
std::cout << " -BasicAFP: the input file has just been closed " << fCurrentFileName << std::endl;
}
// open the file
std::string tmp = fPath;
if ( tmp.size() > 0 && !(tmp.at(tmp.size()-1) == '/') )
tmp += '/';
std::ostringstream filename;
filename << tmp << fBaseForName
<< std::setfill('0') << std::setw(4) << fCurrentFileNumber++ << std::setfill(' ')
<< ".adf";
fCurrentFileName = filename.str();
fCurrentFile = ::fopen(fCurrentFileName.c_str(),"wb");
if ( fCurrentFile != 0x0 ) {
Log << info << "A new output file has just been open "
<< fCurrentFileName << nline;
fEndOfFrames.SetFile(fCurrentFile,fMaxSize);
GetFrameIO().SetStatus(BaseFrameIO::kIdle);
size_t len = fCurrentFileName.length();
size_t lpt = fCurrentFileName.find_last_of('/');
fCurrentName = fCurrentFileName.substr(lpt+1, len-lpt-1);
// add conf frame at the beginning of the file and a vertex frame.
GetFrameIO().RecordGlobalConfiguration();
ok = true;
}
else {
Log << warning << "Cannot open file " << fCurrentFileName << nline;
GetFrameIO().SetStatus(BaseFrameIO::kFinished);
ok = false;
}
Log << dolog;
return ok;
Log.SetProcessMethod("NewFile");
Bool_t ok = false;
// close if already open
if ( fCurrentFile ) {
::fclose(fCurrentFile);
fCurrentFile = 0x0;
std::cout << " -BasicAFP: the input file has just been closed " << fCurrentFileName << std::endl;
}
// open the file
std::string tmp = fPath;
if ( tmp.size() > 0 && !(tmp.at(tmp.size()-1) == '/') )
tmp += '/';
std::ostringstream filename;
filename << tmp << fBaseForName
<< std::setfill('0') << std::setw(4) << fCurrentFileNumber++ << std::setfill(' ')
<< ".adf";
fCurrentFileName = filename.str();
fCurrentFile = ::fopen(fCurrentFileName.c_str(),"wb");
if ( fCurrentFile != 0x0 ) {
Log << info << "A new output file has just been open "
<< fCurrentFileName << nline;
fEndOfFrames.SetFile(fCurrentFile,fMaxSize);
GetFrameIO().SetStatus(BaseFrameIO::kIdle);
size_t len = fCurrentFileName.length();
size_t lpt = fCurrentFileName.find_last_of('/');
fCurrentName = fCurrentFileName.substr(lpt+1, len-lpt-1);
// add conf frame at the beginning of the file and a vertex frame.
GetFrameIO().RecordGlobalConfiguration();
ok = true;
}
else {
Log << warning << "Cannot open file " << fCurrentFileName << nline;
GetFrameIO().SetStatus(BaseFrameIO::kFinished);
ok = false;
}
Log << dolog;
return ok;
}
UInt_t BasicAFC::ProcessBlock (ADF::FrameBlock &in)
{
Log.ClearMessage(); Log.SetProcessMethod("ProcessBlock");
// attach the FrameBlocks
GetFrameIO().Attach(&in,0x0);
UInt_t nevtsIn = GetFrameIO().GetFramesWritten();
while ( 1 ) {
// fill the output block with the frames from the input block
while ( GetFrameIO().Notify() ) {
}
if ( GetFrameIO().GetCurrentBlockOUT()->IsEoB() ) { // the output file is full
NewFile();
continue;
}
// interruption: means end of file or out is full
if ( GetFrameIO().GetCurrentBlockIN()->IsEoB() ) // the input block is treated
break;
}
UInt_t nevtsOut = GetFrameIO().GetFramesWritten();
//
GetFrameIO().Detach(&in,0x0);
if(fMyID >= 0) {
std::cout << std::setw(2) << fMyID;
std::cout << std::left << std::setw(24) << "-" << gConfigurationFilename << ":" << std::right
<< " " << std::setw(5) << nevtsOut-nevtsIn
<< " evts (" << std::setw(8) << in.GetSize() << ")"
<< " Tot = " << std::setw(8) << nevtsOut
<< " " << fCurrentName << std::endl;
}
return 0u;
// attach the FrameBlocks
GetFrameIO().Attach(&in,0x0);
UInt_t nevtsIn = GetFrameIO().GetFramesWritten();
while ( 1 ) {
// fill the output block with the frames from the input block
while ( GetFrameIO().Notify() ) {
}
if ( GetFrameIO().GetCurrentBlockOUT()->IsEoB() ) { // the output file is full
NewFile();
continue;
}
// interruption: means end of file or out is full
if ( GetFrameIO().GetCurrentBlockIN()->IsEoB() ) // the input block is treated
break;
}
UInt_t nevtsOut = GetFrameIO().GetFramesWritten();
//
GetFrameIO().Detach(&in,0x0);
if(fMyID >= 0) {
std::cout << std::setw(2) << fMyID;
std::cout << std::left << std::setw(24) << "-" << gConfigurationFilename << ":" << std::right
<< " " << std::setw(5) << nevtsOut-nevtsIn
<< " evts (" << std::setw(8) << in.GetSize() << ")"
<< " Tot = " << std::setw(8) << nevtsOut
<< " " << fCurrentName << std::endl;
}
return 0u;
}
Bool_t BasicAFC::SetParameters(std::string _pathforfiles, std::string _basename, int starting_number)
{
Log.ClearMessage(); Log.SetProcessMethod("SetParameters");
if(fInitialized) {
Log << warning << "actor already initialized, SetParameters method ignored " << nline;
Log << dolog;
return false;
}
fPath = _pathforfiles;
fBaseForName = _basename;
fCurrentFileNumber = starting_number;
fInitialized = true;
Log << dolog;
return true;
}
void BasicAFC::process_initialise (UInt_t *error_code)
{
*error_code = 0;
Log.ClearMessage(); Log.SetProcessMethod("process_initialise");
// creates a trigger to register at the beginning of the file a global vertex frame
// that is initiated from ADF.conf
fVertex = AgataFrameTrigger::Build("GVertex","","meta:vertex");
if ( fVertex )
GetFrameIO().Register(fVertex);
// read an input file to get the base filename and the path
std::string conffile = GetConfPath() + gConfigurationFilename;
std::ifstream filein(conffile.data());
if ( filein.is_open() == true ) {
std::string pathforfiles, basename;
UInt_t starting_number;
filein >> pathforfiles >> basename >> starting_number;
if ( filein.good() ) {
fPath = pathforfiles;
fBaseForName = basename;
fCurrentFileNumber = starting_number;
// GetFrameIO().GetConfAgent()->GetRunAgent()->SetSubRun(starting_number);
}
filein.close();
}
// open the first file
if ( !NewFile() )
*error_code = 1;
Log << dolog;
*error_code = 0;
Log.ClearMessage(); Log.SetProcessMethod("process_initialise");
// creates a trigger to register at the beginning of the file a global vertex frame
// that is initiated from ADF.conf
fVertex = AgataFrameTrigger::Build("GVertex","","meta:vertex");
if ( fVertex )
GetFrameIO().Register(fVertex);
if(!fInitialized) {
// read an input file to get the base filename and the path
std::string conffile = GetConfPath() + gConfigurationFilename;
std::ifstream filein(conffile.data());
if ( filein.is_open() == true ) {
std::string pathforfiles, basename;
UInt_t starting_number;
filein >> pathforfiles >> basename >> starting_number;
if ( filein.good() ) {
fPath = pathforfiles;
fBaseForName = basename;
fCurrentFileNumber = starting_number;
// GetFrameIO().GetConfAgent()->GetRunAgent()->SetSubRun(starting_number);
}
filein.close();
}
fInitialized = true;
}
// open the first file
if ( !NewFile() )
*error_code = 1;
Log << dolog;
}
void BasicAFC::process_reset (UInt_t *error_code)
{
*error_code = 0;
Log.ClearMessage(); Log.SetProcessMethod("process_reset");
if ( fCurrentFile )
::fclose(fCurrentFile);
GetFrameIO().Print( Log() );
Log << dolog;
*error_code = 0;
Log.ClearMessage(); Log.SetProcessMethod("process_reset");
if ( fCurrentFile )
::fclose(fCurrentFile);
GetFrameIO().Print( Log() );
Log << dolog;
}
/*
......
......@@ -58,9 +58,11 @@ private:
UInt_t fMaxSize;
//! id of the instance, used for printouts
Int_t fMyID;
// current file name
//! current file name
std::string fCurrentFileName;
std::string fCurrentName;
//! status of initialization
bool fInitialized;
private:
ADF::AgataFrameTrigger *fVertex;
......@@ -85,6 +87,9 @@ public:
virtual void process_reset (UInt_t *error_code);
virtual UInt_t ProcessBlock (ADF::FrameBlock &) ;
//! To set the actor parameters without configuration file
virtual Bool_t SetParameters(std::string _pathforfiles, std::string _basename, int starting_number) ;
};
......
......@@ -29,45 +29,46 @@
#include <fstream>
#include <algorithm>
using namespace ADF;
BasicAFP::BasicAFP(Int_t id):
NarvalProducer(),
fSourceOfFrames(aMByte,ConfAgent::kRead),
fPath("./"),
fBaseForName("AFP_"),
fCurrentFile(0x0),
fCurrentFileNumber(0u),
fMaxSize(kMaxInt_t),
fMyID(id),
fEndOfFrame("EndOfFrame")
using namespace ADF;
BasicAFP::BasicAFP(Int_t id):
NarvalProducer(),
fSourceOfFrames(aMByte,ConfAgent::kRead),
fPath("./"),
fBaseForName("AFP_"),
fCurrentFile(0x0),
fCurrentFileNumber(0u),
fMaxSize(kMaxInt_t),
fMyID(id),
fEndOfFrame("EndOfFrame"),
fInitialized(false)
{
Log.GetProcessName() = "BasicAFP";
GetFrameIO().SetName("BasicAFP");
// to be sure unknown frames are written in the ouput
GetFrameIO().SetModel(ConfAgent::kSafe);
// to protect writings in the source of frames
fSourceOfFrames.SetModeIO(ConfAgent::kRead);
// the input datablock is owned by BasicAFP
GetFrameIO().Attach(&fSourceOfFrames,0x0);
Log.GetProcessName() = "BasicAFP";
GetFrameIO().SetName("BasicAFP");
// to be sure unknown frames are written in the ouput
GetFrameIO().SetModel(ConfAgent::kSafe);
// to protect writings in the source of frames
fSourceOfFrames.SetModeIO(ConfAgent::kRead);
// the input datablock is owned by BasicAFP
GetFrameIO().Attach(&fSourceOfFrames,0x0);
}
BasicAFP::~BasicAFP()
{
// in principle not needed ... just in case reset it has not been called by narval
UInt_t error = 0u; process_reset(&error) ;
// in principle not needed ... just in case reset it has not been called by narval
UInt_t error = 0u; process_reset(&error) ;
}
Bool_t BasicAFP::NewFile()
{
Bool_t ok = false;
if ( fCurrentFile ) {
::fclose(fCurrentFile);
fCurrentFile = 0x0;
std::cout << " -BasicAFP: the input file has just been closed " << fCurrentFileName << std::endl;
}
Bool_t ok = false;
if ( fCurrentFile ) {
::fclose(fCurrentFile);
fCurrentFile = 0x0;
std::cout << " -BasicAFP: the input file has just been closed " << fCurrentFileName << std::endl;
}
if(fListOfIndividualFiles.size()) {
if(fCurrentFileNumber<fListOfIndividualFiles.size()) fCurrentFileName = fListOfIndividualFiles.at(fCurrentFileNumber);
......@@ -78,7 +79,7 @@ Bool_t BasicAFP::NewFile()
// open the first file to be ready to be run
std::string tmp = fPath;
if ( tmp.size() > 0 && !(tmp.at(tmp.size()-1) == '/') )
tmp += '/';
tmp += '/';
std::ostringstream filename;
filename << tmp << fBaseForName
......@@ -86,37 +87,37 @@ Bool_t BasicAFP::NewFile()
<< ".adf";
fCurrentFileName = filename.str();
}
fCurrentFile = ::fopen(fCurrentFileName.c_str(),"rb");
if ( fCurrentFile != 0x0 ) {
Log << " -BasicAFP: the input file has just been opened "
<< fCurrentFileName << nline;
fSourceOfFrames.SetFile(fCurrentFile,fMaxSize);
GetFrameIO().SetStatus(BaseFrameIO::kIdle);
size_t len = fCurrentFileName.length();
size_t lpt = fCurrentFileName.find_last_of('/');
fCurrentName = fCurrentFileName.substr(lpt+1, len-lpt-1);
ok = true;
}
fCurrentFile = ::fopen(fCurrentFileName.c_str(),"rb");
if ( fCurrentFile != 0x0 ) {
Log << " -BasicAFP: the input file has just been opened "
<< fCurrentFileName << nline;
fSourceOfFrames.SetFile(fCurrentFile,fMaxSize);
GetFrameIO().SetStatus(BaseFrameIO::kIdle);
size_t len = fCurrentFileName.length();
size_t lpt = fCurrentFileName.find_last_of('/');
fCurrentName = fCurrentFileName.substr(lpt+1, len-lpt-1);
ok = true;
}
else {
if(fCurrentFileName.length()) Log << "Could not open input file " << fCurrentFileName << nline;
GetFrameIO().SetStatus(BaseFrameIO::kFinished);
ok = false;
}
return ok;
GetFrameIO().SetStatus(BaseFrameIO::kFinished);
ok = false;
}
return ok;
}
void BasicAFP::process_config (const Char_t *directory_path, UInt_t *error_code)
{
// first init narval and ADF stuff (if required)
NarvalInterface::process_config(directory_path, error_code);
if ( (*error_code) == 0u ) {
// now init your stuff
}
// first init narval and ADF stuff (if required)
NarvalInterface::process_config(directory_path, error_code);
if ( (*error_code) == 0u ) {
// now init your stuff
}
}
UInt_t BasicAFP::ProcessBlock(ADF::FrameBlock &out)
......@@ -141,10 +142,10 @@ UInt_t BasicAFP::ProcessBlock(ADF::FrameBlock &out)
if(fMyID >= 0) {
std::cout << std::setw(2) << fMyID;
std::cout << std::left << std::setw(24) << "-BasicAFP:" << std::right
<< " " << std::setw(5) << nevtsOut-nevtsIn
<< " evts (" << std::setw(8) << out.GetSize() << ")"
<< " Tot = " << std::setw(8) << nevtsOut
<< " " << fCurrentName << std::endl;
<< " " << std::setw(5) << nevtsOut-nevtsIn
<< " evts (" << std::setw(8) << out.GetSize() << ")"
<< " Tot = " << std::setw(8) << nevtsOut
<< " " << fCurrentName << std::endl;
}
if ( GetFrameIO().GetStatus() == BaseFrameIO::kFinished ) {
......@@ -179,66 +180,114 @@ UInt_t BasicAFP::ProcessBlock(ADF::FrameBlock &out)
return 0u;
}
Bool_t BasicAFP::SetParameters(std::string _pathforfiles, std::string _basename, int starting_number)
{
Log.ClearMessage(); Log.SetProcessMethod("SetParameters");
if(fInitialized) {
Log << warning << "actor already initialized, SetParameters method ignored " << nline;
Log << dolog;
return false;
}
fPath = _pathforfiles;
fBaseForName = _basename;
fCurrentFileNumber = starting_number;
fInitialized = true;
Log << dolog;
return true;
}
Bool_t BasicAFP::SetParameters(std::vector<std::string> _listoffiles)
{
Log.ClearMessage(); Log.SetProcessMethod("SetParameters");
if(fInitialized) {
Log << warning << "actor already initialized, SetParameters method ignored " << nline;
Log << dolog;
return false;
}
if(!_listoffiles.size()) {
Log << warning << "list of input files is empty, SetParameters method ignored " << nline;
Log << dolog;
return false;
}
for(auto &i: _listoffiles) fListOfIndividualFiles.push_back(i);
fInitialized = true;
Log << dolog;
return true;
}
void BasicAFP::process_initialise (UInt_t *error_code)
{
*error_code = 0u;
Log.ClearMessage(); Log.SetProcessMethod("process_initialise");
// read an input file to get the base filename and the path
std::string conffile = GetConfPath() + "BasicAFP.conf";
std::ifstream filein(conffile.data());
if ( filein.is_open() == true ) {
// check with the first line if the files are given one by one
std::string line;
std::getline(filein,line);
int nblank = std::count(line.begin(), line.end(),' ');
filein.seekg(0);