ATLAS Offline Software
VP1BatchUtilities.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Implementation of class VP1BatchUtilities //
8 // //
9 // Author: Riccardo Maria Bianchi <rbianchi@cern.ch> //
10 // //
11 // Initial version: Jan 2019 //
12 // //
14 
15 
17 
18 #include <string>
19 #include <vector>
20 #include <iostream>
21 #include <random> // C++11
22 #include <iomanip>
23 #include <functional>
24 
25 
26 
27 VP1BatchUtilities::VP1BatchUtilities(const std::vector<std::string>& files) :
28  m_files(files),
29  m_indexFile(0),
30  m_lastIndexFile(0)
31 {
32  std::cout << "Got vector of " << files.size() << " items" << std::endl;
33  // Iterate and print values of vector
34  for(const std::string& n : m_files) {
35  std::cout << n << '\n';
36  }
37 }
38 
39 
41 {
42  std::cout <<"VP1BatchUtilities::getRandomConfigFile()" << std::endl;
43 
44  std::string configFile;
45 
46 
47  int nConfigFiles = m_files.size();
48  std::cout << " ===> # config files: " << nConfigFiles << std::endl;
49 
50  // setup random generator in [0, nConfigFiles]
51  int nPositions = nConfigFiles - 1;
52  auto seed = std::random_device{}();
53  auto randomDist = std::bind(std::uniform_int_distribution<int>(0, nPositions ),
54  std::mt19937(seed));
55 
56  // get a random index,
57  m_indexFile = randomDist();
58  // avoiding having the same index in a row
59  while ( m_indexFile == m_lastIndexFile ) {
60  m_indexFile = randomDist();
61  }
63  std::cout << " ===> random index: " << m_indexFile << std::endl;
64 
66  std::cout << " ===> random file: " << configFile << std::endl;
67 
68  return configFile;
69 
70 }
71 
72 // Overlay the ATLAS logo to the image
74 {
75  /*
76  * different example commands for logo overlay:
77  *
78  * std::string commandStr = "convert -composite `cat latest_vp1image` $TestArea/InstallArea/share/ATLAS-Logo-New_300pixels.png -geometry 150x150+0+0 -depth 8 test.png"; // this set the logo size to 150px and it draws it at (0,0)px
79  * std::string commandStr = "convert -composite `cat latest_vp1image` $TestArea/InstallArea/share/ATLAS-Logo-New_300pixels.png -geometry +10+10 -depth 8 test.png"; // this uses the original logo size and it draws it at (10,10)px
80  */
81 
82  std::string commandStr = "convert -composite `cat latest_vp1image` $TestArea/InstallArea/share/ATLAS-Logo-New_300pixels.png -geometry +10+10 -depth 8 `cat latest_vp1image`";
83 
84  std::cout << " ===> overlay the ATLAS logo: " << commandStr << std::endl;
85  try {
86  system(commandStr.c_str());
87  } catch (std::runtime_error& err) {
88  std::cout << "Exception caught: " << err.what() << std::endl;
89  std::cout << "Unable to run 'convert'!" << std::endl;
90  }
91 }
92 
93 // Overlay the event details to the image
94 // it replaces the original image with a version having event details on it
95 void VP1BatchUtilities::overlayEventDetails(unsigned long runNumber, unsigned long eventNumber, const std::string& humanTimestamp)
96 {
97 
98  std::string nRun = std::to_string(runNumber);
99  std::string nEvent = std::to_string(eventNumber);
100 
101  /*
102  * example of different bash command for event details overlay:
103  *
104  * nRun=0; nEvent=4; img=`cat latest_vp1image`; width=$(identify -format %W ${img}); width=$(( ${width} * 3 / 10 )); convert -background '#0008' -gravity west -fill white -size ${width}x80 -font Courier -density 72 -pointsize 18 -interline-spacing 4 caption:'Run number: '${nRun}'\nEvent number: '${nEvent}'\n2015-02-02, 15:10:00' ${img} +swap -gravity SouthEast -composite ${img}-30
105  * nRun=0; nEvent=4; timestamp='ciao'; img=`cat latest_vp1image`; width=$(identify -format %W ${img}); width=$(( ${width} * 3 / 10 )); convert -background '#0008' -gravity west -fill white -size ${width}x80 -font Courier -density 72 -pointsize 18 -interline-spacing 4 caption:'Run number: '${nRun}'\nEvent number: '${nEvent}'\n'${timestamp} ${img} +swap -gravity SouthEast -composite ${img}-31
106  * nRun=0; nEvent=4; timestamp='2015-02-02T10:10:00'; img=`cat latest_vp1image`; width=$(identify -format %W ${img}); width=$(( ${width} * 3 / 10 )); convert -background '#0008' -gravity west -fill white -size ${width}x80 -font Courier -density 72 -pointsize 18 -interline-spacing 4 caption:'Run number: '${nRun}'\nEvent number: '${nEvent}'\n'${timestamp} ${img} +swap -gravity SouthEast -composite ${img}-36
107  */
108 
109  std::string commandStr;
110 
111  // setting bash variables
112  commandStr += "nRun="+nRun+"; ";
113  commandStr += "nEvent="+nEvent+"; ";
114  if (humanTimestamp != "0") commandStr += "timestamp='"+humanTimestamp+"'; "; // 'timestamp' must not have white spaces
115 
116  // get input image
117  commandStr += "img=`cat latest_vp1image`; "; // get the filename of the latest image produced
118  commandStr += "width=$(identify -format %W ${img}); "; // get the width of the image
119  commandStr += "width=$(( ${width} * 3 / 10 )); "; // set the caption width as a fraction of the image width
120 
121  // ImageMagik 'convert' command settings. (ImageMagik is installed by default on SLC LXPLUS machines)
122  commandStr = commandStr
123  + "convert "
124  + "-background '#0008' " // semi-transparent grey bkg
125  + "-geometry +20+20 " // set an offset to the label position
126  + "-gravity West " // set text position inside the caption space (justification)
127  + "-fill white " // text font color
128  + "-size ${width}x80 " // set text size relative to 'width'
129 
130  + "-font Courier " // text font
131  + "-density 72 " // dots-per-inch resolution
132  + "-pointsize 18 " // text size in points
133  //+ "-interline-spacing 4 " // additional number of pixels between lines of text (only with ImageMagik >= 6.5.5-8!!! Lxplus has 6.7 but not all SLC6 machines...)
134 
135  //+ "caption:'Run number: ${nRun}' " // set the caption text
136  //+ (m_timeStamp > 0 ? "caption:'Run number: '${nRun}'\\nEvent number: '${nEvent}'\\n'${timestamp} " : "caption:'Run number: '${nRun}'\\nEvent number: '${nEvent}'\\n'${timestamp} ") // set the caption text; '\n' needs to be double-escaped while passed to system()
137  + "caption:'Run number: '${nRun}'\\nEvent number: '${nEvent}'\\n'${timestamp} " // set the caption text; '\n' needs to be double-escaped while passed to system()
138 
139  + "${img} " // imput image
140  + "+swap "
141  + "-gravity SouthEast " // set overall caption position
142  + "-composite "
143  + "${img}"; // output image: here we replace the original image
144 
145 
146  std::cout << " ===> overlay the event details: " << commandStr << std::endl;
147  try {
148  system(commandStr.c_str());
149  } catch (std::runtime_error& err) {
150  std::cout << "Exception caught: " << err.what() << std::endl;
151  std::cout << "Unable to run 'convert'!" << std::endl;
152  }
153 }
154 
155 
VP1BatchUtilities::overlayEventDetails
static void overlayEventDetails(unsigned long runNumber, unsigned long eventNumber, const std::string &humanTimestamp)
Definition: VP1BatchUtilities.cxx:95
VP1BatchUtilities::m_indexFile
int m_indexFile
Definition: VP1BatchUtilities.h:37
taskman.configFile
configFile
Definition: taskman.py:311
VP1BatchUtilities::m_files
std::vector< std::string > m_files
Definition: VP1BatchUtilities.h:36
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
beamspotman.n
n
Definition: beamspotman.py:731
generateReferenceFile.files
files
Definition: generateReferenceFile.py:12
VP1BatchUtilities::VP1BatchUtilities
VP1BatchUtilities(const std::vector< std::string > &files)
Definition: VP1BatchUtilities.cxx:27
VP1BatchUtilities.h
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
VP1BatchUtilities::overlayATLASlogo
static void overlayATLASlogo()
Definition: VP1BatchUtilities.cxx:73
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
VP1BatchUtilities::m_lastIndexFile
int m_lastIndexFile
Definition: VP1BatchUtilities.h:38
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
VP1BatchUtilities::getRandomConfigFile
std::string getRandomConfigFile()
Definition: VP1BatchUtilities.cxx:40