1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
#!/usr/bin/env perl
# SELMA - Saclay Ecal Laser Monitoring and Analysis
# contacts: Julie Malcles, Gautier Hamel de Monchenault
# last modified: Sat Nov 24 08:56:52 CET 2007
use Term::ANSIColor;
use Cwd;
use File::stat;
use Time::localtime;
$firstRun = @ARGV[0];
$lastRun = @ARGV[1];
$useMatacq = @ARGV[2];
$useShape = @ARGV[3];
$fitAB = @ARGV[4];
$linkName = @ARGV[5];
$user = @ARGV[6];
$ecalPart = @ARGV[7];
$nmaxjobshead = @ARGV[8];
$nmaxjobstot = @ARGV[9];
# Defaults arguments values
#===========================
$firstRunDefault = "0" ;
$lastRunDefault = "100000" ;
$useMatacqDefault = 1 ;
$useShapeDefault = 1 ;
$linkNameDefault = "LaserMonitoring" ;
$userDefault="ecallaser";
$ecalPartDefault="Ecal";
$debug=0;
@analyzeSMRunning = (0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0);
@detectSMRunning = (0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0);
# Setup defaults arguments values
#=================================
if( $firstRun eq "" )
{
$firstRun = $firstRunDefault;
$lastRun = $lastRunDefault;
}
elsif( $lastRun eq "+" )
{
$lastRun = "99999";
}
elsif( $lastRun eq "" )
{
$lastRun = $firstRun;
}
if( $useMatacq eq "" )
{
$useMatacq=$useMatacqDefault;
}
if( $useShape eq "" ){
$useShape=$useShapeDefault;
}
if( $useMatacq == 0 ) {
$useShape = 0;
}
if( $user eq "" ){
$user=$userDefault;
}
if( $ecalPart eq "" ){
$ecalPart = $ecalPartDefault;
}
# Directories settings
#======================
$localdir = cwd;
if ( $linkName eq "" ) {
$proddir = "${localdir}/${linkNameDefault}";
}else{
$proddir = "${localdir}/${linkName}";
}
$scriptdir = "$proddir/scripts";
$shapedir = "$proddir/shapes";
$sortdir = "$proddir/sorting";
# ECAL numbering settings
#=========================
$firsteem = 601;
$firstebm = 610;
$firstebp = 628;
$firsteep = 646;
$lastecal = 654;
do "${scriptdir}/monitoringFunctions.pl";
print color("red"),"\n\n ***** Saclay Ecal Laser Monitoring & Analysis *****\n", color("reset");
print color("red"), " ***** Analyzing : ${ecalPart} *****\n\n", color("reset");
# Analyze the sorting directory:
#===============================
while( 1 )
{
system date;
analyze();
sleep 60;
}
exit;
sub analyze
{
print color("green"), " \n ** Restarting Analyzer ** \n\n", color("reset");
opendir(SORTDIR, $sortdir) || die "cannot open sorting directory $sortdir \n";
$dirname = "";
$fedname = "";
$lbname = "";
$run = 0;
$fed = 0;
my @sortdirs = sort readdir( SORTDIR );
# Detect news super-modules
#===========================
foreach my $dir (@sortdirs)
{
if( $debug == 1 ) { print "Directory: ${dir} detected.\n"; }
next unless( $dir =~ /E(E|B)(\+|-)(\d{1})/ );
$fed = getFedNumber(${dir});
if( $debug == 1 ) { print "Cut1Passed fed:${fed},dir:${dir},ecalPart:${ecalPart} \n";}
next unless( doProcessFed($fed, $ecalPart) == 1 );
if( $debug == 1 ) { print "Cut2Passed (doProcessFed) \n";}
# Create eventually new directory
# ================================
my $smdir = "${proddir}/${dir}";
if( -e ${smdir} )
{
if( $debug == 1 ) { print "${smdir} exists.\n"; }
}else{
print "creating directory ${smdir}\n";
$command = "${scriptdir}/createDirs.csh ${proddir} ${dir}" ;
system ${command};
}
# Check if analyzer is running and eventuelly launch it
# ======================================================
if( $detectSMRunning[$fed-600] == 0 ){
$detectSMRunning[$fed-600]= isDetectSMRunning($fed, $dir, $user, $linkName);
}
if( $detectSMRunning[$fed-600] == 0 ){
print "now launch the script to detect new files for module ${dir}\n";
my $curtime=time();
my $smlog="${smdir}/detectSM_${curtime}.log";
$command = "nohup ${scriptdir}/detectSM.pl ${firstRun} ${lastRun} ${fed} ${dir} ${useShape} ${fitAB} ${linkName} ${user} ${nmaxjobshead} ${debug} > ${smlog} &\n";
system ${command};
$detectSMRunning[$fed-600]=1;
}
if( $analyzeSMRunning[$fed-600] == 0 ){
$analyzeSMRunning[$fed-600]= isAnalyzeSMRunning($fed, $dir, $user, $linkName);
}
if( $analyzeSMRunning[$fed-600] == 0 ){
print "now launch the script to analyze module ${dir}\n";
my $curtime=time();
my $smlog="${smdir}/analyzeSM_${curtime}.log";
$command = "nohup ${scriptdir}/analyzeSM.pl ${fed} ${dir} ${useMatacq} ${useShape} ${fitAB} ${linkName} ${user} ${nmaxjobstot} ${debug} > ${smlog} &\n";
system ${command};
$analyzeSMRunning[$fed-600]=1;
}
sleep 1;
}
close(SORTDIR);
}
sub isAnalyzeSMRunning
{
my $fedToCheck=$_[0];
my $smToCheck=$_[1];
my $username=$_[2];
my $linkName=$_[3];
my $isItRunning=1;
my $command = "ps x -u $username";
my $nproc=0;
open(COMMAND, "${command}|" ) or die $!;
while( my $ligne = <COMMAND> ) {
next unless( $ligne =~ /(.*)analyzeSM.pl $fedToCheck $smToCheck(.*)$linkName(.*)/ );
$nproc=$nproc+1;
}
close COMMAND;
if( $debug ==1 ) {print "isAnalyzeSMRunning: $fed nproc= $nproc \n"; }
if( $nproc == 0 ) {
$isItRunning=0;
}
return $isItRunning;
}
sub isDetectSMRunning
{
my $fedToCheck=$_[0];
my $smToCheck=$_[1];
my $username=$_[2];
my $linkName=$_[3];
my $isItRunning=1;
my $command = "ps x -u $username";
my $nproc=0;
open(COMMAND, "${command}|" ) or die $!;
while( my $ligne = <COMMAND> ) {
next unless( $ligne =~ /(.*)detectSM.pl $fedToCheck $smToCheck(.*)$linkName(.*)/ );
$nproc=$nproc+1;
}
close COMMAND;
if( $debug ==1 ) {print "isDetectSMRunning: $fed nproc= $nproc \n"; }
if( $nproc == 0 ) {
$isItRunning=0;
}
return $isItRunning;
}
|