Skip to content

Commit

Permalink
Merge pull request #73 from PADME-Experiment/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
eleonardi authored Oct 10, 2017
2 parents 278a74c + 54edfe0 commit 59d0521
Show file tree
Hide file tree
Showing 173 changed files with 7,909 additions and 1,055 deletions.
26 changes: 5 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,14 @@
*.pyc
*.dump
*.root
*.pcm
*.heprep
run_*
PersistencyDict.cc
PersistencyDict.h
.*.swp
Session.vim
html/
*.pcm


PadmeReco/ECal/lib/
PadmeReco/ECal/tmp/
PadmeReco/EVeto/lib/
PadmeReco/EVeto/tmp/
PadmeReco/HEPVeto/lib/
PadmeReco/HEPVeto/tmp/
PadmeReco/PVeto/lib/
PadmeReco/PVeto/tmp/
PadmeReco/PadmeReco
PadmeReco/RecoBase/lib/
PadmeReco/RecoBase/tmp/
PadmeReco/SAC/lib/
PadmeReco/SAC/tmp/
PadmeReco/Target/lib/
PadmeReco/Target/tmp/
PadmeReco/lib/
PadmeReco/tmp/

tmp/
lib/
bin/
2 changes: 1 addition & 1 deletion Level1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ DEPEND = $(CXX) -MM

# Define parameters for link command
LIBS = -L$(PADMEROOTDIR)/lib -lPadmeRoot -L/usr/lib64/mysql -lmysqlclient
LDFLAGS = -O4 $(ROOTLDFLAGS) $(ROOTLIBS) $(LIBS)
LDFLAGS = -O4 $(ROOTLDFLAGS) $(LIBS) $(ROOTLIBS)

# Get list of files to process
SOURCES := $(wildcard $(SDIR)/*.cc)
Expand Down
2 changes: 1 addition & 1 deletion Level1/PadmeLevel1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ int main(int argc, char* argv[])
} else {
printf("Run %d Events %d. WARNING - DB returns %d events: updating DB.\n",runnr,eventnr,n_events);
}
int rc = db->UpdateRunEvents(n_events,runnr);
int rc = db->UpdateRunEvents(eventnr,runnr);
if (rc != DBSERVICE_OK) {
printf("ERROR updating DB for run %d. Aborting\n",runnr);
exit(1);
Expand Down
158 changes: 100 additions & 58 deletions Level1/ReadTest.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
#include "Riostream.h"
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <sys/stat.h>

#include "TFile.h"
#include "TChain.h"
#include "TTree.h"
#include "TBranch.h"
#include "TObjArray.h"

#include "TRawEvent.hh"

int main(int argc, char* argv[])
{

int c;
std::string infile = "rawdata.root";
int verbose = 0;
int nevents = 0;

TString inputFileName;
TObjArray inputFileNameList;
struct stat filestat;

// Parse options
while ((c = getopt (argc, argv, "i:n:v:h")) != -1) {
while ((c = getopt (argc, argv, "i:l:n:v:h")) != -1) {
switch (c)
{
case 'i':
infile = optarg;
fprintf(stdout,"Set input data file to '%s'\n",infile.c_str());
inputFileNameList.Add(new TObjString(optarg));
fprintf(stdout,"Added input data file '%s'\n",optarg);
break;
case 'l':
if ( stat(Form(optarg),&filestat) == 0 ) {
fprintf(stdout,"Reading list of input files from '%s'\n",optarg);
std::ifstream inputList(optarg);
while( inputFileName.ReadLine(inputList) ){
if ( stat(Form(inputFileName.Data()),&filestat) == 0 ) {
inputFileNameList.Add(new TObjString(inputFileName.Data()));
fprintf(stdout,"Added input data file '%s'\n",inputFileName.Data());
} else {
fprintf(stdout,"WARNING: file '%s' is not accessible\n",inputFileName.Data());
}
}
} else {
fprintf(stdout,"WARNING: file list '%s' is not accessible\n",optarg);
}
break;
case 'n':
if ( sscanf(optarg,"%d",&nevents) != 1 ) {
Expand Down Expand Up @@ -74,82 +97,101 @@ int main(int argc, char* argv[])
}
}

TFile* fRawEv = new TFile(infile.c_str());
TTree* tRawEv = (TTree*)fRawEv->Get("RawEvents");
TBranch* bRawEv = tRawEv->GetBranch("RawEvent");
TRawEvent* rawEv = new TRawEvent();
bRawEv->SetAddress(&rawEv);
if ( inputFileNameList.GetEntries() == 0 ) {
perror(Form("ERROR No Input File specified"));
exit(1);
}

// Create chain of input files
fprintf(stdout,"=== === === Chain of input files === === ===\n");
TChain* inputChain = new TChain("RawEvents");
for (Int_t iFile = 0; iFile < inputFileNameList.GetEntries(); iFile++) {
fprintf(stdout,"%4d %s\n",iFile,((TObjString*)inputFileNameList.At(iFile))->GetString().Data());
inputChain->AddFile(((TObjString*)inputFileNameList.At(iFile))->GetString());
}
if (inputChain->GetEntries() == 0) {
perror(Form("ERROR No events found for tree 'RawEvents' in input chain"));
exit(1);
}

Int_t nevt = tRawEv->GetEntries();
printf("TTree RawEvents contains %d events\n",nevt);
// Get some info about the input chain
Int_t runNEntries = inputChain->GetEntries();
std::cout << "Found Tree 'RawEvents' with " << runNEntries << " entries" << std::endl;
TRawEvent* rawEv = new TRawEvent();
inputChain->SetBranchAddress("RawEvent",&rawEv);

// Set number of events to read
Int_t ntoread = nevt;
if (nevents && nevents<nevt) ntoread = nevents;
Int_t ntoread = runNEntries;
if (nevents && nevents<runNEntries) {
ntoread = nevents;
printf("Reading first %d events\n",ntoread);
}

printf("Reading the first %d events\n",ntoread);
for(Int_t iev=0;iev<ntoread;iev++){

// Read event
printf("Reading event %d\n",iev);
bRawEv->GetEntry(iev);
printf("Event %d read\n",iev);
//printf("Reading event %d\n",iev);
inputChain->GetEntry(iev);
//printf("Event %d read\n",iev);

// Show event header
UChar_t nBoards = rawEv->GetNADCBoards();
printf("Event %d Run nr %d Event nr %d ADC boards %d\n",
iev,rawEv->GetRunNumber(),rawEv->GetEventNumber(),nBoards);

// Loop over boards
for(UChar_t b=0;b<nBoards;b++){

// Show board info
TADCBoard* adcB = rawEv->ADCBoard(b);
UChar_t nTrg = adcB->GetNADCTriggers();
UChar_t nChn = adcB->GetNADCChannels();
printf("\tBoard %u Board Id %u LVDS %u Status %u GMsk 0x%1x EvtCnt %u Time %u ActMsk 0x%08x AccMsk 0x%08x #Trg %u #Chn %u\n",
b,adcB->GetBoardId(),adcB->GetLVDSPattern(),adcB->GetStatus(),adcB->GetGroupMask(),adcB->GetEventCounter(),
adcB->GetEventTimeTag(),adcB->GetActiveChannelMask(),adcB->GetAcceptedChannelMask(),nTrg,nChn);

// Loop over triggers
for(UChar_t t=0;t<nTrg;t++){
TADCTrigger* trg = adcB->ADCTrigger(t);
printf("\t\tTrig %u Grp %u SIC %u Freq %u Sign %u Time %u\n",
t,trg->GetGroupNumber(),trg->GetStartIndexCell(),trg->GetFrequency(),trg->GetTriggerSignal(),
trg->GetTriggerTimeTag());
for(UShort_t s=0;s<trg->GetNSamples();s++){
if ( (s%40)==0 ) printf("\t\t\t");
printf(" %04u",trg->GetSample(s));
if ( (s%40)==39 ) printf("\n");
}
printf("\n");
}
if (verbose>0) {

// Loop over boards
for(UChar_t b=0;b<nBoards;b++){

// Show board info
TADCBoard* adcB = rawEv->ADCBoard(b);
UChar_t nTrg = adcB->GetNADCTriggers();
UChar_t nChn = adcB->GetNADCChannels();
printf("\tBoard %u Board Id %u LVDS %u Status %u GMsk 0x%1x EvtCnt %u Time %u ActMsk 0x%08x AccMsk 0x%08x #Trg %u #Chn %u\n",
b,adcB->GetBoardId(),adcB->GetLVDSPattern(),adcB->GetStatus(),adcB->GetGroupMask(),adcB->GetEventCounter(),
adcB->GetEventTimeTag(),adcB->GetActiveChannelMask(),adcB->GetAcceptedChannelMask(),nTrg,nChn);

if (verbose>1) {

// Loop over triggers
for(UChar_t t=0;t<nTrg;t++){
TADCTrigger* trg = adcB->ADCTrigger(t);
printf("\t\tTrig %u Grp %u SIC %u Freq %u Sign %u Time %u\n",
t,trg->GetGroupNumber(),trg->GetStartIndexCell(),trg->GetFrequency(),trg->GetTriggerSignal(),
trg->GetTriggerTimeTag());
for(UShort_t s=0;s<trg->GetNSamples();s++){
if ( (s%40)==0 ) printf("\t\t\t");
printf(" %04u",trg->GetSample(s));
if ( (s%40)==39 ) printf("\n");
}
printf("\n");
}

// Loop over channels
for(UChar_t c=0;c<nChn;c++){
TADCChannel* chn = adcB->ADCChannel(c);
printf("\t\tChan %u Chn# %u\n",c,chn->GetChannelNumber());
for(UShort_t s=0;s<chn->GetNSamples();s++){
if ( (s%40)==0 ) printf("\t\t\t");
printf(" %04u",chn->GetSample(s));
if ( (s%40)==39 ) printf("\n");
}
printf("\n");
}

// Loop over channels
for(UChar_t c=0;c<nChn;c++){
TADCChannel* chn = adcB->ADCChannel(c);
printf("\t\tChan %u Chn# %u\n",c,chn->GetChannelNumber());
for(UShort_t s=0;s<chn->GetNSamples();s++){
if ( (s%40)==0 ) printf("\t\t\t");
printf(" %04u",chn->GetSample(s));
if ( (s%40)==39 ) printf("\n");
}
printf("\n");
}

} // End loop over boards

}

// Clear event
rawEv->Clear("C");

}
} // End loop over events

delete rawEv;
delete bRawEv;
delete tRawEv;

fRawEv->Close();
delete fRawEv;

exit(0);

Expand Down
131 changes: 131 additions & 0 deletions PadmeCDR/code/transfer_files.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/usr/bin/perl

use Getopt::Std;

printf "Running on node $ENV{'HOSTNAME'} as user $ENV{'USER'} in dir $ENV{'HOME'}\n";

$YEAR = 1900+(localtime)[5];
getopts('y:');
if ($opt_y) {
$YEAR = $opt_y;
}
printf "Will transfer files for year $YEAR\n";

$DATA_DIR = "rawdata/$YEAR";

$DAQ_SRV = "padmesrv1";
$DAQ_USER = "daq";
$DAQ_PATH = "/home/daq/DAQ";

$DAQ_ADLER32_CMD = "/home/daq/DAQ/tools/adler32";

$DAQ_SFTP = "sftp://$DAQ_SRV$DAQ_PATH";
$LNF_SRM = "srm://atlasse.lnf.infn.it:8446/srm/managerv2?SFN=/dpm/lnf.infn.it/home/vo.padme.org/testbeam";
$CNAF_SRM = "srm://storm-fe-archive.cr.cnaf.infn.it:8444/srm/managerv2?SFN=/padmeTape/testbeam";

print "Getting list of raw data files for year $YEAR on $DAQ_SRV\n";
my @daq_list = `ssh -l $DAQ_USER $DAQ_SRV ls $DAQ_PATH/$DATA_DIR`;
chomp(@daq_list);
my %daq_list = map { $_ => 1 } @daq_list;

print "Getting list of raw data files for year $YEAR on LNF disks\n";
my @lnf_list = `gfal-ls $LNF_SRM/$DATA_DIR`;
chomp(@lnf_list);
my %lnf_list = map { $_ => 1 } @lnf_list;

print "Getting list of raw data files for year $YEAR on CNAF tape library\n";
my @cnaf_list = `gfal-ls $CNAF_SRM/$DATA_DIR`;
chomp(@cnaf_list);
my %cnaf_list = map { $_ => 1 } @cnaf_list;

# Make a full list and show which file is located where
@full_list = ();
push(@full_list,@daq_list);
push(@full_list,@lnf_list);
push(@full_list,@cnaf_list);
@full_list = sort @full_list;
$i = 0;
$uniq_list[0] = $full_list[0];
foreach my $file (@full_list) {
if ($file ne $uniq_list[$i]) {
push(@uniq_list,$file);
$i++;
}
}
foreach my $file (@uniq_list) {
printf("%-30s ",$file);
if ( exists($daq_list{$file}) ) { printf "D"; } else { printf "-"; }
if ( exists($lnf_list{$file}) ) { printf "L"; } else { printf "-"; }
if ( exists($cnaf_list{$file}) ) { printf "C"; } else { printf "-"; }
printf "\n";
}

#foreach my $file ("run_628.root") {
foreach my $file (@uniq_list) {

printf "\n=== Checking file $file ===\n";

# If file exists on DAQ and not at LNF, copy it
if ( exists($daq_list{$file}) and not exists($lnf_list{$file}) ) {

printf "Starting copy of $file from DAQ to LNF\n";

# Copy from PADME on-line server to LNF storage system
$cmd = "gfal-copy -t 3600 -T 3600 -D\"SFTP PLUGIN:USER=$DAQ_USER\" -D\"SFTP PLUGIN:PRIVKEY=/home/$ENV{'USER'}/.ssh/id_rsa\" $DAQ_SFTP/$DATA_DIR/$file $LNF_SRM/$DATA_DIR/$file";
printf "> $cmd\n";
#system(split(/ /,$cmd));
system($cmd);

# Verify ADLER32 checksum

$a32_daq_out = `ssh -l $DAQ_USER $DAQ_SRV $DAQ_ADLER32_CMD $DAQ_PATH/$DATA_DIR/$file`;
chomp $a32_daq_out;
$a32_daq = (split(/ /,$a32_daq_out))[0];

$a32_lnf_out = `gfal-sum $LNF_SRM/$DATA_DIR/$file ADLER32`;
chomp $a32_lnf_out;
$a32_lnf = (split(/ /,$a32_lnf_out))[1];

if ( $a32_daq ne $a32_lnf ) {
printf "ADLER32 CRC ***ERROR***: DAQ $a32_daq LNF $a32_lnf\n";
} else {
printf "ADLER32 CRC OK: DAQ $a32_daq LNF $a32_lnf\n";
# Copy was successful: add file to list at LNF
$lnf_list{$file} = 1;
# Add DAQ->LNF post-transfer processing here
}

}

# If file exist at LNF but not at CNAF, copy it
if ( exists($lnf_list{$file}) and not exists($cnaf_list{$file}) ) {

printf "Starting copy of $file from LNF to CNAF\n";

# Copy from LNF storage system to CNAF tape library using gfal-copy
$cmd = "gfal-copy -t 3600 -T 3600 $LNF_SRM/$DATA_DIR/$file $CNAF_SRM/$DATA_DIR/$file";
printf "> $cmd\n";
system(split(/ /,$cmd));

# Verify ADLER32 checksum

$a32_lnf_out = `gfal-sum $LNF_SRM/$DATA_DIR/$file ADLER32`;
chomp $a32_lnf_out;
$a32_lnf = (split(/ /,$a32_lnf_out))[1];

$a32_cnaf_out = `gfal-sum $CNAF_SRM/$DATA_DIR/$file ADLER32`;
chomp $a32_cnaf_out;
$a32_cnaf = (split(/ /,$a32_cnaf_out))[1];

if ( $a32_lnf ne $a32_cnaf ) {
printf "ADLER32 CRC ***ERROR***: LNF $a32_lnf CNAF $a32_cnaf\n";
} else {
printf "ADLER32 CRC OK: LNF $a32_lnf CNAF $a32_cnaf\n";
# Copy was successful: add file to list at LNF
$cnaf_list{$file} = 1;
# Add LNF->CNAF post-transfer processing here
}

}

}
Loading

0 comments on commit 59d0521

Please sign in to comment.